LCOV - differential code coverage report
Current view: top level - src/backend/postmaster - interrupt.c (source / functions) Coverage Total Hit UBC GNC CBC DCB
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 95.2 % 21 20 1 20 4
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 4 4 2 2
Baseline: 16@8cea358b128 Branches: 87.5 % 8 7 1 7
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed [..60] days: 100.0 % 1 1 1
(240..) days: 95.0 % 20 19 1 19
Function coverage date bins:
(240..) days: 100.0 % 4 4 2 2
Branch coverage date bins:
(240..) days: 87.5 % 8 7 1 7

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * interrupt.c
                                  4                 :                :  *    Interrupt handling routines.
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2024, 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
 1580 rhaas@postgresql.org       34                 :CBC       30855 : HandleMainLoopInterrupts(void)
                                 35                 :                : {
 1578                            36         [ +  + ]:          30855 :     if (ProcSignalBarrierPending)
                                 37                 :            163 :         ProcessProcSignalBarrier();
                                 38                 :                : 
 1580                            39         [ +  + ]:          30855 :     if (ConfigReloadPending)
                                 40                 :                :     {
                                 41                 :            227 :         ConfigReloadPending = false;
                                 42                 :            227 :         ProcessConfigFile(PGC_SIGHUP);
                                 43                 :                :     }
                                 44                 :                : 
                                 45         [ +  + ]:          30855 :     if (ShutdownRequestPending)
                                 46                 :            805 :         proc_exit(0);
                                 47                 :                : 
                                 48                 :                :     /* Perform logging of memory contexts of this process */
  824 fujii@postgresql.org       49         [ -  + ]:          30050 :     if (LogMemoryContextPending)
  824 fujii@postgresql.org       50                 :UBC           0 :         ProcessLogMemoryContextInterrupt();
 1580 rhaas@postgresql.org       51                 :CBC       30050 : }
                                 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                 :            754 : SignalHandlerForConfigReload(SIGNAL_ARGS)
                                 62                 :                : {
                                 63                 :            754 :     ConfigReloadPending = true;
                                 64                 :            754 :     SetLatch(MyLatch);
                                 65                 :            754 : }
                                 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                 :           1521 : 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 exit with code 2, not 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                 :                :      */
    0 andres@anarazel.de         89                 :           1521 :     immediate_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 exits on SIGUSR2, and the WAL
                                 98                 :                :  * writer and the logical replication parallel apply worker exits on either
                                 99                 :                :  * SIGINT or SIGTERM.
                                100                 :                :  *
                                101                 :                :  * ShutdownRequestPending should be checked at a convenient place within the
                                102                 :                :  * main loop, or else the main loop should call HandleMainLoopInterrupts.
                                103                 :                :  */
                                104                 :                : void
 1580 rhaas@postgresql.org      105                 :           1694 : SignalHandlerForShutdownRequest(SIGNAL_ARGS)
                                106                 :                : {
                                107                 :           1694 :     ShutdownRequestPending = true;
                                108                 :           1694 :     SetLatch(MyLatch);
                                109                 :           1694 : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622