Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1f0019d

Browse files
committed
Don't leak a signalfd when using latches in the postmaster.
At the time of commit 6a2a70a we didn't use latch infrastructure in the postmaster. We're planning to start doing that, so we'd better make sure that the signalfd inherited from a postmaster is not duplicated and then leaked in the child. Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Justin Pryzby <pryzby@telsasoft.com> Discussion: https://postgr.es/m/CA%2BhUKG%2BZ-HpOj1JsO9eWUP%2Bar7npSVinsC_npxSy%2BjdOMsx%3DGg%40mail.gmail.com
1 parent 30829e5 commit 1f0019d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/backend/storage/ipc/latch.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,22 @@ InitializeLatchSupport(void)
283283
#ifdef WAIT_USE_SIGNALFD
284284
sigset_t signalfd_mask;
285285

286+
if (IsUnderPostmaster)
287+
{
288+
/*
289+
* It would probably be safe to re-use the inherited signalfd since
290+
* signalfds only see the current process's pending signals, but it
291+
* seems less surprising to close it and create our own.
292+
*/
293+
if (signal_fd != -1)
294+
{
295+
/* Release postmaster's signal FD; ignore any error */
296+
(void) close(signal_fd);
297+
signal_fd = -1;
298+
ReleaseExternalFD();
299+
}
300+
}
301+
286302
/* Block SIGURG, because we'll receive it through a signalfd. */
287303
sigaddset(&UnBlockSig, SIGURG);
288304

0 commit comments

Comments
 (0)