LCOV - code coverage report
Current view: top level - src/port - pqsignal.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 8 9 88.9 %
Date: 2019-11-21 12:06:29 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * pqsignal.c
       4             :  *    reliable BSD-style signal(2) routine stolen from RWW who stole it
       5             :  *    from Stevens...
       6             :  *
       7             :  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
       8             :  * Portions Copyright (c) 1994, Regents of the University of California
       9             :  *
      10             :  *
      11             :  * IDENTIFICATION
      12             :  *    src/port/pqsignal.c
      13             :  *
      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.
      18             :  *
      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.
      24             :  *
      25             :  * ------------------------------------------------------------------------
      26             :  */
      27             : 
      28             : #include "c.h"
      29             : 
      30             : #include <signal.h>
      31             : 
      32             : #if !defined(WIN32) || defined(FRONTEND)
      33             : 
      34             : /*
      35             :  * Set up a signal handler, with SA_RESTART, for signal "signo"
      36             :  *
      37             :  * Returns the previous handler.
      38             :  */
      39             : pqsigfunc
      40      164908 : pqsignal(int signo, pqsigfunc func)
      41             : {
      42             : #ifndef WIN32
      43             :     struct sigaction act,
      44             :                 oact;
      45             : 
      46      164908 :     act.sa_handler = func;
      47      164908 :     sigemptyset(&act.sa_mask);
      48      164908 :     act.sa_flags = SA_RESTART;
      49             : #ifdef SA_NOCLDSTOP
      50      164908 :     if (signo == SIGCHLD)
      51       11966 :         act.sa_flags |= SA_NOCLDSTOP;
      52             : #endif
      53      164908 :     if (sigaction(signo, &act, &oact) < 0)
      54           0 :         return SIG_ERR;
      55      164908 :     return oact.sa_handler;
      56             : #else                           /* WIN32 */
      57             :     return signal(signo, func);
      58             : #endif
      59             : }
      60             : 
      61             : #endif                          /* !defined(WIN32) || defined(FRONTEND) */

Generated by: LCOV version 1.13