-Implement/fix locking for dhcp/hosts management plugins

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@5234 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2010-02-19 15:00:51 +00:00
parent 4e76bb177c
commit a8c1a1a560
2 changed files with 6 additions and 1 deletions

View File

@ -540,7 +540,7 @@ sub process_request
}
my $dhcplockfd;
open($dhcplockfd,"/tmp/xcat/dhcplock");
open($dhcplockfd,">","/tmp/xcat/dhcplock");
flock($dhcplockfd,LOCK_EX);
if (grep /^-n$/, @{$req->{arg}})
{

View File

@ -6,6 +6,7 @@ use xCAT::Table;
use Data::Dumper;
use File::Copy;
use Getopt::Long;
use Fcntl ':flock';
my @hosts; #Hold /etc/hosts data to be written back
@ -159,6 +160,7 @@ sub process_request {
my $hoststab = xCAT::Table->new('hosts');
my $sitetab = xCAT::Table->new('site');
my $domain;
my $lockh;
if ($sitetab) {
my $dent = $sitetab->getAttribs({key=>'domain'},'value');
if ($dent and $dent->{value}) {
@ -177,6 +179,8 @@ sub process_request {
my $bakname = "/etc/hosts.xcatbak";
copy("/etc/hosts",$bakname);
}
open($lockh,">","/tmp/xcat/hostsfile.lock");
flock($lockh,LOCK_EX);
my $rconf;
open($rconf,"/etc/hosts"); # Read file into memory
if ($rconf) {
@ -213,6 +217,7 @@ sub process_request {
}
}
writeout();
flock($lockh,LOCK_UN);
}