|
|
|
@ -413,38 +413,42 @@ class YumModule(YumDnf):
|
|
|
|
|
|
|
|
|
|
def is_lockfile_pid_valid(self):
|
|
|
|
|
try:
|
|
|
|
|
with open(self.lockfile, 'r') as f:
|
|
|
|
|
oldpid = int(f.readline())
|
|
|
|
|
except ValueError:
|
|
|
|
|
# invalid data
|
|
|
|
|
os.unlink(self.lockfile)
|
|
|
|
|
return False
|
|
|
|
|
except (IOError, OSError) as e:
|
|
|
|
|
self.module.fail_json(msg="Failure opening %s: %s" % (self.lockfile, to_native(e)))
|
|
|
|
|
|
|
|
|
|
if oldpid == os.getpid():
|
|
|
|
|
# that's us?
|
|
|
|
|
os.unlink(self.lockfile)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
with open("/proc/%d/stat" % oldpid, 'r') as f:
|
|
|
|
|
stat = f.readline()
|
|
|
|
|
try:
|
|
|
|
|
with open(self.lockfile, 'r') as f:
|
|
|
|
|
oldpid = int(f.readline())
|
|
|
|
|
except ValueError:
|
|
|
|
|
# invalid data
|
|
|
|
|
os.unlink(self.lockfile)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
if stat.split()[2] == 'Z':
|
|
|
|
|
# Zombie
|
|
|
|
|
if oldpid == os.getpid():
|
|
|
|
|
# that's us?
|
|
|
|
|
os.unlink(self.lockfile)
|
|
|
|
|
return False
|
|
|
|
|
except IOError:
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
os.kill(oldpid, 0)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
if e.errno == errno.ESRCH:
|
|
|
|
|
# No such process
|
|
|
|
|
with open("/proc/%d/stat" % oldpid, 'r') as f:
|
|
|
|
|
stat = f.readline()
|
|
|
|
|
|
|
|
|
|
if stat.split()[2] == 'Z':
|
|
|
|
|
# Zombie
|
|
|
|
|
os.unlink(self.lockfile)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
self.module.fail_json(msg="Unable to check PID %s in %s: %s" % (oldpid, self.lockfile, to_native(e)))
|
|
|
|
|
except IOError:
|
|
|
|
|
# either /proc is not mounted or the process is already dead
|
|
|
|
|
try:
|
|
|
|
|
# check the state of the process
|
|
|
|
|
os.kill(oldpid, 0)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
if e.errno == errno.ESRCH:
|
|
|
|
|
# No such process
|
|
|
|
|
os.unlink(self.lockfile)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
self.module.fail_json(msg="Unable to check PID %s in %s: %s" % (oldpid, self.lockfile, to_native(e)))
|
|
|
|
|
except (IOError, OSError) as e:
|
|
|
|
|
# lockfile disappeared?
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# another copy seems to be running
|
|
|
|
|
return True
|
|
|
|
|