--- loncom/apachereload 2005/10/31 16:13:45 1.4 +++ loncom/apachereload 2011/05/14 16:12:53 1.7 @@ -3,7 +3,7 @@ # # apachereload - setuid script that reloads the apache daemon. # -# $Id: apachereload,v 1.4 2005/10/31 16:13:45 albertel Exp $ +# $Id: apachereload,v 1.7 2011/05/14 16:12:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -46,7 +46,8 @@ use lib '/home/httpd/lib/perl/'; use LONCAPA::Configuration; my %perlvar= %{&LONCAPA::Configuration::read_conf('loncapa.conf')}; -my $dist=`$perlvar{'lonDaemons'}/distprobe`; +my ($execdir) = ($perlvar{'lonDaemons'} =~/(.*)/); +my $dist=`$execdir/distprobe`; if ($dist =~ /^(suse|sles)/) { $command = "/etc/init.d/apache reload"; } @@ -67,14 +68,6 @@ if ($wwwid!=$>) { # ----------------------------------- Start running script with www permissions &disable_root_capability; -# --------------------------- Handle case of another apachereload process (locking) -unless (&try_to_lock('/tmp/lock_apachereload')) { - print "Error. Too many other simultaneous password change requests being ". - "made.\n" unless $noprint; - exit 4; -} - - &enable_root_capability; ($>,$<)=(0,0); @@ -84,12 +77,7 @@ unless (&try_to_lock('/tmp/lock_apachere system($command); -# Remove the lock file. - - - &disable_root_capability; -unlink('/tmp/lock_apachereload'); exit 0; # ---------------------------------------------- have setuid script run as root @@ -115,44 +103,6 @@ sub disable_root_capability { } } -# ----------------------- make sure that another apachereload process isn't running -sub try_to_lock { - my ($lockfile)=@_; - my $currentpid; - my $lastpid; - # Do not manipulate lock file as root - if ($>==0) { - return 0; - } - # Try to generate lock file. - # Wait 3 seconds. If same process id is in - # lock file, then assume lock file is stale, and - # go ahead. If process id's fluctuate, try - # for a maximum of 10 times. - for (0..10) { - if (-e $lockfile) { - open(LOCK,"<$lockfile"); - $currentpid=; - close LOCK; - if ($currentpid==$lastpid) { - last; - } - sleep 3; - $lastpid=$currentpid; - } - else { - last; - } - if ($_==10) { - return 0; - } - } - open(LOCK,">$lockfile"); - print LOCK $$; - close LOCK; - return 1; -} - =head1 NAME apachereload -setuid script to reload the apache web server.