From a8c1a1a5604ace9fa7f0bd693a93e55cc28498dc Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Fri, 19 Feb 2010 15:00:51 +0000 Subject: [PATCH] -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 --- xCAT-server/lib/xcat/plugins/dhcp.pm | 2 +- xCAT-server/lib/xcat/plugins/hosts.pm | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm index f4006937e..f7281552f 100644 --- a/xCAT-server/lib/xcat/plugins/dhcp.pm +++ b/xCAT-server/lib/xcat/plugins/dhcp.pm @@ -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}}) { diff --git a/xCAT-server/lib/xcat/plugins/hosts.pm b/xCAT-server/lib/xcat/plugins/hosts.pm index cb6d2ce39..05f7f7ada 100644 --- a/xCAT-server/lib/xcat/plugins/hosts.pm +++ b/xCAT-server/lib/xcat/plugins/hosts.pm @@ -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); }