Header And Logo

PostgreSQL
| The world's most advanced open source database.

kill.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * kill.c
00004  *    kill()
00005  *
00006  * Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  *
00008  *  This is a replacement version of kill for Win32 which sends
00009  *  signals that the backend can recognize.
00010  *
00011  * IDENTIFICATION
00012  *    src/port/kill.c
00013  *
00014  *-------------------------------------------------------------------------
00015  */
00016 
00017 #include "c.h"
00018 
00019 #ifdef WIN32
00020 /* signal sending */
00021 int
00022 pgkill(int pid, int sig)
00023 {
00024     char        pipename[128];
00025     BYTE        sigData = sig;
00026     BYTE        sigRet = 0;
00027     DWORD       bytes;
00028 
00029     /* we allow signal 0 here, but it will be ignored in pg_queue_signal */
00030     if (sig >= PG_SIGNAL_COUNT || sig < 0)
00031     {
00032         errno = EINVAL;
00033         return -1;
00034     }
00035     if (pid <= 0)
00036     {
00037         /* No support for process groups */
00038         errno = EINVAL;
00039         return -1;
00040     }
00041     snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\pgsignal_%u", pid);
00042 
00043     if (CallNamedPipe(pipename, &sigData, 1, &sigRet, 1, &bytes, 1000))
00044     {
00045         if (bytes != 1 || sigRet != sig)
00046         {
00047             errno = ESRCH;
00048             return -1;
00049         }
00050         return 0;
00051     }
00052 
00053     if (GetLastError() == ERROR_FILE_NOT_FOUND)
00054         errno = ESRCH;
00055     else if (GetLastError() == ERROR_ACCESS_DENIED)
00056         errno = EPERM;
00057     else
00058         errno = EINVAL;
00059     return -1;
00060 }
00061 
00062 #endif