gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

95 行
3.0KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * pmsignal.h
  4. * routines for signaling the postmaster from its child processes
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2019, 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_WAKEN_ARCHIVER, /* send a NOTIFY signal to xlog archiver */
  34. PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */
  35. PMSIGNAL_START_AUTOVAC_LAUNCHER, /* start an autovacuum launcher */
  36. PMSIGNAL_START_AUTOVAC_WORKER, /* start an autovacuum worker */
  37. PMSIGNAL_BACKGROUND_WORKER_CHANGE, /* background worker state change */
  38. PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */
  39. PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */
  40. NUM_PMSIGNALS /* Must be last value of enum! */
  41. } PMSignalReason;
  42. /* PMSignalData is an opaque struct, details known only within pmsignal.c */
  43. typedef struct PMSignalData PMSignalData;
  44. /*
  45. * prototypes for functions in pmsignal.c
  46. */
  47. extern Size PMSignalShmemSize(void);
  48. extern void PMSignalShmemInit(void);
  49. extern void SendPostmasterSignal(PMSignalReason reason);
  50. extern bool CheckPostmasterSignal(PMSignalReason reason);
  51. extern int AssignPostmasterChildSlot(void);
  52. extern bool ReleasePostmasterChildSlot(int slot);
  53. extern bool IsPostmasterChildWalSender(int slot);
  54. extern void MarkPostmasterChildActive(void);
  55. extern void MarkPostmasterChildInactive(void);
  56. extern void MarkPostmasterChildWalSender(void);
  57. extern bool PostmasterIsAliveInternal(void);
  58. extern void PostmasterDeathSignalInit(void);
  59. /*
  60. * Do we have a way to ask for a signal on parent death?
  61. *
  62. * If we do, pmsignal.c will set up a signal handler, that sets a flag when
  63. * the parent dies. Checking the flag first makes PostmasterIsAlive() a lot
  64. * cheaper in usual case that the postmaster is alive.
  65. */
  66. #if (defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_PDEATHSIG)) || \
  67. (defined(HAVE_SYS_PROCCTL_H) && defined(PROC_PDEATHSIG_CTL))
  68. #define USE_POSTMASTER_DEATH_SIGNAL
  69. #endif
  70. #ifdef USE_POSTMASTER_DEATH_SIGNAL
  71. extern volatile sig_atomic_t postmaster_possibly_dead;
  72. static inline bool
  73. PostmasterIsAlive(void)
  74. {
  75. if (likely(!postmaster_possibly_dead))
  76. return true;
  77. return PostmasterIsAliveInternal();
  78. }
  79. #else
  80. #define PostmasterIsAlive() PostmasterIsAliveInternal()
  81. #endif
  82. #endif /* PMSIGNAL_H */
上海开阖软件有限公司 沪ICP备12045867号-1