Use signals for postmaster death on FreeBSD.
authorThomas Munro <tmunro@postgresql.org>
Wed, 11 Jul 2018 00:47:42 +0000 (12:47 +1200)
committerThomas Munro <tmunro@postgresql.org>
Wed, 11 Jul 2018 01:14:07 +0000 (13:14 +1200)
Use FreeBSD 11.2's new support for detecting parent process death to
make PostmasterIsAlive() very cheap, as was done for Linux in an
earlier commit.

Author: Thomas Munro
Discussion: https://postgr.es/m/7261eb39-0369-f2f4-1bb5-62f3b6083b5e@iki.fi

configure
configure.in
src/backend/storage/ipc/pmsignal.c
src/include/pg_config.h.in
src/include/storage/pmsignal.h

index 41e0e1cf34ab73c94c04fae218db49f94bf33c84..f891914ed9963e1d3a14fe98176a2b29943070a6 100755 (executable)
--- a/configure
+++ b/configure
@@ -12494,7 +12494,7 @@ $as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
 fi
 
 
-for ac_header in atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
+for ac_header in atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
index 1e76c9ee46b5ca849ffccf5671cdd192e6a4a5b8..5712419a2749a79dc1c2e9f9ce183009ef0cf5a4 100644 (file)
@@ -1260,7 +1260,7 @@ AC_SUBST(UUID_LIBS)
 
 AC_HEADER_STDBOOL
 
-AC_CHECK_HEADERS([atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h])
+AC_CHECK_HEADERS([atomic.h crypt.h dld.h fp_class.h getopt.h ieeefp.h ifaddrs.h langinfo.h mbarrier.h poll.h sys/epoll.h sys/ipc.h sys/prctl.h sys/procctl.h sys/pstat.h sys/resource.h sys/select.h sys/sem.h sys/shm.h sys/sockio.h sys/tas.h sys/un.h termios.h ucred.h utime.h wchar.h wctype.h])
 
 # On BSD, test for net/if.h will fail unless sys/socket.h
 # is included first.
index ebf027306f7754b55320938d667d2bd943e388b5..f658588c272f8e810fcb0472feebc66a5721d856 100644 (file)
@@ -379,6 +379,9 @@ PostmasterDeathSignalInit(void)
 #if defined(PR_SET_PDEATHSIG)
    if (prctl(PR_SET_PDEATHSIG, signum) < 0)
        elog(ERROR, "could not request parent death signal: %m");
+#elif defined(PROC_PDEATHSIG_CTL)
+   if (procctl(P_PID, 0, PROC_PDEATHSIG_CTL, &signum) < 0)
+       elog(ERROR, "could not request parent death signal: %m");
 #else
 #error "USE_POSTMASTER_DEATH_SIGNAL set, but there is no mechanism to request the signal"
 #endif
index 4ef53416785062119f007b11d352478934fb8497..f9fb92f31c125aeeaf3ff1c7d8d313d11f8327e7 100644 (file)
 /* Define to 1 if you have the <sys/prctl.h> header file. */
 #undef HAVE_SYS_PRCTL_H
 
+/* Define to 1 if you have the <sys/procctl.h> header file. */
+#undef HAVE_SYS_PROCCTL_H
+
 /* Define to 1 if you have the <sys/pstat.h> header file. */
 #undef HAVE_SYS_PSTAT_H
 
index 54e7108ac0b316176cdaf2631f7e276092ad9195..5ecc1b757c8b72a95d4e1873925b98a9f5b810d3 100644 (file)
 #include "sys/prctl.h"
 #endif
 
+#ifdef HAVE_SYS_PROCCTL_H
+#include "sys/procctl.h"
+#endif
+
 /*
  * Reasons for signaling the postmaster.  We can cope with simultaneous
  * signals for different reasons.  If the same reason is signaled multiple
@@ -66,7 +70,8 @@ extern void PostmasterDeathSignalInit(void);
  * the parent dies.  Checking the flag first makes PostmasterIsAlive() a lot
  * cheaper in usual case that the postmaster is alive.
  */
-#if defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_PDEATHSIG)
+#if (defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_PDEATHSIG)) || \
+   (defined(HAVE_SYS_PROCCTL_H) && defined(PROC_PDEATHSIG_CTL))
 #define USE_POSTMASTER_DEATH_SIGNAL
 #endif