From f364f773a0381a75b5992c8c8a1d63a81dbd4422 Mon Sep 17 00:00:00 2001 From: Robert Yang Date: Mon, 19 Sep 2016 00:20:08 -0700 Subject: runqemu: acquire_lock() should fail when failed to open the file The open(self.lock, 'w') may fail when the lock is created by other users, return false for this case to let it try other devices. Fixed: runqemu - INFO - Running /sbin/ip link... runqemu - INFO - Acquiring lockfile /tmp/qemu-tap-locks/tap0.lock... Traceback (most recent call last): File "/buildarea/lyang1/poky/scripts/runqemu", line 972, in ret = main() File "/buildarea/lyang1/poky/scripts/runqemu", line 963, in main config.setup_network() File "/buildarea/lyang1/poky/scripts/runqemu", line 810, in setup_network self.setup_tap() File "/buildarea/lyang1/poky/scripts/runqemu", line 761, in setup_tap if self.acquire_lock(): File "/buildarea/lyang1/poky/scripts/runqemu", line 182, in acquire_lock lock_descriptor = open(self.lock, 'w') PermissionError: [Errno 13] Permission denied: '/tmp/qemu-tap-locks/tap0.lock' Signed-off-by: Robert Yang Signed-off-by: Richard Purdie --- scripts/runqemu | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/runqemu b/scripts/runqemu index b6bc0ba734..380568560b 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -168,14 +168,14 @@ class BaseConfig(object): def acquire_lock(self): logger.info("Acquiring lockfile %s..." % self.lock) - lock_descriptor = open(self.lock, 'w') try: - fcntl.flock(lock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB) + self.lock_descriptor = open(self.lock, 'w') + fcntl.flock(self.lock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB) except Exception as e: logger.info("Acquiring lockfile %s failed: %s" % (self.lock, e)) - lock_descriptor.close() + if self.lock_descriptor: + self.lock_descriptor.close() return False - self.lock_descriptor = lock_descriptor return True def release_lock(self): -- cgit v1.2.3