Only set the secret preference if we're going to attempt an authrestart; rely on default behavior otherwise

This commit is contained in:
Greg Neagle
2017-04-13 16:31:30 -07:00
parent 72f369544f
commit 8b6ecc6788
2 changed files with 21 additions and 14 deletions
+10 -1
View File
@@ -103,6 +103,15 @@ def get_auth_restart_key():
return ''
def can_attempt_auth_restart():
'''Returns a boolean to indicate if all the needed conditions are present
for us to attempt an authrestart'''
os_version_tuple = osutils.getOsVersion(as_tuple=True)
return (os_version_tuple >= (10, 8) and
prefs.pref('PerformAuthRestarts') and filevault_is_active() and
supports_auth_restart() and get_auth_restart_key() != '')
def perform_auth_restart():
"""When called this will perform an authorized restart. Before trying
to perform an authorized restart it checks to see if the machine supports
@@ -138,7 +147,7 @@ def perform_auth_restart():
def do_authorized_or_normal_restart():
'''Do an authrestart is allowed/possible, else do a normal restart.'''
'''Do an authrestart if allowed/possible, else do a normal restart.'''
display.display_info('Restarting now.')
os_version_tuple = osutils.getOsVersion(as_tuple=True)
if (prefs.pref('PerformAuthRestarts')
+11 -13
View File
@@ -110,24 +110,22 @@ class StartOSInstallRunner(object):
display.display_error(
'Could not set up Munki to run after OS upgrade is complete: '
"%s", err)
# remove the diskimage to free up more space for the actual install
if pkgutils.hasValidDiskImageExt(self.installer):
# remove the diskimage to free up more space for the actual install
try:
os.unlink(self.installer)
except (IOError, OSError):
pass
# set a preference to tell the osinstaller process to exit instead
# of restart
# this is the equivalent of:
# `defaults write /Library/Preferences/.GlobalPreferences
# IAQuitInsteadOfReboot -bool YES`
CFPreferencesSetValue(
'IAQuitInsteadOfReboot', True, '.GlobalPreferences',
kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
if authrestart.can_attempt_auth_restart():
# set a secret preference to tell the osinstaller process to exit
# instead of restart
# this is the equivalent of:
# `defaults write /Library/Preferences/.GlobalPreferences
# IAQuitInsteadOfReboot -bool YES`
CFPreferencesSetValue(
'IAQuitInsteadOfReboot', True, '.GlobalPreferences',
kCFPreferencesAnyUser, kCFPreferencesCurrentHost)
# now tell startosinstall it's OK to proceed
# can't use os.kill now that we wrap the call of startosinstall
#os.kill(self.startosinstall_pid, signal.SIGUSR1)
# so just target processes named 'startosinstall'
subprocess.call(['/usr/bin/killall', '-SIGUSR1', 'startosinstall'])
def get_app_path(self, itempath):
@@ -317,7 +315,7 @@ class StartOSInstallRunner(object):
if retcode == 255:
munkilog.log('startosinstall quit instead of rebooted; we will '
'do restart.')
# clear our special InstallAssistant preference
# clear our special secret InstallAssistant preference
CFPreferencesSetValue(
'IAQuitInsteadOfReboot', None, '.GlobalPreferences',
kCFPreferencesAnyUser, kCFPreferencesCurrentHost)