Move pgkill out into /port so pg_ctl can use it on Win32.

This commit is contained in:
Bruce Momjian 2004-05-27 13:08:57 +00:00
parent d157b7bbc7
commit 6f21f4adaa
5 changed files with 67 additions and 46 deletions

1
configure vendored
View File

@ -12014,6 +12014,7 @@ esac
case $host_os in mingw*)
LIBOBJS="$LIBOBJS copydir.$ac_objext"
LIBOBJS="$LIBOBJS gettimeofday.$ac_objext"
LIBOBJS="$LIBOBJS kill.$ac_objext"
LIBOBJS="$LIBOBJS open.$ac_objext"
LIBOBJS="$LIBOBJS rand.$ac_objext" ;;
esac

View File

@ -1,5 +1,5 @@
dnl Process this file with autoconf to produce a configure script.
dnl $PostgreSQL: pgsql/configure.in,v 1.358 2004/05/22 00:34:49 tgl Exp $
dnl $PostgreSQL: pgsql/configure.in,v 1.359 2004/05/27 13:08:48 momjian Exp $
dnl
dnl Developers, please strive to achieve this order:
dnl
@ -891,6 +891,7 @@ esac
case $host_os in mingw*)
AC_LIBOBJ(copydir)
AC_LIBOBJ(gettimeofday)
AC_LIBOBJ(kill)
AC_LIBOBJ(open)
AC_LIBOBJ(rand) ;;
esac

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/port/win32/signal.c,v 1.1 2004/04/12 16:19:18 momjian Exp $
* $PostgreSQL: pgsql/src/backend/port/win32/signal.c,v 1.2 2004/05/27 13:08:50 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -152,46 +152,6 @@ pqsignal(int signum, pqsigfunc handler)
return prevfunc;
}
/* signal sending */
int
pqkill(int pid, int sig)
{
char pipename[128];
BYTE sigData = sig;
BYTE sigRet = 0;
DWORD bytes;
if (sig >= PG_SIGNAL_COUNT || sig <= 0)
{
errno = EINVAL;
return -1;
}
if (pid <= 0)
{
/* No support for process groups */
errno = EINVAL;
return -1;
}
wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%i", 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;
}
/*
* All functions below execute on the signal handler thread
* and must be synchronized as such!

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.23 2004/04/22 03:51:24 momjian Exp $ */
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.24 2004/05/27 13:08:54 momjian Exp $ */
/* undefine and redefine after #include */
#undef mkdir
@ -116,10 +116,10 @@ void pg_queue_signal(int signum);
#define SIG_ERR ((pqsigfunc)-1)
#define SIG_IGN ((pqsigfunc)1)
#ifndef FRONTEND
#define kill(pid,sig) pqkill(pid,sig)
extern int pqkill(int pid, int sig);
#define kill(pid,sig) pgkill(pid,sig)
extern int pgkill(int pid, int sig);
#ifndef FRONTEND
#define pg_usleep(t) pgwin32_backend_usleep(t)
void pgwin32_backend_usleep(long microsec);
#endif

59
src/port/kill.c Normal file
View File

@ -0,0 +1,59 @@
/*-------------------------------------------------------------------------
*
* kill.c
* kill()
*
* Copyright (c) 1996-2003, 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.1 2004/05/27 13:08:57 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#ifdef WIN32
/* signal sending */
int
pgkill(int pid, int sig)
{
char pipename[128];
BYTE sigData = sig;
BYTE sigRet = 0;
DWORD bytes;
if (sig >= PG_SIGNAL_COUNT || sig <= 0)
{
errno = EINVAL;
return -1;
}
if (pid <= 0)
{
/* No support for process groups */
errno = EINVAL;
return -1;
}
wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%i", 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