Re: Latch implementation that wakes on postmaster death on both win32 and Unix - Mailing list pgsql-hackers

From Peter Geoghegan
Subject Re: Latch implementation that wakes on postmaster death on both win32 and Unix
Date
Msg-id BANLkTimi_CgmEV-XQviTAtPb=v16=XkGAQ@mail.gmail.com
Whole thread Raw
In response to Re: Latch implementation that wakes on postmaster death on both win32 and Unix  (Heikki Linnakangas <heikki.linnakangas@enterprisedb.com>)
Responses Re: Latch implementation that wakes on postmaster death on both win32 and Unix
Re: Latch implementation that wakes on postmaster death on both win32 and Unix
List pgsql-hackers
I had another quick look-over this patch, and realised that I made a
minor mistake:

+void
+ReleasePostmasterDeathWatchHandle(void)
+{
+    /* MyProcPid won't have been set yet */
+    Assert(PostmasterPid != getpid());
+    /* Please don't ask twice */
+    Assert(postmaster_alive_fds[POSTMASTER_FD_OWN] != -1);
+    /* Release parent's ownership fd - only postmaster should hold it */
+    if (close(postmaster_alive_fds[ POSTMASTER_FD_OWN]))
+    {
+        ereport(FATAL,
+            (errcode_for_socket_access(),
+             errmsg("Failed to close file descriptor associated with
Postmaster death in child process %d", MyProcPid)));
+    }
+    postmaster_alive_fds[POSTMASTER_FD_OWN] = -1;
+}
+

MyProcPid is used in this errmsg, and as noted in the first comment,
it isn't expected to be initialised when
ReleasePostmasterDeathWatchHandle() is called. Therefore, MyProcPid
should be replaced with a call to getpid(), just as it is for
Assert(PostmasterPid != getpid()).

I suppose that you could take the view that MyProcPid ought to be
initialised before the function is called, but I thought this was the
least worst way. Better to do it this way than to touch all the
different ways in which MyProcPid might be initialised, I suspect.

--
Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services


pgsql-hackers by date:

Previous
From: Florian Pflug
Date:
Subject: Re: proposal: a validator for configuration files
Next
From: Heikki Linnakangas
Date:
Subject: Re: Latch implementation that wakes on postmaster death on both win32 and Unix