From 2b53c6eac6ef1e4c7ee034d39d492180a34f7da0 Mon Sep 17 00:00:00 2001 From: josh Date: Mon, 13 Aug 2007 21:38:31 +0000 Subject: [PATCH] FEATURE: Maui now detaches from the terminal when it is in a daemonizing mode Organization: Mauiusers List Contact: Stanislav Ievlev git-svn-id: svn://opensvn.adaptivecomputing.com/maui/trunk@92 3f5042e3-fb1d-0410-be18-d6ca2573e517 --- src/server/OServer.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/server/OServer.c b/src/server/OServer.c index 04cb004..d952fe8 100644 --- a/src/server/OServer.c +++ b/src/server/OServer.c @@ -149,6 +149,8 @@ int ServerDemonize() int pid; #endif /* __NT */ + FILE *fp; + const char *FName = "ServerDemonize"; DBG(2,fALL) DPrint("%s()\n", @@ -179,6 +181,8 @@ int ServerDemonize() { /* only background if not in debug mode */ + /* NOTE: setsid() disconnects from controlling-terminal */ + #ifndef __NT if ((pid = fork()) == -1) @@ -205,6 +209,28 @@ int ServerDemonize() DBG(3,fALL) DPrint("INFO: child process in background\n"); } + if (setsid() == -1) + { + MDB(3,fALL) MLog("INFO: could not disconnect from controlling-terminal, errno=%d - %s\n", + errno, + strerror(errno)); + } + + /* disconnect stdin */ + + fclose(stdin); + fp = fopen("/dev/null","r"); + + /* disconnect stdout */ + + fclose(stdout); + fp = fopen("/dev/null","w"); + + /* disconnect stderr */ + + fclose(stderr); + fp = fopen("/dev/null","w"); + #endif /* __NT */ } } /* END if (MSched.Mode != msmSim) */