summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e512539)
raw | patch | inline | side by side (parent: e512539)
author | opensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 18 May 2010 17:41:16 +0000 (17:41 +0000) | ||
committer | opensides <opensides@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 18 May 2010 17:41:16 +0000 (17:41 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@18539 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-server | patch | blob | history |
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 88e13681e45cdca30dd594b9091c1d8596065036..895ca1edcd87d7a7edfe36d9ce6821629777109a 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
}
}
-
-#=== FUNCTION ================================================================
-# NAME: check_cmdline_param
-# PARAMETERS: nothing
-# RETURNS: nothing
-# DESCRIPTION: validates commandline parameter
-#===============================================================================
-sub check_cmdline_param () {
- my $err_counter = 0;
-
- # Check configuration file
- if(not defined($cfg_file)) {
- $cfg_file = "/etc/gosa-si/server.conf";
- if(! -r $cfg_file) {
- print STDERR "Please specify a config file.\n";
- $err_counter++;
- }
- }
-
- # Prepare identification which gosa-si parts should be debugged and which not
- if (defined $debug_parts)
- {
- if ($debug_parts =~ /^\d+$/)
- {
- $debug_parts_bitstring = unpack("B32", pack("N", $debug_parts));
- }
- else
- {
- print STDERR "Value '$debug_parts' invalid for option d (number expected)\n";
- $err_counter++;
- }
- }
-
- # Exit if an error occour
- if( $err_counter > 0 ) { &usage( "", 1 ); }
-}
-
-
-#=== FUNCTION ================================================================
-# NAME: check_pid
-# PARAMETERS: nothing
-# RETURNS: nothing
-# DESCRIPTION: handels pid processing
-#===============================================================================
-sub check_pid {
- $pid = -1;
- # Check, if we are already running
- if( open( my $LOCK_FILE, "<", "$pid_file" ) ) {
- $pid = <$LOCK_FILE>;
- if( defined $pid ) {
- chomp( $pid );
- if( -f "/proc/$pid/stat" ) {
- my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/;
- if( $stat ) {
- print STDERR "\nERROR: Already running!\n";
- close( $LOCK_FILE );
- exit -1;
- }
- }
- }
- close( $LOCK_FILE );
- unlink( $pid_file );
- }
-
- # create a syslog msg if it is not to possible to open PID file
- if (not sysopen(my $LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
- my($msg) = "Couldn't obtain lockfile '$pid_file' ";
- if (open(my $LOCK_FILE, '<', $pid_file)
- && ($pid = <$LOCK_FILE>))
- {
- chomp($pid);
- $msg .= "(PID $pid)\n";
- } else {
- $msg .= "(unable to read PID)\n";
- }
- if( ! ($foreground) ) {
- openlog( $0, "cons,pid", "daemon" );
- syslog( "warning", $msg );
- closelog();
- }
- else {
- print( STDERR " $msg " );
- }
- exit( -1 );
- }
-}
-
#=== FUNCTION ================================================================
# NAME: import_modules
# PARAMETERS: module_path - string - abs. path to the directory the modules
sub start_daemon {
+ #to prevent zombie child
+ $SIG{CHLD} = 'IGNORE';
+
if( ! $foreground ) {
chdir '/' or die "Can't chdir to /: $!";
umask 0;
open STDIN, '+>/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '+>&STDIN' or die "Can't write to /dev/null: $!";
open STDERR, '+>&STDIN' or die "Can't write to /dev/null: $!";
- defined(my $child_pid = fork) or die "Can't fork: $!";
- exit if $child_pid;
+ defined($pid = fork) or die "Can't fork: $!";
+ exit if $pid;
setsid or die "Can't start a new session: $!";
}
return;
# read and set config parameters
&read_configfile($config, %cfg_defaults);
+# daemonize the program
+&start_daemon($pid, $foreground);
+
# create pid file
&create_pid($pid, $pid_file);
-# daemonize the program
-&start_daemon($foreground);
-
# Determine root uid and adm gid, used for creating log files
&get_perms_admin($root_uid, $adm_gid);