From d990f65805dca69bdfd725457569209c7c64fb07 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Wed, 14 Oct 2026 16:26:54 +0800 Subject: [PATCH] Reinitialize the event loop after daemonize() The loop is created before the programs fork into the background, and kqueue/epoll descriptors do not survive fork(), so ss-server -f (which ss-manager always uses) died as soon as it ran. Call uv_loop_fork() in the child. --- src/event/program.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/event/program.hpp b/src/event/program.hpp index 1701b2e2..c253ef3c 100644 --- a/src/event/program.hpp +++ b/src/event/program.hpp @@ -29,6 +29,18 @@ public: Status init() noexcept { return loop_.init(); } Loop &loop() noexcept { return loop_; } + // In the child after daemonize(): kqueue and epoll descriptors do not + // survive fork(). + Status after_fork() noexcept + { +#ifndef _WIN32 + if (uv_loop_fork(loop_.native()) != 0) { + return fail(Errc::io); + } +#endif + return {}; + } + // SIGINT and SIGTERM end the run (and SIGUSR1 with `usr1`). With // `plugin_alive`, SIGCHLD ends it with exit code -1 once that reports // the plugin gone. Signals libuv cannot watch on this platform are