Skip to content

Commit cb4df96

Browse files
authored
windows: updating close logic for server and client pipes (osquery#53)
1 parent f13c7a8 commit cb4df96

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

Diff for: osquery/TPipe.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def close(self):
3232
in the same way
3333
"""
3434
if self._handle is not None:
35-
win32pipe.DisconnectNamedPipe(self._handle)
35+
win32file.CloseHandle(self._handle)
3636
self._handle = None
3737

3838

@@ -67,13 +67,10 @@ def open(self):
6767
while conns < self._max_conn_attempts:
6868
try:
6969
h = win32file.CreateFile(
70-
self._pipe_name,
71-
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
72-
0,
73-
None,
74-
win32file.OPEN_EXISTING,
75-
win32file.FILE_FLAG_OVERLAPPED,
76-
None)
70+
self._pipe_name,
71+
win32file.GENERIC_READ | win32file.GENERIC_WRITE, 0, None,
72+
win32file.OPEN_EXISTING, win32file.FILE_FLAG_OVERLAPPED,
73+
None)
7774
except pywintypes.error as e:
7875
if e.winerror != winerror.ERROR_PIPE_BUSY:
7976
raise TTransportException(
@@ -198,8 +195,8 @@ def create_named_pipe(self):
198195

199196
self._handle = win32pipe.CreateNamedPipe(
200197
self._pipe_name, openMode, pipeMode,
201-
win32pipe.PIPE_UNLIMITED_INSTANCES, self._buff_size, self._buff_size,
202-
win32pipe.NMPWAIT_WAIT_FOREVER, saAttr)
198+
win32pipe.PIPE_UNLIMITED_INSTANCES, self._buff_size,
199+
self._buff_size, win32pipe.NMPWAIT_WAIT_FOREVER, saAttr)
203200

204201
err = win32api.GetLastError()
205202
if self._handle.handle == winerror.ERROR_INVALID_HANDLE:
@@ -223,3 +220,13 @@ def initiate_named_connect(self):
223220
if ret == winerror.ERROR_PIPE_CONNECTED:
224221
win32event.SetEvent(self._overlapped.hEvent)
225222
break
223+
224+
def close(self):
225+
"""
226+
The server must ensure to disconnect so that subsequent reconnect
227+
attempts are successful
228+
"""
229+
if self._handle is not None:
230+
win32pipe.DisconnectNamedPipe(self._handle)
231+
win32file.CloseHandle(self._handle)
232+
self._handle = None

0 commit comments

Comments
 (0)