mirror of
https://github.com/munki/munki.git
synced 2026-04-30 09:19:31 -05:00
munkicommon: New currentGUIusers() function to get list of current GUI users
managedsoftwareupdate: makes use of munkicommon.currentGUIusers() to more accurately determine if anyone is logged in to the GUI (Fast User Switching aware) git-svn-id: http://munki.googlecode.com/svn/trunk@445 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
@@ -144,21 +144,10 @@ def doRestart():
|
||||
print restartMessage
|
||||
sys.stdout.flush()
|
||||
|
||||
consoleuser = munkicommon.getconsoleuser()
|
||||
if consoleuser == None:
|
||||
if not munkicommon.currentGUIusers():
|
||||
# no-one is logged in and we're at the loginwindow
|
||||
time.sleep(5)
|
||||
retcode = subprocess.call(["/sbin/shutdown", "-r", "now"])
|
||||
elif consoleuser == u"loginwindow":
|
||||
# crap. Someone is logged in, Fast User Switching is active,
|
||||
# but we're switched out to the loginwindow. Not safe to
|
||||
# restart because users might have unsaved work.
|
||||
# this could happen if someone switched to the loginwindow while
|
||||
# updates were being installed.
|
||||
#
|
||||
# TO-DO: handle this!
|
||||
#
|
||||
pass
|
||||
else:
|
||||
if munkicommon.munkistatusoutput:
|
||||
# someone is logged in and we're using munkistatus
|
||||
@@ -454,20 +443,24 @@ def main():
|
||||
# just install
|
||||
mustrestart = doInstallTasks()
|
||||
elif options.auto:
|
||||
consoleuser = munkicommon.getconsoleuser()
|
||||
if consoleuser:
|
||||
# someone is logged in.
|
||||
if consoleuser == u"loginwindow":
|
||||
# someone is logged in, but we're sitting at
|
||||
# the loginwindow due to fast user switching
|
||||
# so do nothing
|
||||
pass
|
||||
else:
|
||||
# notify the current console user
|
||||
notifyUserOfUpdates()
|
||||
elif getIdleSeconds() > 10:
|
||||
# no console user, system is idle, so install
|
||||
mustrestart = doInstallTasks()
|
||||
if not munkicommon.currentGUIusers():
|
||||
# no GUI users
|
||||
if getIdleSeconds() > 10:
|
||||
# no GUI users, system is idle, so install
|
||||
mustrestart = doInstallTasks()
|
||||
else:
|
||||
# there are GUI users
|
||||
consoleuser = munkicommon.getconsoleuser()
|
||||
if consoleuser:
|
||||
# someone is logged in.
|
||||
if consoleuser == u"loginwindow":
|
||||
# someone is logged in, but we're sitting at
|
||||
# the loginwindow due to fast user switching
|
||||
# so do nothing
|
||||
pass
|
||||
else:
|
||||
# notify the current console user
|
||||
notifyUserOfUpdates()
|
||||
elif not options.quiet:
|
||||
print ("\nRun %s --installonly to install the downloaded "
|
||||
"updates." % myname)
|
||||
|
||||
@@ -351,8 +351,23 @@ def getconsoleuser():
|
||||
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
|
||||
cfuser = SCDynamicStoreCopyConsoleUser( None, None, None )
|
||||
return cfuser[0]
|
||||
|
||||
|
||||
|
||||
|
||||
def currentGUIusers():
|
||||
'''Gets a list of GUI users by parsing the output of /usr/bin/who'''
|
||||
gui_users = []
|
||||
p = subprocess.Popen("/usr/bin/who", shell=False, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(output, err) = p.communicate()
|
||||
lines = output.splitlines()
|
||||
for line in lines:
|
||||
if "console" in line:
|
||||
parts = line.split()
|
||||
gui_users.append(parts[0])
|
||||
|
||||
return gui_users
|
||||
|
||||
|
||||
def pythonScriptRunning(scriptname):
|
||||
cmd = ['/bin/ps', '-eo', 'pid=,command=']
|
||||
p = subprocess.Popen(cmd, shell=False, bufsize=1, stdin=subprocess.PIPE,
|
||||
|
||||
Reference in New Issue
Block a user