Merge pull request #46786 from twangboy/fix_46757

Return int(-1) when pidfile contains invalid data
This commit is contained in:
Nicole Thomas 2018-04-02 14:42:12 -04:00 committed by GitHub
commit f1be939763
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -35,6 +35,7 @@ import salt.utils.args
import salt.utils.xdg
import salt.utils.jid
import salt.utils.files
import salt.utils.win_functions
from salt.utils import kinds
from salt.defaults import DEFAULT_TARGET_DELIM
from salt.utils.validate.path import is_writeable
@ -1017,11 +1018,11 @@ class DaemonMixIn(six.with_metaclass(MixInMeta, object)):
if self.check_pidfile():
pid = self.get_pidfile()
if not salt.utils.is_windows():
if self.check_pidfile() and self.is_daemonized(pid) and not os.getppid() == pid:
if self.check_pidfile() and self.is_daemonized(pid) and os.getppid() != pid:
return True
else:
# We have no os.getppid() on Windows. Best effort.
if self.check_pidfile() and self.is_daemonized(pid):
# We have no os.getppid() on Windows. Use salt.utils.win_functions.get_parent_pid
if self.check_pidfile() and self.is_daemonized(pid) and salt.utils.win_functions.get_parent_pid() != pid:
return True
return False

View file

@ -147,7 +147,7 @@ def get_pidfile(pidfile):
pid = pdf.read().strip()
return int(pid)
except (OSError, IOError, TypeError, ValueError):
return None
return -1
def clean_proc(proc, wait_for_kill=10):