|
1 | 1 | ## |
2 | | -# copyright 2009, James William Pye |
3 | | -# http://python.projects.postgresql.org |
| 2 | +# .port.signal1_msw |
4 | 3 | ## |
5 | 4 | """ |
6 | 5 | Support for PG signals on Windows platforms. |
7 | 6 |
|
8 | | -This implementation supports all known versions of PostgreSQL. (2009) |
| 7 | +This implementation supports all known versions of PostgreSQL. (2010) |
9 | 8 |
|
10 | 9 | CallNamedPipe: |
11 | 10 | http://msdn.microsoft.com/en-us/library/aa365144%28VS.85%29.aspx |
12 | 11 | """ |
| 12 | +import errno |
13 | 13 | from ctypes import windll, wintypes, pointer |
14 | 14 |
|
15 | 15 | # CallNamedPipe from kernel32. |
|
26 | 26 | ) |
27 | 27 |
|
28 | 28 | 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. |
30 | 30 | SIG_DFL=0 |
31 | 31 | SIGHUP=1 |
32 | 32 | SIGQUIT=3 |
|
45 | 45 | SIGUSR1=30 |
46 | 46 | SIGUSR2=31 |
47 | 47 |
|
| 48 | +# SYNC: port.h |
| 49 | +PG_SIGNAL_COUNT = 32 |
| 50 | + |
48 | 51 | # In the situation of another variant, another module should be constructed. |
49 | 52 | def kill(pid : int, signal : int, timeout = 1000, dword1 = wintypes.DWORD(1)): |
50 | 53 | """ |
51 | 54 | Re-implementation of pg_kill for win32 using ctypes. |
52 | 55 | """ |
| 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") |
53 | 60 | inbuffer = pointer(wintypes.BYTE(signal)) |
54 | 61 | outbuffer = pointer(wintypes.BYTE(0)) |
55 | 62 | outbytes = pointer(wintypes.DWORD(0)) |
56 | 63 | pidpipe = br'\\.\pipe\pgsignal_' + str(pid).encode('ascii') |
57 | 64 | 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") |
70 | 76 | __docformat__ = 'reStructuredText' |
0 commit comments