~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/port/kill.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * kill.c
 
4
 *        kill()
 
5
 *
 
6
 * Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
7
 *
 
8
 *      This is a replacement version of kill for Win32 which sends
 
9
 *      signals that the backend can recognize.
 
10
 *
 
11
 * IDENTIFICATION
 
12
 *        $PostgreSQL: pgsql/src/port/kill.c,v 1.6 2004-12-31 22:03:53 pgsql Exp $
 
13
 *
 
14
 *-------------------------------------------------------------------------
 
15
 */
 
16
 
 
17
#include "c.h"
 
18
 
 
19
#ifdef WIN32
 
20
/* signal sending */
 
21
int
 
22
pgkill(int pid, int sig)
 
23
{
 
24
        char            pipename[128];
 
25
        BYTE            sigData = sig;
 
26
        BYTE            sigRet = 0;
 
27
        DWORD           bytes;
 
28
 
 
29
        /* we allow signal 0 here, but it will be ignored in pg_queue_signal */
 
30
        if (sig >= PG_SIGNAL_COUNT || sig < 0)
 
31
        {
 
32
                errno = EINVAL;
 
33
                return -1;
 
34
        }
 
35
        if (pid <= 0)
 
36
        {
 
37
                /* No support for process groups */
 
38
                errno = EINVAL;
 
39
                return -1;
 
40
        }
 
41
        wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%i", pid);
 
42
        if (!CallNamedPipe(pipename, &sigData, 1, &sigRet, 1, &bytes, 1000))
 
43
        {
 
44
                if (GetLastError() == ERROR_FILE_NOT_FOUND)
 
45
                        errno = ESRCH;
 
46
                else if (GetLastError() == ERROR_ACCESS_DENIED)
 
47
                        errno = EPERM;
 
48
                else
 
49
                        errno = EINVAL;
 
50
                return -1;
 
51
        }
 
52
        if (bytes != 1 || sigRet != sig)
 
53
        {
 
54
                errno = ESRCH;
 
55
                return -1;
 
56
        }
 
57
 
 
58
        return 0;
 
59
}
 
60
 
 
61
#endif