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.
This commit is contained in:
Max Lv
2026-10-15 00:34:31 +08:00
parent 3efcb79010
commit d990f65805
+12
View File
@@ -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