]> granicus.if.org Git - postgresql/commit
Make latch.c more paranoid about child-process cases.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 27 Apr 2017 19:07:36 +0000 (15:07 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 27 Apr 2017 19:07:36 +0000 (15:07 -0400)
commit866452cd8b52b0231e159eab4201d86d9164ab69
tree79ece0314949754bc3beba585f12672b5d7e1a59
parente880df25ec35fab727678531d392403ce4226dd9
Make latch.c more paranoid about child-process cases.

Although the postmaster doesn't currently create a self-pipe or any
latches, there's discussion of it doing so in future.  It's also
conceivable that a shared_preload_libraries extension would try to
create such a thing in the postmaster process today.  In that case
the self-pipe FDs would be inherited by forked child processes.
latch.c was entirely unprepared for such a case and could suffer an
assertion failure, or worse try to use the inherited pipe if somebody
called WaitLatch without having called InitializeLatchSupport in that
process.  Make it keep track of whether InitializeLatchSupport has been
called in the *current* process, and do the right thing if state has
been inherited from a parent.

Apply FD_CLOEXEC to file descriptors created in latch.c (the self-pipe,
as well as epoll event sets).  This ensures that child processes spawned
in backends, the archiver, etc cannot accidentally or intentionally mess
with these FDs.  It also ensures that we end up with the right state
for the self-pipe in EXEC_BACKEND processes, which otherwise wouldn't
know to close the postmaster's self-pipe FDs.

Back-patch to 9.6, mainly to keep latch.c looking similar in all branches
it exists in.

Discussion: https://postgr.es/m/8322.1493240739@sss.pgh.pa.us
src/backend/storage/ipc/latch.c