-->
sub update_httpd_config
{
my $file=shift;
if (! $file) { error("Call to update_httpd_config with wrong parameter"); }
open(FILE, $file) || error("Failed to open $file for update");
open(FILETMP, ">$file.tmp") || error("Failed to open $file.tmp for writing");
# $%conf contains param and values
my %confchanged=();
my $conflinenb = 0;
# First, change values that are already present in old config file
while(<FILE>) {
my $savline=$_;
chomp $_; s/\r//;
$conflinenb++;
# Remove comments not at beginning of line
$_ =~ s/\s#.*$//;
# Change line
if ($_ =~ /^CustomLog\s(.*)\scommon$/i) { $savline="CustomLog $1 combined"; }
# Write line
print FILETMP "$savline";
}
close(FILE);
close(FILETMP);
# Move file to file.sav
if (rename("$file","$file.old")==0) {
error("Failed to make backup of current config file to $file.old");
}
# Move tmp file into config file
if (rename("$file.tmp","$file")==0) {
error("Failed to move tmp config file $file.tmp to $file");
}
return 0;
}
其中error子例程是打印退出!

发表评论