diff options
Diffstat (limited to 'scripts/runqemu')
-rwxr-xr-x | scripts/runqemu | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/scripts/runqemu b/scripts/runqemu index edd17d09c4..f9a1a0da32 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -232,9 +232,12 @@ class BaseConfig(object): def release_taplock(self): if self.taplock_descriptor: logger.debug("Releasing lockfile for tap device '%s'" % self.tap) - fcntl.flock(self.taplock_descriptor, fcntl.LOCK_UN) + # We pass the fd to the qemu process and if we unlock here, it would unlock for + # that too. Therefore don't unlock, just close + # fcntl.flock(self.taplock_descriptor, fcntl.LOCK_UN) self.taplock_descriptor.close() - os.remove(self.taplock) + # Removing the file is a potential race, don't do that either + # os.remove(self.taplock) self.taplock_descriptor = None def check_free_port(self, host, port, lockdir): @@ -272,17 +275,23 @@ class BaseConfig(object): def release_portlock(self, lockfile=None): if lockfile != None: - logger.debug("Releasing lockfile '%s'" % lockfile) - fcntl.flock(self.portlocks[lockfile], fcntl.LOCK_UN) - self.portlocks[lockfile].close() - os.remove(lockfile) - del self.portlocks[lockfile] + logger.debug("Releasing lockfile '%s'" % lockfile) + # We pass the fd to the qemu process and if we unlock here, it would unlock for + # that too. Therefore don't unlock, just close + # fcntl.flock(self.portlocks[lockfile], fcntl.LOCK_UN) + self.portlocks[lockfile].close() + # Removing the file is a potential race, don't do that either + # os.remove(lockfile) + del self.portlocks[lockfile] elif len(self.portlocks): for lockfile, descriptor in self.portlocks.items(): logger.debug("Releasing lockfile '%s'" % lockfile) - fcntl.flock(descriptor, fcntl.LOCK_UN) + # We pass the fd to the qemu process and if we unlock here, it would unlock for + # that too. Therefore don't unlock, just close + # fcntl.flock(descriptor, fcntl.LOCK_UN) descriptor.close() - os.remove(lockfile) + # Removing the file is a potential race, don't do that either + # os.remove(lockfile) self.portlocks = {} def get(self, key): @@ -766,7 +775,7 @@ class BaseConfig(object): raise RunQemuError('BIOS not found: %s' % bios_match_name) if not os.path.exists(self.bios): - raise RunQemuError("KERNEL %s not found" % self.bios) + raise RunQemuError("BIOS %s not found" % self.bios) def check_mem(self): @@ -1564,7 +1573,8 @@ def main(): def sigterm_handler(signum, frame): logger.info("SIGTERM received") - os.kill(config.qemupid, signal.SIGTERM) + if config.qemupid: + os.kill(config.qemupid, signal.SIGTERM) config.cleanup() # Deliberately ignore the return code of 'tput smam'. subprocess.call(["tput", "smam"]) |