mirror of
https://github.com/munki/munki.git
synced 2026-04-23 13:29:26 -05:00
Move getPIDforProcessName into munkicommon for use by both munkistatus and adobeutils
This commit is contained in:
@@ -427,24 +427,7 @@ def findAdobeDeploymentManager(dirpath):
|
||||
if os.path.exists(dm_path):
|
||||
return dm_path
|
||||
return ''
|
||||
|
||||
|
||||
def getPID(processname):
|
||||
'''Returns process ID for a command string'''
|
||||
cmd = ['/bin/ps', '-eo', 'pid=,command=']
|
||||
proc = subprocess.Popen(cmd, shell=False, bufsize=1,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
(out, unused_err) = proc.communicate()
|
||||
lines = str(out).splitlines()
|
||||
for line in lines:
|
||||
(pid, process) = line.split(None, 1)
|
||||
if process.find(processname) != -1:
|
||||
return pid
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
secondsToLive = {}
|
||||
def killStupidProcesses():
|
||||
@@ -456,7 +439,7 @@ def killStupidProcesses():
|
||||
"open -a /Library/Application Support/Adobe/SwitchBoard/SwitchBoard.app"]
|
||||
|
||||
for procname in stupid_processes:
|
||||
pid = getPID(procname)
|
||||
pid = munkicommon.getPIDforProcessName(procname)
|
||||
if pid:
|
||||
if not pid in secondsToLive:
|
||||
secondsToLive[pid] = 30
|
||||
@@ -682,7 +665,7 @@ def runAdobeCS5AAMEEInstall(dmgpath):
|
||||
munkicommon.getconsoleuser() == u"loginwindow"):
|
||||
# we're at the loginwindow, so we need to run the deployment
|
||||
# manager in the loginwindow context using launchctl bsexec
|
||||
loginwindowPID = getPID("loginwindow")
|
||||
loginwindowPID = munkicommon.getPIDforProcessName("loginwindow")
|
||||
cmd = ['/bin/launchctl', 'bsexec', loginwindowPID]
|
||||
else:
|
||||
cmd = []
|
||||
|
||||
@@ -643,6 +643,34 @@ def getconsoleuser():
|
||||
return cfuser[0]
|
||||
|
||||
|
||||
def getPIDforProcessName(processname):
|
||||
'''Returns a process ID for processname'''
|
||||
cmd = ['/bin/ps', '-eo', 'pid=,command=']
|
||||
try:
|
||||
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
while True:
|
||||
line = proc.stdout.readline().decode('UTF-8')
|
||||
if not line and (proc.poll() != None):
|
||||
break
|
||||
line = line.rstrip('\n')
|
||||
if line:
|
||||
try:
|
||||
(pid, process) = line.split(None, 1)
|
||||
except ValueError:
|
||||
# funky process line, so we'll skip it
|
||||
pass
|
||||
else:
|
||||
if process.find(processname) != -1:
|
||||
return str(pid)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def currentGUIusers():
|
||||
"""Gets a list of GUI users by parsing the output of /usr/bin/who"""
|
||||
gui_users = []
|
||||
|
||||
@@ -101,39 +101,12 @@ def readResponse():
|
||||
return ''
|
||||
|
||||
|
||||
def getPIDforProcessName(processname):
|
||||
'''Returns a process ID for processname'''
|
||||
cmd = ['/bin/ps', '-eo', 'pid=,command=']
|
||||
try:
|
||||
proc = subprocess.Popen(cmd, shell=False, bufsize=1,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
except OSError:
|
||||
return 0
|
||||
|
||||
while True:
|
||||
line = proc.stdout.readline().decode('UTF-8')
|
||||
if not line and (proc.poll() != None):
|
||||
break
|
||||
line = line.rstrip('\n')
|
||||
if line:
|
||||
try:
|
||||
(pid, process) = line.split(None, 1)
|
||||
except ValueError:
|
||||
# funky process line, so we'll skip it
|
||||
pass
|
||||
else:
|
||||
if process.find(processname) != -1:
|
||||
return str(pid)
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def getMunkiStatusPID():
|
||||
'''Gets the process ID for Managed Software Update'''
|
||||
return getPIDforProcessName(
|
||||
"Managed Software Update.app/Contents/MacOS/Managed Software Update") \
|
||||
or getPIDforProcessName("MunkiStatus.app/Contents/MacOS/MunkiStatus")
|
||||
return munkicommon.getPIDforProcessName(
|
||||
"Managed Software Update.app/Contents/MacOS/Managed Software Update") \
|
||||
or munkicommon.getPIDforProcessName(
|
||||
"MunkiStatus.app/Contents/MacOS/MunkiStatus")
|
||||
|
||||
|
||||
def getMunkiStatusSocket():
|
||||
|
||||
Reference in New Issue
Block a user