2013-03-17 17:06:42 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pqsignal.c
|
|
|
|
* reliable BSD-style signal(2) routine stolen from RWW who stole it
|
|
|
|
* from Stevens...
|
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
|
2013-03-17 17:06:42 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/port/pqsignal.c
|
|
|
|
*
|
Remove support for Unix systems without the POSIX signal APIs.
Remove configure's checks for HAVE_POSIX_SIGNALS, HAVE_SIGPROCMASK, and
HAVE_SIGSETJMP. These APIs are required by the Single Unix Spec v2
(POSIX 1997), which we generally consider to define our minimum required
set of Unix APIs. Moreover, no buildfarm member has reported not having
them since 2012 or before, which means that even if the code is still live
somewhere, it's untested --- and we've made plenty of signal-handling
changes of late. So just take these APIs as given and save the cycles for
configure probes for them.
However, we can't remove as much C code as I'd hoped, because the Windows
port evidently still uses the non-POSIX code paths for signal masking.
Since we're largely emulating these BSD-style APIs for Windows anyway, it
might be a good thing to switch over to POSIX-like notation and thereby
remove a few more #ifdefs. But I'm not in a position to code or test that.
In the meantime, we can at least make things a bit more transparent by
testing for WIN32 explicitly in these places.
2015-08-31 18:55:59 +02:00
|
|
|
* We now assume that all Unix-oid systems have POSIX sigaction(2)
|
|
|
|
* with support for restartable signals (SA_RESTART). We used to also
|
|
|
|
* support BSD-style signal(2), but there really shouldn't be anything
|
|
|
|
* out there anymore that doesn't have the POSIX API.
|
2013-03-17 17:06:42 +01:00
|
|
|
*
|
2013-03-17 20:19:47 +01:00
|
|
|
* Windows, of course, is resolutely in a class by itself. In the backend,
|
|
|
|
* we don't use this file at all; src/backend/port/win32/signal.c provides
|
|
|
|
* pqsignal() for the backend environment. Frontend programs can use
|
Remove support for Unix systems without the POSIX signal APIs.
Remove configure's checks for HAVE_POSIX_SIGNALS, HAVE_SIGPROCMASK, and
HAVE_SIGSETJMP. These APIs are required by the Single Unix Spec v2
(POSIX 1997), which we generally consider to define our minimum required
set of Unix APIs. Moreover, no buildfarm member has reported not having
them since 2012 or before, which means that even if the code is still live
somewhere, it's untested --- and we've made plenty of signal-handling
changes of late. So just take these APIs as given and save the cycles for
configure probes for them.
However, we can't remove as much C code as I'd hoped, because the Windows
port evidently still uses the non-POSIX code paths for signal masking.
Since we're largely emulating these BSD-style APIs for Windows anyway, it
might be a good thing to switch over to POSIX-like notation and thereby
remove a few more #ifdefs. But I'm not in a position to code or test that.
In the meantime, we can at least make things a bit more transparent by
testing for WIN32 explicitly in these places.
2015-08-31 18:55:59 +02:00
|
|
|
* this version of pqsignal() if they wish, but beware that this does
|
|
|
|
* not provide restartable signals on Windows.
|
|
|
|
*
|
2013-03-17 17:06:42 +01:00
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "c.h"
|
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
2013-03-17 20:19:47 +01:00
|
|
|
#if !defined(WIN32) || defined(FRONTEND)
|
2013-03-17 17:06:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up a signal handler for signal "signo"
|
|
|
|
*
|
2013-03-17 20:19:47 +01:00
|
|
|
* Returns the previous handler.
|
2013-03-17 17:06:42 +01:00
|
|
|
*/
|
|
|
|
pqsigfunc
|
|
|
|
pqsignal(int signo, pqsigfunc func)
|
|
|
|
{
|
Remove support for Unix systems without the POSIX signal APIs.
Remove configure's checks for HAVE_POSIX_SIGNALS, HAVE_SIGPROCMASK, and
HAVE_SIGSETJMP. These APIs are required by the Single Unix Spec v2
(POSIX 1997), which we generally consider to define our minimum required
set of Unix APIs. Moreover, no buildfarm member has reported not having
them since 2012 or before, which means that even if the code is still live
somewhere, it's untested --- and we've made plenty of signal-handling
changes of late. So just take these APIs as given and save the cycles for
configure probes for them.
However, we can't remove as much C code as I'd hoped, because the Windows
port evidently still uses the non-POSIX code paths for signal masking.
Since we're largely emulating these BSD-style APIs for Windows anyway, it
might be a good thing to switch over to POSIX-like notation and thereby
remove a few more #ifdefs. But I'm not in a position to code or test that.
In the meantime, we can at least make things a bit more transparent by
testing for WIN32 explicitly in these places.
2015-08-31 18:55:59 +02:00
|
|
|
#ifndef WIN32
|
2013-03-17 17:06:42 +01:00
|
|
|
struct sigaction act,
|
|
|
|
oact;
|
|
|
|
|
|
|
|
act.sa_handler = func;
|
|
|
|
sigemptyset(&act.sa_mask);
|
2013-06-15 21:39:51 +02:00
|
|
|
act.sa_flags = SA_RESTART;
|
2013-03-17 17:06:42 +01:00
|
|
|
#ifdef SA_NOCLDSTOP
|
|
|
|
if (signo == SIGCHLD)
|
|
|
|
act.sa_flags |= SA_NOCLDSTOP;
|
|
|
|
#endif
|
|
|
|
if (sigaction(signo, &act, &oact) < 0)
|
|
|
|
return SIG_ERR;
|
|
|
|
return oact.sa_handler;
|
Remove support for Unix systems without the POSIX signal APIs.
Remove configure's checks for HAVE_POSIX_SIGNALS, HAVE_SIGPROCMASK, and
HAVE_SIGSETJMP. These APIs are required by the Single Unix Spec v2
(POSIX 1997), which we generally consider to define our minimum required
set of Unix APIs. Moreover, no buildfarm member has reported not having
them since 2012 or before, which means that even if the code is still live
somewhere, it's untested --- and we've made plenty of signal-handling
changes of late. So just take these APIs as given and save the cycles for
configure probes for them.
However, we can't remove as much C code as I'd hoped, because the Windows
port evidently still uses the non-POSIX code paths for signal masking.
Since we're largely emulating these BSD-style APIs for Windows anyway, it
might be a good thing to switch over to POSIX-like notation and thereby
remove a few more #ifdefs. But I'm not in a position to code or test that.
In the meantime, we can at least make things a bit more transparent by
testing for WIN32 explicitly in these places.
2015-08-31 18:55:59 +02:00
|
|
|
#else /* WIN32 */
|
|
|
|
return signal(signo, func);
|
|
|
|
#endif
|
2013-03-17 17:06:42 +01:00
|
|
|
}
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
#endif /* !defined(WIN32) || defined(FRONTEND) */
|