summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2018-11-28 17:30:10 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2018-12-16 14:31:26 +0000
commitd99e6afb8d6a7c3cfc8cf2eeab3db24dd9702d7f (patch)
treea6d080e2f9803d13c8e6fc955b0bcbb2f252662a /scripts
parentf7b5f33ae1ef9560917c39904c0813b28ae8ee7b (diff)
downloadpoky-d99e6afb8d6a7c3cfc8cf2eeab3db24dd9702d7f.tar.gz
scripts/runqemu: Tidy up lock handling code
Various tweaks: - Balance up the aquire/release functions - Use debug messge for both acquiring and release message for consistency in logs - Use None instead of an empty string - Reset the value of the field if we don't have the lock any more (From OE-Core rev: d3c052e6ccd81d544b23a3bee80ba00cafaedbbd) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/runqemu16
1 files changed, 9 insertions, 7 deletions
diff --git a/scripts/runqemu b/scripts/runqemu
index c9a351e251..a83c8a6944 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -218,7 +218,7 @@ class BaseConfig(object):
218 self.tcpserial_portnum = '' 218 self.tcpserial_portnum = ''
219 self.custombiosdir = '' 219 self.custombiosdir = ''
220 self.lock = '' 220 self.lock = ''
221 self.lock_descriptor = '' 221 self.lock_descriptor = None
222 self.bitbake_e = '' 222 self.bitbake_e = ''
223 self.snapshot = False 223 self.snapshot = False
224 self.fstypes = ('ext2', 'ext3', 'ext4', 'jffs2', 'nfs', 'btrfs', 224 self.fstypes = ('ext2', 'ext3', 'ext4', 'jffs2', 'nfs', 'btrfs',
@@ -252,13 +252,17 @@ class BaseConfig(object):
252 logger.info(msg) 252 logger.info(msg)
253 if self.lock_descriptor: 253 if self.lock_descriptor:
254 self.lock_descriptor.close() 254 self.lock_descriptor.close()
255 self.lock_descriptor = None
255 return False 256 return False
256 return True 257 return True
257 258
258 def release_lock(self): 259 def release_lock(self):
259 fcntl.flock(self.lock_descriptor, fcntl.LOCK_UN) 260 if self.lock_descriptor:
260 self.lock_descriptor.close() 261 logger.debug("Releasing lockfile for tap device '%s'" % self.tap)
261 os.remove(self.lock) 262 fcntl.flock(self.lock_descriptor, fcntl.LOCK_UN)
263 self.lock_descriptor.close()
264 os.remove(self.lock)
265 self.lock_descriptor = None
262 266
263 def get(self, key): 267 def get(self, key):
264 if key in self.d: 268 if key in self.d:
@@ -1232,9 +1236,7 @@ class BaseConfig(object):
1232 cmd = 'sudo %s %s %s' % (self.qemuifdown, self.tap, self.bindir_native) 1236 cmd = 'sudo %s %s %s' % (self.qemuifdown, self.tap, self.bindir_native)
1233 logger.debug('Running %s' % cmd) 1237 logger.debug('Running %s' % cmd)
1234 subprocess.check_call(cmd, shell=True) 1238 subprocess.check_call(cmd, shell=True)
1235 if self.lock_descriptor: 1239 self.release_lock()
1236 logger.info("Releasing lockfile for tap device '%s'" % self.tap)
1237 self.release_lock()
1238 1240
1239 if self.nfs_running: 1241 if self.nfs_running:
1240 logger.info("Shutting down the userspace NFS server...") 1242 logger.info("Shutting down the userspace NFS server...")