LCOV - code coverage report
Current view: top level - src/include/storage - pmsignal.h (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 100.0 % 4 4
Test Date: 2026-07-25 22:15:46 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 100.0 % 2 2

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * pmsignal.h
       4                 :             :  *    routines for signaling between the postmaster and its child processes
       5                 :             :  *
       6                 :             :  *
       7                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       8                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
       9                 :             :  *
      10                 :             :  * src/include/storage/pmsignal.h
      11                 :             :  *
      12                 :             :  *-------------------------------------------------------------------------
      13                 :             :  */
      14                 :             : #ifndef PMSIGNAL_H
      15                 :             : #define PMSIGNAL_H
      16                 :             : 
      17                 :             : #include <signal.h>
      18                 :             : 
      19                 :             : #ifdef HAVE_SYS_PRCTL_H
      20                 :             : #include <sys/prctl.h>
      21                 :             : #endif
      22                 :             : 
      23                 :             : #ifdef HAVE_SYS_PROCCTL_H
      24                 :             : #include <sys/procctl.h>
      25                 :             : #endif
      26                 :             : 
      27                 :             : /*
      28                 :             :  * Reasons for signaling the postmaster.  We can cope with simultaneous
      29                 :             :  * signals for different reasons.  If the same reason is signaled multiple
      30                 :             :  * times in quick succession, however, the postmaster is likely to observe
      31                 :             :  * only one notification of it.  This is okay for the present uses.
      32                 :             :  */
      33                 :             : typedef enum
      34                 :             : {
      35                 :             :     PMSIGNAL_RECOVERY_STARTED,  /* recovery has started */
      36                 :             :     PMSIGNAL_RECOVERY_CONSISTENT,   /* recovery has reached consistent state */
      37                 :             :     PMSIGNAL_BEGIN_HOT_STANDBY, /* begin Hot Standby */
      38                 :             :     PMSIGNAL_ROTATE_LOGFILE,    /* send SIGUSR1 to syslogger to rotate logfile */
      39                 :             :     PMSIGNAL_START_AUTOVAC_LAUNCHER,    /* start an autovacuum launcher */
      40                 :             :     PMSIGNAL_START_AUTOVAC_WORKER,  /* start an autovacuum worker */
      41                 :             :     PMSIGNAL_IO_WORKER_GROW,    /* I/O worker pool wants to grow */
      42                 :             :     PMSIGNAL_BACKGROUND_WORKER_CHANGE,  /* background worker state change */
      43                 :             :     PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */
      44                 :             :     PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */
      45                 :             :     PMSIGNAL_XLOG_IS_SHUTDOWN,  /* ShutdownXLOG() completed */
      46                 :             : } PMSignalReason;
      47                 :             : 
      48                 :             : #define NUM_PMSIGNALS (PMSIGNAL_XLOG_IS_SHUTDOWN+1)
      49                 :             : 
      50                 :             : /*
      51                 :             :  * Reasons why the postmaster would send SIGQUIT to its children.
      52                 :             :  */
      53                 :             : typedef enum
      54                 :             : {
      55                 :             :     PMQUIT_NOT_SENT = 0,        /* postmaster hasn't sent SIGQUIT */
      56                 :             :     PMQUIT_FOR_CRASH,           /* some other backend bought the farm */
      57                 :             :     PMQUIT_FOR_STOP,            /* immediate stop was commanded */
      58                 :             : } QuitSignalReason;
      59                 :             : 
      60                 :             : /* PMSignalData is an opaque struct, details known only within pmsignal.c */
      61                 :             : typedef struct PMSignalData PMSignalData;
      62                 :             : 
      63                 :             : #ifdef EXEC_BACKEND
      64                 :             : extern PGDLLIMPORT volatile PMSignalData *PMSignalState;
      65                 :             : #endif
      66                 :             : 
      67                 :             : /*
      68                 :             :  * prototypes for functions in pmsignal.c
      69                 :             :  */
      70                 :             : extern void SendPostmasterSignal(PMSignalReason reason);
      71                 :             : extern bool CheckPostmasterSignal(PMSignalReason reason);
      72                 :             : extern void SetQuitSignalReason(QuitSignalReason reason);
      73                 :             : extern QuitSignalReason GetQuitSignalReason(void);
      74                 :             : extern void MarkPostmasterChildSlotAssigned(int slot);
      75                 :             : extern bool MarkPostmasterChildSlotUnassigned(int slot);
      76                 :             : extern bool IsPostmasterChildWalSender(int slot);
      77                 :             : extern void RegisterPostmasterChildActive(void);
      78                 :             : extern void MarkPostmasterChildWalSender(void);
      79                 :             : extern bool PostmasterIsAliveInternal(void);
      80                 :             : extern void PostmasterDeathSignalInit(void);
      81                 :             : 
      82                 :             : 
      83                 :             : /*
      84                 :             :  * Do we have a way to ask for a signal on parent death?
      85                 :             :  *
      86                 :             :  * If we do, pmsignal.c will set up a signal handler, that sets a flag when
      87                 :             :  * the parent dies.  Checking the flag first makes PostmasterIsAlive() a lot
      88                 :             :  * cheaper in usual case that the postmaster is alive.
      89                 :             :  */
      90                 :             : #if (defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_PDEATHSIG)) || \
      91                 :             :     (defined(HAVE_SYS_PROCCTL_H) && defined(PROC_PDEATHSIG_CTL))
      92                 :             : #define USE_POSTMASTER_DEATH_SIGNAL
      93                 :             : #endif
      94                 :             : 
      95                 :             : #ifdef USE_POSTMASTER_DEATH_SIGNAL
      96                 :             : extern PGDLLIMPORT volatile sig_atomic_t postmaster_possibly_dead;
      97                 :             : 
      98                 :             : static inline bool
      99                 :     2961997 : PostmasterIsAlive(void)
     100                 :             : {
     101         [ +  + ]:     2961997 :     if (likely(!postmaster_possibly_dead))
     102                 :     2961189 :         return true;
     103                 :         808 :     return PostmasterIsAliveInternal();
     104                 :             : }
     105                 :             : #else
     106                 :             : #define PostmasterIsAlive() PostmasterIsAliveInternal()
     107                 :             : #endif
     108                 :             : 
     109                 :             : #endif                          /* PMSIGNAL_H */
        

Generated by: LCOV version 2.0-1