YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/build/debugcov-clang-dynamic-arm64-ninja/postgres_build/src/interfaces/libpq/pqsignal.c
Line
Count
Source (jump to first uncovered line)
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-2018, 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
pqsignal(int signo, pqsigfunc func)
41
79.3k
{
42
79.3k
#ifndef WIN32
43
79.3k
  struct sigaction act,
44
79.3k
        oact;
45
46
79.3k
  act.sa_handler = func;
47
79.3k
  sigemptyset(&act.sa_mask);
48
79.3k
  act.sa_flags = SA_RESTART;
49
79.3k
#ifdef SA_NOCLDSTOP
50
79.3k
  if (signo == SIGCHLD)
51
5.25k
    act.sa_flags |= SA_NOCLDSTOP;
52
79.3k
#endif
53
79.3k
  if (sigaction(signo, &act, &oact) < 0)
54
0
    return SIG_ERR;
55
79.3k
  return oact.sa_handler;
56
#else             /* WIN32 */
57
  return signal(signo, func);
58
#endif
59
79.3k
}
60
61
/*
62
 * Set up a signal handler, without SA_RESTART, for signal "signo"
63
 *
64
 * Returns the previous handler.
65
 *
66
 * On Windows, this would be identical to pqsignal(), so don't bother.
67
 */
68
#ifndef WIN32
69
70
pqsigfunc
71
pqsignal_no_restart(int signo, pqsigfunc func)
72
6.32k
{
73
6.32k
  struct sigaction act,
74
6.32k
        oact;
75
76
6.32k
  act.sa_handler = func;
77
6.32k
  sigemptyset(&act.sa_mask);
78
6.32k
  act.sa_flags = 0;
79
6.32k
#ifdef SA_NOCLDSTOP
80
6.32k
  if (signo == SIGCHLD)
81
904
    act.sa_flags |= SA_NOCLDSTOP;
82
6.32k
#endif
83
6.32k
  if (sigaction(signo, &act, &oact) < 0)
84
0
    return SIG_ERR;
85
6.32k
  return oact.sa_handler;
86
6.32k
}
87
88
#endif              /* !WIN32 */
89
90
#endif              /* !defined(WIN32) || defined(FRONTEND) */