LCOV - differential code coverage report
Current view: top level - src/backend/postmaster - interrupt.c (source / functions) Coverage Total Hit UBC GIC CBC ECB
Current: Differential Code Coverage HEAD vs 15 Lines: 88.0 % 25 22 3 4 18 4
Current Date: 2023-04-08 15:15:32 Functions: 75.0 % 4 3 1 1 2 1
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /*-------------------------------------------------------------------------
       2                 :  *
       3                 :  * interrupt.c
       4                 :  *    Interrupt handling routines.
       5                 :  *
       6                 :  * Portions Copyright (c) 1996-2023, 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 CBC       10790 : HandleMainLoopInterrupts(void)
      35                 : {
      36           10790 :     if (ProcSignalBarrierPending)
      37              38 :         ProcessProcSignalBarrier();
      38                 : 
      39           10790 :     if (ConfigReloadPending)
      40                 :     {
      41              36 :         ConfigReloadPending = false;
      42              36 :         ProcessConfigFile(PGC_SIGHUP);
      43                 :     }
      44                 : 
      45           10790 :     if (ShutdownRequestPending)
      46             352 :         proc_exit(0);
      47                 : 
      48                 :     /* Perform logging of memory contexts of this process */
      49           10438 :     if (LogMemoryContextPending)
      50 UBC           0 :         ProcessLogMemoryContextInterrupt();
      51 CBC       10438 : }
      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 HandleMainLoopInterrupts.
      59                 :  */
      60                 : void
      61             304 : SignalHandlerForConfigReload(SIGNAL_ARGS)
      62                 : {
      63             304 :     int         save_errno = errno;
      64                 : 
      65             304 :     ConfigReloadPending = true;
      66             304 :     SetLatch(MyLatch);
      67                 : 
      68             304 :     errno = save_errno;
      69             304 : }
      70                 : 
      71                 : /*
      72                 :  * Simple signal handler for exiting quickly as if due to a crash.
      73                 :  *
      74                 :  * Normally, this would be used for handling SIGQUIT.
      75                 :  */
      76                 : void
      77 UBC           0 : SignalHandlerForCrashExit(SIGNAL_ARGS)
      78                 : {
      79                 :     /*
      80                 :      * We DO NOT want to run proc_exit() or atexit() callbacks -- we're here
      81                 :      * because shared memory may be corrupted, so we don't want to try to
      82                 :      * clean up our transaction.  Just nail the windows shut and get out of
      83                 :      * town.  The callbacks wouldn't be safe to run from a signal handler,
      84                 :      * anyway.
      85                 :      *
      86                 :      * Note we do _exit(2) not _exit(0).  This is to force the postmaster into
      87                 :      * a system reset cycle if someone sends a manual SIGQUIT to a random
      88                 :      * backend.  This is necessary precisely because we don't clean up our
      89                 :      * shared memory state.  (The "dead man switch" mechanism in pmsignal.c
      90                 :      * should ensure the postmaster sees this as a crash, too, but no harm in
      91                 :      * being doubly sure.)
      92                 :      */
      93               0 :     _exit(2);
      94                 : }
      95                 : 
      96                 : /*
      97                 :  * Simple signal handler for triggering a long-running background process to
      98                 :  * shut down and exit.
      99                 :  *
     100                 :  * Typically, this handler would be used for SIGTERM, but some processes use
     101                 :  * other signals. In particular, the checkpointer exits on SIGUSR2, and the WAL
     102                 :  * writer and the logical replication parallel apply worker exits on either
     103                 :  * SIGINT or SIGTERM.
     104                 :  *
     105                 :  * ShutdownRequestPending should be checked at a convenient place within the
     106                 :  * main loop, or else the main loop should call HandleMainLoopInterrupts.
     107                 :  */
     108                 : void
     109 GIC        1392 : SignalHandlerForShutdownRequest(SIGNAL_ARGS)
     110 ECB             : {
     111 GIC        1392 :     int         save_errno = errno;
     112 ECB             : 
     113 GIC        1392 :     ShutdownRequestPending = true;
     114 CBC        1392 :     SetLatch(MyLatch);
     115 ECB             : 
     116 GIC        1392 :     errno = save_errno;
     117 CBC        1392 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a