Make wineclipsrv run as a daemon (close stdout/stderr, no controlling

terminal, session group leader).
This commit is contained in:
Jason Phillips 2002-03-11 01:13:27 +00:00 committed by Alexandre Julliard
parent 46a9db644f
commit 7c18771736
1 changed files with 37 additions and 0 deletions

View File

@ -188,6 +188,7 @@ static const char * const event_names[] =
* Prototypes * Prototypes
*/ */
int RunAsDaemon( void );
BOOL Init(int argc, char **argv); BOOL Init(int argc, char **argv);
void TerminateServer( int ret ); void TerminateServer( int ret );
int AcquireSelection(); int AcquireSelection();
@ -209,6 +210,12 @@ int main(int argc, char **argv)
{ {
XEvent event; XEvent event;
if ( RunAsDaemon() == -1 )
{
ERR("could not run as daemon\n");
exit(1);
}
if ( !Init(argc, argv) ) if ( !Init(argc, argv) )
exit(0); exit(0);
@ -231,6 +238,36 @@ int main(int argc, char **argv)
} }
/**************************************************************************
* RunAsDaemon()
*/
int RunAsDaemon( void )
{
int i;
/* fork child process and let parent exit ; gets rid of original PID */
switch( fork() )
{
case -1:
ERR("fork failed\n");
return(-1);
case 0:
exit(0);
break;
}
/* below is child process w/ new PID, set as session leader */
setsid();
/* close stdin,stdout,stderr and file descriptors (overkill method) */
for ( i = 0; i < 256 ; i++ )
close(i);
TRACE("now running as daemon...\n");
return 0;
}
/************************************************************************** /**************************************************************************
* Init() * Init()
* Initialize the clipboard server * Initialize the clipboard server