#!/usr/bin/perl # # File: hupsyslog # # Copyright 1995 University Corporation for Atmospheric Research # See ../COPYRIGHT file for copying and redistribution conditions. # # Description: This perl script provides an alternative to the c code hupsyslog # and platforms without the /etc/syslog.pid file. # # Modifications: # Marcus Vinicius S. Mendes - CPTEC/INPE - BRAZIL # - Modifications done to run under syslog-ng on Open Suse 10.2 # # Files: # # Environment Variables: # # Usage: # # hupsyslog.pl # ############################################################################### # Reseting the PATH making it secure # This is necessary to pass through the suidperl security directives $path = $ENV{'PATH'}; $ENV{'PATH'} = '/bin:/usr/bin'; delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; # # get the existing runtime environment # ($os,$hostname,$version) = split(/ /,`/bin/uname -a`); $syslogpid = getPid() ; $syslogpid =~ /(.*)/; $syslogpid_to_kill = $1; #print "SYSLOGPID=$syslogpid\nSYSLOGPID_TO_KILL=$syslogpid_to_kill\n" ; system( "kill -HUP $syslogpid_to_kill" ) ; ############################################################################### sub getPid { my( $i, @F, $pid_num ) ; # looking for the syslog-ng pid if ($os eq "SunOS" && $version =~ /^4/) { open( IN, "ps -gawxl |" ) || die "ps: Cannot open ps" ; $default = 2 ; } elsif ($os eq "Linux") { open( IN, "/bin/ps ajx |" ) || die "ps: Cannot open ps" ; $default = 1 ; } else { open( IN, "/bin/ps -eaf |" ) || die "ps: Cannot open ps" ; $default = 1 ; } # each platform has fields in different order, looking for PID $_ = ; s/^\s*([A-Z].*)/\1/ ; $index = -1 ; ( @F ) = split( /[ \t]+/, $_ ) ; for( $i = 0; $i <= $#F; $i++ ) { next if( $F[ $i ] =~ /PPID/i ) ; if( $F[ $i ] =~ /PID/i ) { $index = $i ; last ; } } $index = $default if( $index == -1 ) ; @F = ( ) ; # search through all processes, looking for syslog-ng while( ) { next unless( /syslog-ng/ ) ; s/^\s*([a-z0-9].*)/\1/ ; ( @F ) = split( /[ \t]+/, $_ ) ; last ; } close( IN ) ; # no pid, no syslog-ng running return -1 if( $#F == -1 ) ; return $F[ $index ] ; } ###############################################################################