From 4d80668f1fbc4027ca3bc81b171e233071e91b2f Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 24 Oct 2023 19:35:20 +0200 Subject: [PATCH] Merge remote-tracking branch 'origin/topic/awelzel/3190-supervisor-eventmgr-shared-pipe-fix' * origin/topic/awelzel/3190-supervisor-eventmgr-shared-pipe-fix: event: Reinitialize EventMgr's flare after fork() from stem (cherry picked from commit 22fb445a7f087278109f16c35b824daa110ab32c) --- src/Event.cc | 8 ++++++++ src/Event.h | 3 +++ src/zeek-setup.cc | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/Event.cc b/src/Event.cc index de26955d56..f382163108 100644 --- a/src/Event.cc +++ b/src/Event.cc @@ -207,4 +207,12 @@ void EventMgr::InitPostScript() reporter->FatalError("Failed to register event manager FD with iosource_mgr"); } +void EventMgr::InitPostFork() + { + // Re-initialize the flare, closing and re-opening the underlying + // pipe FDs. This is needed so that each Zeek process in a supervisor + // setup has its own pipe instead of them all sharing a single pipe. + queue_flare = zeek::detail::Flare{}; + } + } // namespace zeek diff --git a/src/Event.h b/src/Event.h index b746635007..75929817c1 100644 --- a/src/Event.h +++ b/src/Event.h @@ -118,6 +118,9 @@ public: const char* Tag() override { return "EventManager"; } void InitPostScript(); + // Initialization to be done after a fork() happened. + void InitPostFork(); + uint64_t num_events_queued = 0; uint64_t num_events_dispatched = 0; diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 41c8479f2a..23bc8033af 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -554,8 +554,14 @@ SetupResult setup(int argc, char** argv, Options* zopts) auto stem = Supervisor::CreateStem(options.supervisor_mode); if ( Supervisor::ThisNode() ) + { + // If we get here, we're a supervised node that just returned + // from CreateStem() after being forked from the stem. Supervisor::ThisNode()->Init(&options); + event_mgr.InitPostFork(); + } + script_coverage_mgr.ReadStats(); auto dns_type = options.dns_mode;