Re: pg_ctl.c - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: pg_ctl.c
Date
Msg-id 200405271307.i4RD7oO13463@candle.pha.pa.us
Whole thread Raw
In response to Re: pg_ctl.c  ("Magnus Hagander" <mha@sollentuna.net>)
List pgsql-patches
Magnus Hagander wrote:
> Seems it needs an implementation of the "pgwin32 special kill". Try
> stealing the one from  backend/port/win32/signal.c (look for pqkill).
>
> Perhaps this function (not the rest of signal.c!) should be moved into
> port/, instead of backend/port. IIRC it depends on no other backend
> code.

OK, patch attached and applied, and new kill.c file that goes into
/port.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure
===================================================================
RCS file: /cvsroot/pgsql-server/configure,v
retrieving revision 1.369
diff -c -c -r1.369 configure
*** configure    22 May 2004 00:34:49 -0000    1.369
--- configure    27 May 2004 13:05:41 -0000
***************
*** 12014,12019 ****
--- 12014,12020 ----
  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
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.358
diff -c -c -r1.358 configure.in
*** configure.in    22 May 2004 00:34:49 -0000    1.358
--- configure.in    27 May 2004 13:05:43 -0000
***************
*** 891,896 ****
--- 891,897 ----
  case $host_os in mingw*)
  AC_LIBOBJ(copydir)
  AC_LIBOBJ(gettimeofday)
+ AC_LIBOBJ(kill)
  AC_LIBOBJ(open)
  AC_LIBOBJ(rand) ;;
  esac
Index: src/backend/port/win32/signal.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/port/win32/signal.c,v
retrieving revision 1.1
diff -c -c -r1.1 signal.c
*** src/backend/port/win32/signal.c    12 Apr 2004 16:19:18 -0000    1.1
--- src/backend/port/win32/signal.c    27 May 2004 13:05:48 -0000
***************
*** 152,197 ****
      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!
--- 152,157 ----
Index: src/include/port/win32.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/port/win32.h,v
retrieving revision 1.23
diff -c -c -r1.23 win32.h
*** src/include/port/win32.h    22 Apr 2004 03:51:24 -0000    1.23
--- src/include/port/win32.h    27 May 2004 13:06:03 -0000
***************
*** 116,125 ****
  #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 pg_usleep(t) pgwin32_backend_usleep(t)
  void pgwin32_backend_usleep(long microsec);
  #endif
--- 116,125 ----
  #define SIG_ERR ((pqsigfunc)-1)
  #define SIG_IGN ((pqsigfunc)1)

! #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
/*-------------------------------------------------------------------------
 *
 * 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-server/src/port/pipe.c,v 1.4 2004/05/18 20:18:59 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

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Relocatable locale
Next
From: Peter Eisentraut
Date:
Subject: Re: Relocatable locale