From: psc Date: Fri, 11 Mar 2011 15:34:00 +0000 (+0000) Subject: Apply patch for #6281 from LHM X-Git-Url: https://git.tokkee.org/?p=gosa.git;a=commitdiff_plain;h=3bf144af17c4442c0de04b9e8a73aa2f3f28d69f Apply patch for #6281 from LHM Cleanup gosa-si-client forking behaviour git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@20615 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/trunk/gosa-si/gosa-si-client b/trunk/gosa-si/gosa-si-client index 57f261671..403261ac6 100755 --- a/trunk/gosa-si/gosa-si-client +++ b/trunk/gosa-si/gosa-si-client @@ -1235,33 +1235,6 @@ GetOptions("h|help" => \&usage, &read_configfile($cfg_file, %cfg_defaults); &check_pid; -# 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 /: $!"; - $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 ) { - open( LOCK_FILE, ">$pid_file" ); - print LOCK_FILE "$pid\n"; - close( LOCK_FILE ); - if( !$foreground ) { - exit( 0 ) - }; -} - # parse head url and revision from svn my $client_status_hash = { 'developmental'=>'revision', 'stable'=>'release'}; $client_version =~ /^\$HeadURL: (\S+) \$:\$Rev: (\d+) \$$/; @@ -1290,6 +1263,39 @@ daemon_log("INFO: ".$client_status_hash->{$client_status}.": $client_revision", # delete old DBsqlite lock files system('rm -f /tmp/gosa_si_lock*gosa-si-client*'); +# Just fork, if we are not in foreground mode +if( ! $foreground ) { + if (! chdir('/')) { + daemon_log("ERROR: Can't chdir to /: $!"); + exit( 1 ); + } + umask( 0 ); + $pid = fork; +} else { + $pid = $$; +} + +if( 0 != $pid ) { + # Parent: put our PID into the $pid_file + open( LOCK_FILE, ">$pid_file" ); + print LOCK_FILE "$pid\n"; + close( LOCK_FILE ); + if( !$foreground ) { + exit( 0 ); + } +} +else { + # Child + open( STDIN, '+>/dev/null' ); + open( STDOUT, '+>&STDIN' ); + open( STDERR, '+>&STDIN' ); + if (! POSIX::setsid()) { + deamon_log("ERROR: Can't start a new session: $!", 1); + exit( 1 ); + } + $poe_kernel->has_forked() if ($poe_kernel->can('has_forked')); +} + # detect ip and mac address and complete host address $client_address = $client_ip.":".$client_port; my $network_interface= &get_interface_for_ip($client_ip);