-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:
parent
4e76bb177c
commit
a8c1a1a560
@ -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}})
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user