2
0

pmsignal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*-------------------------------------------------------------------------
  2. *
  3. * pmsignal.h
  4. * routines for signaling between the postmaster and its child processes
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, 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. #include <signal.h>
  17. #ifdef HAVE_SYS_PRCTL_H
  18. #include "sys/prctl.h"
  19. #endif
  20. #ifdef HAVE_SYS_PROCCTL_H
  21. #include "sys/procctl.h"
  22. #endif
  23. /*
  24. * Reasons for signaling the postmaster. We can cope with simultaneous
  25. * signals for different reasons. If the same reason is signaled multiple
  26. * times in quick succession, however, the postmaster is likely to observe
  27. * only one notification of it. This is okay for the present uses.
  28. */
  29. typedef enum
  30. {
  31. PMSIGNAL_RECOVERY_STARTED, /* recovery has started */
  32. PMSIGNAL_BEGIN_HOT_STANDBY, /* begin Hot Standby */
  33. PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */
  34. PMSIGNAL_START_AUTOVAC_LAUNCHER, /* start an autovacuum launcher */
  35. PMSIGNAL_START_AUTOVAC_WORKER, /* start an autovacuum worker */
  36. PMSIGNAL_BACKGROUND_WORKER_CHANGE, /* background worker state change */
  37. PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */
  38. PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */
  39. NUM_PMSIGNALS /* Must be last value of enum! */
  40. } PMSignalReason;
  41. /*
  42. * Reasons why the postmaster would send SIGQUIT to its children.
  43. */
  44. typedef enum
  45. {
  46. PMQUIT_NOT_SENT = 0, /* postmaster hasn't sent SIGQUIT */
  47. PMQUIT_FOR_CRASH, /* some other backend bought the farm */
  48. PMQUIT_FOR_STOP /* immediate stop was commanded */
  49. } QuitSignalReason;
  50. /* PMSignalData is an opaque struct, details known only within pmsignal.c */
  51. typedef struct PMSignalData PMSignalData;
  52. /*
  53. * prototypes for functions in pmsignal.c
  54. */
  55. extern Size PMSignalShmemSize(void);
  56. extern void PMSignalShmemInit(void);
  57. extern void SendPostmasterSignal(PMSignalReason reason);
  58. extern bool CheckPostmasterSignal(PMSignalReason reason);
  59. extern void SetQuitSignalReason(QuitSignalReason reason);
  60. extern QuitSignalReason GetQuitSignalReason(void);
  61. extern int AssignPostmasterChildSlot(void);
  62. extern bool ReleasePostmasterChildSlot(int slot);
  63. extern bool IsPostmasterChildWalSender(int slot);
  64. extern void MarkPostmasterChildActive(void);
  65. extern void MarkPostmasterChildInactive(void);
  66. extern void MarkPostmasterChildWalSender(void);
  67. extern bool PostmasterIsAliveInternal(void);
  68. extern void PostmasterDeathSignalInit(void);
  69. /*
  70. * Do we have a way to ask for a signal on parent death?
  71. *
  72. * If we do, pmsignal.c will set up a signal handler, that sets a flag when
  73. * the parent dies. Checking the flag first makes PostmasterIsAlive() a lot
  74. * cheaper in usual case that the postmaster is alive.
  75. */
  76. #if (defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_PDEATHSIG)) || \
  77. (defined(HAVE_SYS_PROCCTL_H) && defined(PROC_PDEATHSIG_CTL))
  78. #define USE_POSTMASTER_DEATH_SIGNAL
  79. #endif
  80. #ifdef USE_POSTMASTER_DEATH_SIGNAL
  81. extern PGDLLIMPORT volatile sig_atomic_t postmaster_possibly_dead;
  82. static inline bool
  83. PostmasterIsAlive(void)
  84. {
  85. if (likely(!postmaster_possibly_dead))
  86. return true;
  87. return PostmasterIsAliveInternal();
  88. }
  89. #else
  90. #define PostmasterIsAlive() PostmasterIsAliveInternal()
  91. #endif
  92. #endif /* PMSIGNAL_H */