LCOV - code coverage report
Current view: top level - src/interfaces/libpq - legacy-pqsignal.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 10 11 90.9 %
Date: 2024-04-24 21:11:03 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  *
       3             :  * legacy-pqsignal.c
       4             :  *    reliable BSD-style signal(2) routine stolen from RWW who stole it
       5             :  *    from Stevens...
       6             :  *
       7             :  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
       8             :  * Portions Copyright (c) 1994, Regents of the University of California
       9             :  *
      10             :  *
      11             :  * IDENTIFICATION
      12             :  *    src/interfaces/libpq/legacy-pqsignal.c
      13             :  *
      14             :  *-------------------------------------------------------------------------
      15             :  */
      16             : #include "postgres_fe.h"
      17             : 
      18             : #include <signal.h>
      19             : 
      20             : 
      21             : /*
      22             :  * This version of pqsignal() exists only because pre-9.3 releases
      23             :  * of libpq exported pqsignal(), and some old client programs still
      24             :  * depend on that.  (Since 9.3, clients are supposed to get it from
      25             :  * libpgport instead.)
      26             :  *
      27             :  * Because it is only intended for backwards compatibility, we freeze it
      28             :  * with the semantics it had in 9.2; in particular, this has different
      29             :  * behavior for SIGALRM than the version in src/port/pqsignal.c.
      30             :  *
      31             :  * libpq itself does not use this.
      32             :  */
      33             : pqsigfunc
      34       60838 : pqsignal(int signo, pqsigfunc func)
      35             : {
      36             : #ifndef WIN32
      37             :     struct sigaction act,
      38             :                 oact;
      39             : 
      40       60838 :     act.sa_handler = func;
      41       60838 :     sigemptyset(&act.sa_mask);
      42       60838 :     act.sa_flags = 0;
      43       60838 :     if (signo != SIGALRM)
      44       46536 :         act.sa_flags |= SA_RESTART;
      45             : #ifdef SA_NOCLDSTOP
      46       60838 :     if (signo == SIGCHLD)
      47       14852 :         act.sa_flags |= SA_NOCLDSTOP;
      48             : #endif
      49       60838 :     if (sigaction(signo, &act, &oact) < 0)
      50           0 :         return SIG_ERR;
      51       60838 :     return oact.sa_handler;
      52             : #else                           /* WIN32 */
      53             :     return signal(signo, func);
      54             : #endif
      55             : }

Generated by: LCOV version 1.14