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
This commit is contained in:
josh 2007-08-13 21:38:31 +00:00
parent 869ce69e6b
commit 2b53c6eac6

View File

@ -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) */