Fix poll() implementation of WaitLatchOrSocket to notice postmaster death.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sun, 15 Jan 2012 20:03:09 +0000 (22:03 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Sun, 15 Jan 2012 20:08:03 +0000 (22:08 +0200)
When the remote end of the pipe is closed, select() reports the fd as
readable, but poll() has a separate POLLHUP return code for that.

Spotted by Peter Geoghegan.

src/backend/port/unix_latch.c

index fc1a579ad2a94e4768cad38f88f4d41127ba5647..10bf2dbec7ec052cb52d2ff286e46bd5039431d9 100644 (file)
@@ -310,8 +310,13 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
        {
            result |= WL_SOCKET_WRITEABLE;
        }
+       /*
+        * We expect a POLLHUP when the remote end is closed, but because we
+        * don't expect the pipe to become readable or to have any errors
+        * either, treat those as postmaster death, too.
+        */
        if ((wakeEvents & WL_POSTMASTER_DEATH) &&
-           (pfds[nfds - 1].revents & POLLIN))
+           (pfds[nfds - 1].revents & (POLLHUP | POLLIN | POLLERR | POLLNVAL)))
        {
            result |= WL_POSTMASTER_DEATH;
        }