mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #37025 from cro/freebsd_no_proc
Make salt.utils.minion._check_cmdline work on OSes without /proc.
This commit is contained in:
commit
a32b8cd741
1 changed files with 21 additions and 3 deletions
|
@ -17,6 +17,7 @@ def running(opts):
|
|||
'''
|
||||
Return the running jobs on this minion
|
||||
'''
|
||||
|
||||
ret = []
|
||||
proc_dir = os.path.join(opts['cachedir'], 'proc')
|
||||
if not os.path.isdir(proc_dir):
|
||||
|
@ -110,13 +111,30 @@ def _read_proc_file(path, opts):
|
|||
|
||||
def _check_cmdline(data):
|
||||
'''
|
||||
Check the proc filesystem cmdline to see if this process is a salt process
|
||||
In some cases where there are an insane number of processes being created
|
||||
on a system a PID can get recycled or assigned to a non-Salt process.
|
||||
This fn checks to make sure the PID we are checking on is actually
|
||||
a Salt process.
|
||||
|
||||
For non-Linux systems with no procfs style /proc mounted
|
||||
we punt and just return True (assuming that the data has a PID in it)
|
||||
'''
|
||||
if salt.utils.is_windows():
|
||||
return True
|
||||
pid = data.get('pid')
|
||||
if not pid:
|
||||
return False
|
||||
if not os.path.isdir('/proc') or salt.utils.is_windows():
|
||||
return True
|
||||
# Some BSDs have a /proc dir, but procfs is not mounted there. Since
|
||||
# processes are represented by directories in /proc, if there are no
|
||||
# dirs in proc, this is a non-procfs supporting OS. In this case
|
||||
# like the one above we just return True
|
||||
dirs_in_proc = False
|
||||
for dirpath, dirnames, files in os.walk('/proc'):
|
||||
if dirnames:
|
||||
dirs_in_proc = True
|
||||
break
|
||||
if not dirs_in_proc:
|
||||
return True
|
||||
path = os.path.join('/proc/{0}/cmdline'.format(pid))
|
||||
if not os.path.isfile(path):
|
||||
return False
|
||||
|
|
Loading…
Add table
Reference in a new issue