1 /*-------------------------------------------------------------------------
4 * reliable BSD-style signal(2) routine stolen from RWW who stole it
7 * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
14 * We now assume that all Unix-oid systems have POSIX sigaction(2)
15 * with support for restartable signals (SA_RESTART). We used to also
16 * support BSD-style signal(2), but there really shouldn't be anything
17 * out there anymore that doesn't have the POSIX API.
19 * Windows, of course, is resolutely in a class by itself. In the backend,
20 * we don't use this file at all; src/backend/port/win32/signal.c provides
21 * pqsignal() for the backend environment. Frontend programs can use
22 * this version of pqsignal() if they wish, but beware that this does
23 * not provide restartable signals on Windows.
25 * ------------------------------------------------------------------------
32 #if !defined(WIN32) || defined(FRONTEND)
35 * Set up a signal handler for signal "signo"
37 * Returns the previous handler.
40 pqsignal(int signo, pqsigfunc func)
46 act.sa_handler = func;
47 sigemptyset(&act.sa_mask);
48 act.sa_flags = SA_RESTART;
51 act.sa_flags |= SA_NOCLDSTOP;
53 if (sigaction(signo, &act, &oact) < 0)
55 return oact.sa_handler;
57 return signal(signo, func);
61 #endif /* !defined(WIN32) || defined(FRONTEND) */