From 1cef87d79009782e786b85ce6b0adf3bb39b9833 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 5 Sep 2020 12:38:21 -0700 Subject: [PATCH] Use anon semaphores only on Linux On BSDs, anonymous semaphores are implemented using a file descriptor which is not marked CLOEXEC, so it gets leaked into child processes. Use ordinary pipes instead of semaphores everywhere except Linux. Fixes #7304 --- src/topic_monitor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/topic_monitor.cpp b/src/topic_monitor.cpp index 5bc8dacb3..1384fafed 100644 --- a/src/topic_monitor.cpp +++ b/src/topic_monitor.cpp @@ -39,7 +39,9 @@ wcstring generation_list_t::describe() const { binary_semaphore_t::binary_semaphore_t() : sem_ok_(false) { // sem_init always fails with ENOSYS on Mac and has an annoying deprecation warning. -#ifndef __APPLE__ + // On BSD sem_init uses a file descriptor under the hood which doesn't get CLOEXEC (see #7304). + // So use fast semaphores on Linux only. +#ifdef __linux__ sem_ok_ = (0 == sem_init(&sem_, 0, 0)); #endif if (!sem_ok_) {