LCOV - code coverage report
Current view: top level - src/backend/postmaster - interrupt.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 54.5 % 22 12
Test Date: 2026-01-26 10:56:24 Functions: 50.0 % 4 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 75.0 % 8 6

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  *
       3                 :             :  * interrupt.c
       4                 :             :  *        Interrupt handling routines.
       5                 :             :  *
       6                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       7                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
       8                 :             :  *
       9                 :             :  * IDENTIFICATION
      10                 :             :  *        src/backend/postmaster/interrupt.c
      11                 :             :  *
      12                 :             :  *-------------------------------------------------------------------------
      13                 :             :  */
      14                 :             : 
      15                 :             : #include "postgres.h"
      16                 :             : 
      17                 :             : #include <unistd.h>
      18                 :             : 
      19                 :             : #include "miscadmin.h"
      20                 :             : #include "postmaster/interrupt.h"
      21                 :             : #include "storage/ipc.h"
      22                 :             : #include "storage/latch.h"
      23                 :             : #include "storage/procsignal.h"
      24                 :             : #include "utils/guc.h"
      25                 :             : #include "utils/memutils.h"
      26                 :             : 
      27                 :             : volatile sig_atomic_t ConfigReloadPending = false;
      28                 :             : volatile sig_atomic_t ShutdownRequestPending = false;
      29                 :             : 
      30                 :             : /*
      31                 :             :  * Simple interrupt handler for main loops of background processes.
      32                 :             :  */
      33                 :             : void
      34                 :          55 : ProcessMainLoopInterrupts(void)
      35                 :             : {
      36         [ +  + ]:          55 :         if (ProcSignalBarrierPending)
      37                 :           1 :                 ProcessProcSignalBarrier();
      38                 :             : 
      39         [ +  - ]:          55 :         if (ConfigReloadPending)
      40                 :             :         {
      41                 :           0 :                 ConfigReloadPending = false;
      42                 :           0 :                 ProcessConfigFile(PGC_SIGHUP);
      43                 :           0 :         }
      44                 :             : 
      45         [ +  + ]:          55 :         if (ShutdownRequestPending)
      46                 :           2 :                 proc_exit(0);
      47                 :             : 
      48                 :             :         /* Perform logging of memory contexts of this process */
      49         [ +  - ]:          53 :         if (LogMemoryContextPending)
      50                 :           0 :                 ProcessLogMemoryContextInterrupt();
      51                 :          53 : }
      52                 :             : 
      53                 :             : /*
      54                 :             :  * Simple signal handler for triggering a configuration reload.
      55                 :             :  *
      56                 :             :  * Normally, this handler would be used for SIGHUP. The idea is that code
      57                 :             :  * which uses it would arrange to check the ConfigReloadPending flag at
      58                 :             :  * convenient places inside main loops, or else call ProcessMainLoopInterrupts.
      59                 :             :  */
      60                 :             : void
      61                 :           0 : SignalHandlerForConfigReload(SIGNAL_ARGS)
      62                 :             : {
      63                 :           0 :         ConfigReloadPending = true;
      64                 :           0 :         SetLatch(MyLatch);
      65                 :           0 : }
      66                 :             : 
      67                 :             : /*
      68                 :             :  * Simple signal handler for exiting quickly as if due to a crash.
      69                 :             :  *
      70                 :             :  * Normally, this would be used for handling SIGQUIT.
      71                 :             :  */
      72                 :             : void
      73                 :           0 : SignalHandlerForCrashExit(SIGNAL_ARGS)
      74                 :             : {
      75                 :             :         /*
      76                 :             :          * We DO NOT want to run proc_exit() or atexit() callbacks -- we're here
      77                 :             :          * because shared memory may be corrupted, so we don't want to try to
      78                 :             :          * clean up our transaction.  Just nail the windows shut and get out of
      79                 :             :          * town.  The callbacks wouldn't be safe to run from a signal handler,
      80                 :             :          * anyway.
      81                 :             :          *
      82                 :             :          * Note we do _exit(2) not _exit(0).  This is to force the postmaster into
      83                 :             :          * a system reset cycle if someone sends a manual SIGQUIT to a random
      84                 :             :          * backend.  This is necessary precisely because we don't clean up our
      85                 :             :          * shared memory state.  (The "dead man switch" mechanism in pmsignal.c
      86                 :             :          * should ensure the postmaster sees this as a crash, too, but no harm in
      87                 :             :          * being doubly sure.)
      88                 :             :          */
      89                 :           0 :         _exit(2);
      90                 :             : }
      91                 :             : 
      92                 :             : /*
      93                 :             :  * Simple signal handler for triggering a long-running background process to
      94                 :             :  * shut down and exit.
      95                 :             :  *
      96                 :             :  * Typically, this handler would be used for SIGTERM, but some processes use
      97                 :             :  * other signals. In particular, the checkpointer and parallel apply worker
      98                 :             :  * exit on SIGUSR2, and the WAL writer exits on either SIGINT or SIGTERM.
      99                 :             :  *
     100                 :             :  * ShutdownRequestPending should be checked at a convenient place within the
     101                 :             :  * main loop, or else the main loop should call ProcessMainLoopInterrupts.
     102                 :             :  */
     103                 :             : void
     104                 :           7 : SignalHandlerForShutdownRequest(SIGNAL_ARGS)
     105                 :             : {
     106                 :           7 :         ShutdownRequestPending = true;
     107                 :           7 :         SetLatch(MyLatch);
     108                 :           7 : }
        

Generated by: LCOV version 2.3.2-1