yum: check whether the lock file disappeared (#58581)

pull/58987/head
Martin Krizek 5 years ago committed by GitHub
parent 4ab364eaaf
commit b0f38931b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -126,8 +126,9 @@ class YumDnf(with_metaclass(ABCMeta, object)):
# default isn't a bad idea # default isn't a bad idea
self.lockfile = '/var/run/yum.pid' self.lockfile = '/var/run/yum.pid'
@abstractmethod
def is_lockfile_pid_valid(self): def is_lockfile_pid_valid(self):
raise NotImplementedError return
def _is_lockfile_present(self): def _is_lockfile_present(self):
return (os.path.isfile(self.lockfile) or glob.glob(self.lockfile)) and self.is_lockfile_pid_valid() return (os.path.isfile(self.lockfile) or glob.glob(self.lockfile)) and self.is_lockfile_pid_valid()

@ -412,6 +412,7 @@ class YumModule(YumDnf):
raise e raise e
def is_lockfile_pid_valid(self): def is_lockfile_pid_valid(self):
try:
try: try:
with open(self.lockfile, 'r') as f: with open(self.lockfile, 'r') as f:
oldpid = int(f.readline()) oldpid = int(f.readline())
@ -419,8 +420,6 @@ class YumModule(YumDnf):
# invalid data # invalid data
os.unlink(self.lockfile) os.unlink(self.lockfile)
return False 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(): if oldpid == os.getpid():
# that's us? # that's us?
@ -436,7 +435,9 @@ class YumModule(YumDnf):
os.unlink(self.lockfile) os.unlink(self.lockfile)
return False return False
except IOError: except IOError:
# either /proc is not mounted or the process is already dead
try: try:
# check the state of the process
os.kill(oldpid, 0) os.kill(oldpid, 0)
except OSError as e: except OSError as e:
if e.errno == errno.ESRCH: if e.errno == errno.ESRCH:
@ -445,6 +446,9 @@ class YumModule(YumDnf):
return False return False
self.module.fail_json(msg="Unable to check PID %s in %s: %s" % (oldpid, self.lockfile, to_native(e))) 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 # another copy seems to be running
return True return True

Loading…
Cancel
Save