Fix ancient bug in handling of to_char modifier 'TH', when used with HH.
[PostgreSQL.git] / src / port / kill.c
blob5a2faaa751cea57edc89f3dfd591d133d38b48e0
1 /*-------------------------------------------------------------------------
3 * kill.c
4 * kill()
6 * Copyright (c) 1996-2009, PostgreSQL Global Development Group
8 * This is a replacement version of kill for Win32 which sends
9 * signals that the backend can recognize.
11 * IDENTIFICATION
12 * $PostgreSQL$
14 *-------------------------------------------------------------------------
17 #include "c.h"
19 #ifdef WIN32
20 /* signal sending */
21 int
22 pgkill(int pid, int sig)
24 char pipename[128];
25 BYTE sigData = sig;
26 BYTE sigRet = 0;
27 DWORD bytes;
28 int pipe_tries;
30 /* we allow signal 0 here, but it will be ignored in pg_queue_signal */
31 if (sig >= PG_SIGNAL_COUNT || sig < 0)
33 errno = EINVAL;
34 return -1;
36 if (pid <= 0)
38 /* No support for process groups */
39 errno = EINVAL;
40 return -1;
42 snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\pgsignal_%u", pid);
45 * Writing data to the named pipe can fail for transient reasons.
46 * Therefore, it is useful to retry if it fails. The maximum number of
47 * calls to make was empirically determined from a 90-hour notification
48 * stress test.
50 for (pipe_tries = 0; pipe_tries < 3; pipe_tries++)
52 if (CallNamedPipe(pipename, &sigData, 1, &sigRet, 1, &bytes, 1000))
54 if (bytes != 1 || sigRet != sig)
56 errno = ESRCH;
57 return -1;
59 return 0;
63 if (GetLastError() == ERROR_FILE_NOT_FOUND)
64 errno = ESRCH;
65 else if (GetLastError() == ERROR_ACCESS_DENIED)
66 errno = EPERM;
67 else
68 errno = EINVAL;
69 return -1;
72 #endif