From 1c09a4adb20aed76dd5f07051c605ffd56a093d6 Mon Sep 17 00:00:00 2001 From: tcatm Date: Mon, 21 Mar 2011 12:11:05 +0100 Subject: [PATCH] daemon-mode: add sleep() loop to prevent defunct child process, call setsid() in child --- init.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/init.cpp b/init.cpp index 8e581266938..c0b03c87758 100644 --- a/init.cpp +++ b/init.cpp @@ -236,6 +236,10 @@ bool AppInit2(int argc, char* argv[]) } if (pid > 0) return true; + + pid_t sid = setsid(); + if (sid < 0) + fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno); } #endif @@ -466,6 +470,10 @@ bool AppInit2(int argc, char* argv[]) if (fFirstRun) SetStartOnSystemStartup(true); #endif + + if (fDaemon) + while (!fShutdown) + Sleep(5000); return true; }