Handle EACCES errors from kevent() better.
authorThomas Munro <[email protected]>
Thu, 15 Oct 2020 05:23:30 +0000 (18:23 +1300)
committerThomas Munro <[email protected]>
Thu, 15 Oct 2020 05:34:21 +0000 (18:34 +1300)
While registering for postmaster exit events, we have to handle a couple
of edge cases where the postmaster is already gone.  Commit 815c2f09
missed one: EACCES must surely imply that PostmasterPid no longer
belongs to our postmaster process (or alternatively an unexpected
permissions model has been imposed on us).  Like ESRCH, this should be
treated as a WL_POSTMASTER_DEATH event, rather than being raised with
ereport().

No known problems reported in the wild.  Per code review from Tom Lane.
Back-patch to 13.

Reported-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/3624029.1602701929%40sss.pgh.pa.us

src/backend/storage/ipc/latch.c

index eacb8c3c9ee9bb41b73d2ee68d3122fb91a0be3b..24d44c982dabc01e85fa8cbe8a305727b9099851 100644 (file)
@@ -1148,7 +1148,8 @@ WaitEventAdjustKqueue(WaitEventSet *set, WaitEvent *event, int old_events)
 
    if (rc < 0)
    {
-       if (event->events == WL_POSTMASTER_DEATH && errno == ESRCH)
+       if (event->events == WL_POSTMASTER_DEATH &&
+           (errno == ESRCH || errno == EACCES))
            set->report_postmaster_not_running = true;
        else
            ereport(ERROR,