X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=trunk%2Fgosa-si%2Fgosa-si-client;h=5ce0d368fc429a0d9661857f1952bbafb510f8e3;hb=9ee3014961c5f44c31802e4e6d1883023954b807;hp=57f26167185cc5de16e051bec86d3a27d3c87161;hpb=aeb526a7f52c92f0c49d3dbdd8483a759e0d162c;p=gosa.git diff --git a/trunk/gosa-si/gosa-si-client b/trunk/gosa-si/gosa-si-client index 57f261671..5ce0d368f 100755 --- a/trunk/gosa-si/gosa-si-client +++ b/trunk/gosa-si/gosa-si-client @@ -76,6 +76,8 @@ our $client_force_hostname; our $server_key; our $opts_dnslookup; +our $FIFO_FD = undef; + # default variables our $REGISTERED = 0; our $REGISTRATION_IN_PROGRESS = 0; @@ -822,8 +824,16 @@ sub trigger_logged_in_users_report { @logged_in_user_list = split(/\s/, $result); } - system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si-client.socket"); + $FIFO_FD = undef + if (! defined $FIFO_FD && ! defined open($FIFO_FD, '>', $gosa_si_client_fifo)); + if (! defined $FIFO_FD) { + daemon_log("ERROR: unable to open fifo for writing: $!", 1); + $kernel->delay_set('trigger_logged_in_users_report', 30); + } + else { + print($FIFO_FD 'CURRENTLY_LOGGED_IN ' . join(" ", @logged_in_user_list)); $kernel->delay_set('trigger_logged_in_users_report', $trigger_logged_in_users_report_delay); + } } else { # try it in 10 sec again $kernel->delay_set('trigger_logged_in_users_report', 10); @@ -881,9 +891,8 @@ sub trigger_seen_messages { my $send_error = &send_msg_to_target($confirm_msg, $server_address, $server_key); # Delete file - if (not $send_error) { - system("rm $goto_dir/$goto_file"); - } + unlink("$goto_dir/$goto_file") + if (! $send_error); } } @@ -1031,6 +1040,7 @@ sub _stop { $kernel->alias_remove($heap->{alias}); $kernel->alarm_remove_all(); $kernel->post($heap->{child_session}, '_stop'); + close( $FIFO_FD ) if( defined $FIFO_FD ); } @@ -1235,33 +1245,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 +1273,52 @@ 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*'); +# (re-)create FIFO +if (-e $gosa_si_client_fifo) { + daemon_log("INFO: $gosa_si_client_fifo exists - deleting", 5); + if (1 != unlink($gosa_si_client_fifo)) { + daemon_log("ERROR: unable to delete '$gosa_si_client_fifo': $!", 1); + exit( 1 ); + } +} +if (! defined POSIX::mkfifo($gosa_si_client_fifo, "0600")) { + daemon_log("ERROR: failed creating fifo: $!", 1); + exit( 1 ); +} + +# 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); @@ -1334,10 +1363,6 @@ $default_server_key = $server_key; # Find servers from config and DNS &find_servers; -# open fifo for non-gosa-si-client-msgs to gosa-si-server -POSIX::mkfifo("$gosa_si_client_fifo", "0600"); - - POE::Session->create( inline_states => { _start => \&_start,