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:
parent
869ce69e6b
commit
2b53c6eac6
@ -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) */
|
||||
|
Loading…
Reference in New Issue
Block a user