From 2176c59f58cb7a56d51fa4a78fd0924a6a27743d Mon Sep 17 00:00:00 2001 From: psc Date: Fri, 11 Mar 2011 15:34:15 +0000 Subject: [PATCH] Apply patch for #6281 from LHM Cleanup gosa-si-server forking behaviour git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@20618 594d385d-05f5-0310-b6e9-bd551577e9d8 --- trunk/gosa-si/gosa-si-server | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/trunk/gosa-si/gosa-si-server b/trunk/gosa-si/gosa-si-server index c79bfdd1c..18723f8b2 100755 --- a/trunk/gosa-si/gosa-si-server +++ b/trunk/gosa-si/gosa-si-server @@ -3231,32 +3231,39 @@ $adm_gid = getgrnam('adm'); $SIG{CHLD} = 'IGNORE'; -# forward error messages to logfile -if( ! $foreground ) { - open( STDIN, '+>/dev/null' ); - open( STDOUT, '+>&STDIN' ); - open( STDERR, '+>&STDIN' ); -} - # Just fork, if we are not in foreground mode if( ! $foreground ) { - chdir '/' or die "Can't chdir to /: $!"; + if (! chdir('/')) { + daemon_log("Can't chdir to /: $!", 1); + exit( 1 ); + } + umask( 0 ); $pid = fork; - setsid or die "Can't start a new session: $!"; - umask 0; } else { $pid = $$; } -# Do something useful - put our PID into the pid_file if( 0 != $pid ) { + # Parent: put PID into the $pid_file open( LOCK_FILE, ">$pid_file" ); print LOCK_FILE "$pid\n"; close( LOCK_FILE ); if( !$foreground ) { - exit( 0 ) - }; + exit( 0 ); } +} +else { + # Child + open( STDIN, '+>/dev/null' ); + open( STDOUT, '+>&STDIN' ); + open( STDERR, '+>&STDIN' ); + if (! POSIX::setsid()) { + daemon_log("Can't start a new session: $!"); + exit( 1 ); + } + $poe_kernel->has_forked() if ($poe_kernel->can('has_forked')); +} + # parse head url and revision from svn my $server_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; -- 2.30.2