version 1.1, 2003/09/30 10:06:48
|
version 1.7, 2011/05/14 16:12:53
|
Line 3
|
Line 3
|
# |
# |
# apachereload - setuid script that reloads the apache daemon. |
# apachereload - setuid script that reloads the apache daemon. |
# |
# |
|
# $Id$ |
# |
# |
# $Id |
# Copyright Michigan State University Board of Trustees |
# |
# |
# Change log: |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
# $Log$ |
|
# Revision 1.1 2003/09/30 10:06:48 foxr |
|
# This is a setuid script that allows the www user to issue |
|
# /etc/init.d/httpd reload |
|
# |
# |
# This functionality is required by lond and lonc when they have been asked to |
# LON-CAPA is free software; you can redistribute it and/or modify |
# reinitialize themselves. |
# it under the terms of the GNU General Public License as published by |
|
# the Free Software Foundation; either version 2 of the License, or |
|
# (at your option) any later version. |
# |
# |
# Initial undebugged version. |
# LON-CAPA is distributed in the hope that it will be useful, |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
# GNU General Public License for more details. |
|
# |
|
# You should have received a copy of the GNU General Public License |
|
# along with LON-CAPA; if not, write to the Free Software |
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
# |
|
# /home/httpd/html/adm/gpl.txt |
|
# |
|
# http://www.lon-capa.org/ |
# |
# |
### |
|
|
|
|
|
use strict; |
use strict; |
Line 33 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}
|
Line 42 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}
|
|
|
my $command = "/etc/init.d/httpd reload"; |
my $command = "/etc/init.d/httpd reload"; |
|
|
|
use lib '/home/httpd/lib/perl/'; |
|
use LONCAPA::Configuration; |
|
my %perlvar= %{&LONCAPA::Configuration::read_conf('loncapa.conf')}; |
|
|
|
my ($execdir) = ($perlvar{'lonDaemons'} =~/(.*)/); |
|
my $dist=`$execdir/distprobe`; |
|
if ($dist =~ /^(suse|sles)/) { |
|
$command = "/etc/init.d/apache reload"; |
|
} |
# Do not print error messages |
# Do not print error messages |
my $noprint=1; |
my $noprint=1; |
|
|
Line 50 if ($wwwid!=$>) {
|
Line 68 if ($wwwid!=$>) {
|
# ----------------------------------- Start running script with www permissions |
# ----------------------------------- Start running script with www permissions |
&disable_root_capability; |
&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; |
&enable_root_capability; |
($>,$<)=(0,0); |
($>,$<)=(0,0); |
|
|
Line 67 unless (&try_to_lock('/tmp/lock_apachere
|
Line 77 unless (&try_to_lock('/tmp/lock_apachere
|
|
|
system($command); |
system($command); |
|
|
# Remove the lock file. |
|
|
|
|
|
|
|
&disable_root_capability; |
&disable_root_capability; |
unlink('/tmp/lock_apachereload'); |
|
exit 0; |
exit 0; |
|
|
# ---------------------------------------------- have setuid script run as root |
# ---------------------------------------------- have setuid script run as root |
Line 98 sub disable_root_capability {
|
Line 103 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=<LOCK>; |
|
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 |
=head1 NAME |
|
|
apachereload -setuid script to reload the apache web server. |
apachereload -setuid script to reload the apache web server. |