Skip to content

Commit 57df03a

Browse files
author
James William Pye
committed
Reflect the changes to CallNamedPipe in port/kill.c
Apparently, that loop was the cause of the trouble.
1 parent 3c5c225 commit 57df03a

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

postgresql/port/signal1_msw.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
##
2-
# copyright 2009, James William Pye
3-
# http://python.projects.postgresql.org
2+
# .port.signal1_msw
43
##
54
"""
65
Support for PG signals on Windows platforms.
76
8-
This implementation supports all known versions of PostgreSQL. (2009)
7+
This implementation supports all known versions of PostgreSQL. (2010)
98
109
CallNamedPipe:
1110
http://msdn.microsoft.com/en-us/library/aa365144%28VS.85%29.aspx
1211
"""
12+
import errno
1313
from ctypes import windll, wintypes, pointer
1414

1515
# CallNamedPipe from kernel32.
@@ -26,7 +26,7 @@
2626
)
2727

2828
from signal import SIGTERM, SIGINT, SIG_DFL
29-
# Values taken from the port/win32.h file.
29+
# SYNC: Values taken from the port/win32.h file.
3030
SIG_DFL=0
3131
SIGHUP=1
3232
SIGQUIT=3
@@ -45,26 +45,32 @@
4545
SIGUSR1=30
4646
SIGUSR2=31
4747

48+
# SYNC: port.h
49+
PG_SIGNAL_COUNT = 32
50+
4851
# In the situation of another variant, another module should be constructed.
4952
def kill(pid : int, signal : int, timeout = 1000, dword1 = wintypes.DWORD(1)):
5053
"""
5154
Re-implementation of pg_kill for win32 using ctypes.
5255
"""
56+
if pid <= 0:
57+
raise OSError(errno.EINVAL, "process group not supported")
58+
if signal < 0 or signal >= PG_SIGNAL_COUNT:
59+
raise OSError(errno.EINVAL, "unsupported signal number")
5360
inbuffer = pointer(wintypes.BYTE(signal))
5461
outbuffer = pointer(wintypes.BYTE(0))
5562
outbytes = pointer(wintypes.DWORD(0))
5663
pidpipe = br'\\.\pipe\pgsignal_' + str(pid).encode('ascii')
5764
timeout = wintypes.DWORD(timeout)
58-
# Down to the algorithm. No need to second guess that 90-hour trial.
59-
for x in range(3):
60-
r = CallNamedPipeA(
61-
pidpipe, inbuffer, dword1, outbuffer, dword1, outbytes, timeout
62-
)
63-
if r:
64-
if outbuffer.contents.value == signal:
65-
if outbytes.contents.value == 1:
66-
# success
67-
return
68-
raise Exception("failed to validate output")
69-
# didn't work?
65+
r = CallNamedPipeA(
66+
pidpipe, inbuffer, dword1, outbuffer, dword1, outbytes, timeout
67+
)
68+
if r:
69+
if outbuffer.contents.value == signal:
70+
if outbytes.contents.value == 1:
71+
# success
72+
return
73+
# Don't bother emulating the other failure cases/abstractions.
74+
# CallNamedPipeA should raise a WindowsError on those failures.
75+
raise OSError(errno.ESRCH, "unexpected output from CallNamedPipeA")
7076
__docformat__ = 'reStructuredText'

0 commit comments

Comments
 (0)