diff options
Diffstat (limited to 'src/backend/storage/ipc/pmsignal.c')
-rw-r--r-- | src/backend/storage/ipc/pmsignal.c | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c index 306e3f9a216..eea95b7d060 100644 --- a/src/backend/storage/ipc/pmsignal.c +++ b/src/backend/storage/ipc/pmsignal.c @@ -267,42 +267,27 @@ MarkPostmasterChildInactive(void) /* * PostmasterIsAlive - check whether postmaster process is still alive - * - * amDirectChild should be passed as "true" by code that knows it is - * executing in a direct child process of the postmaster; pass "false" - * if an indirect child or not sure. The "true" case uses a faster and - * more reliable test, so use it when possible. */ bool -PostmasterIsAlive(bool amDirectChild) +PostmasterIsAlive(void) { #ifndef WIN32 - if (amDirectChild) - { - pid_t ppid = getppid(); + char c; + ssize_t rc; - /* If the postmaster is still our parent, it must be alive. */ - if (ppid == PostmasterPid) + rc = read(postmaster_alive_fds[POSTMASTER_FD_WATCH], &c, 1); + if (rc < 0) + { + if (errno == EAGAIN || errno == EWOULDBLOCK) return true; - - /* If the init process is our parent, postmaster must be dead. */ - if (ppid == 1) - return false; - - /* - * If we get here, our parent process is neither the postmaster nor - * init. This can occur on BSD and MacOS systems if a debugger has - * been attached. We fall through to the less-reliable kill() method. - */ + else + elog(FATAL, "read on postmaster death monitoring pipe failed: %m"); } + else if (rc > 0) + elog(FATAL, "unexpected data in postmaster death monitoring pipe"); + + return false; - /* - * Use kill() to see if the postmaster is still alive. This can sometimes - * give a false positive result, since the postmaster's PID may get - * recycled, but it is good enough for existing uses by indirect children - * and in debugging environments. - */ - return (kill(PostmasterPid, 0) == 0); #else /* WIN32 */ return (WaitForSingleObject(PostmasterHandle, 0) == WAIT_TIMEOUT); #endif /* WIN32 */ |