1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-21 16:02:15 +03:00
Files
postgres/src/port/kill.c
Magnus Hagander 344d0cae64 Use snprintf instead of wsprintf, and use getenv("APPDATA") instead of
SHGetFolderPath.

This removes the direct dependency on shell32.dll and user32.dll, which
eats a lot of "desktop heap" for each backend that's started. The
desktop heap is a very limited resource, causing backends to no
longer start once it's been exhausted.

We still have indirect depdendencies on user32.dll through third party
libraries, but those can't easily be removed.

Dave Page
2007-10-23 17:58:01 +00:00

62 lines
1.2 KiB
C

/*-------------------------------------------------------------------------
*
* kill.c
* kill()
*
* Copyright (c) 1996-2007, PostgreSQL Global Development Group
*
* This is a replacement version of kill for Win32 which sends
* signals that the backend can recognize.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/port/kill.c,v 1.9 2007/10/23 17:58:01 mha Exp $
*
*-------------------------------------------------------------------------
*/
#include "c.h"
#ifdef WIN32
/* signal sending */
int
pgkill(int pid, int sig)
{
char pipename[128];
BYTE sigData = sig;
BYTE sigRet = 0;
DWORD bytes;
/* we allow signal 0 here, but it will be ignored in pg_queue_signal */
if (sig >= PG_SIGNAL_COUNT || sig < 0)
{
errno = EINVAL;
return -1;
}
if (pid <= 0)
{
/* No support for process groups */
errno = EINVAL;
return -1;
}
snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\pgsignal_%u", pid);
if (!CallNamedPipe(pipename, &sigData, 1, &sigRet, 1, &bytes, 1000))
{
if (GetLastError() == ERROR_FILE_NOT_FOUND)
errno = ESRCH;
else if (GetLastError() == ERROR_ACCESS_DENIED)
errno = EPERM;
else
errno = EINVAL;
return -1;
}
if (bytes != 1 || sigRet != sig)
{
errno = ESRCH;
return -1;
}
return 0;
}
#endif