From 311d20495f2ddb6b6e3f4e75bd6efc9a13d88e27 Mon Sep 17 00:00:00 2001 From: psychon Date: Sun, 4 May 2008 14:08:10 +0000 Subject: [PATCH] Call setsid() after forking This way we get rid of our controlling terminal. Now ZNC won't stay in the session of the shell anymore... git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1036 726aef4b-f618-498e-8847-2d620e286838 --- main.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.cpp b/main.cpp index 6431b780..172f845f 100644 --- a/main.cpp +++ b/main.cpp @@ -216,6 +216,7 @@ int main(int argc, char** argv) { } if (iPid > 0) { + // We are the parent. We are done and will go to bed. CUtils::PrintStatus(true, "[pid: " + CString(iPid) + "]"); pZNC->WritePidFile(iPid); @@ -229,6 +230,12 @@ int main(int argc, char** argv) { close(2); open("/dev/null", O_WRONLY); CUtils::SetStdoutIsTTY(false); + + // We are the child. There is no way we can be a process group + // leader, thus setsid() must succeed. + setsid(); + // Now we are in our own process group and session (no controlling + // terminal). We are independent! #endif struct sigaction sa;