Don't crash when calling checkForSoftwareUpdates() on 10.5.x if /System/Library/CoreServices/Software Update.app does not exist. (problem seen in field; likely user deleting it, but unknown at the time).

Also protect against softwareupdate not existing, or Software Update.app disappearing between stat/chmod and Popen() calls.


git-svn-id: http://munki.googlecode.com/svn/trunk@1153 a4e17f2e-e282-11dd-95e1-755cbddbdd66
This commit is contained in:
Justin McWilliams
2011-04-27 15:27:36 +00:00
parent c54eef542c
commit 820f88f364
+31 -13
View File
@@ -145,14 +145,19 @@ def checkForSoftwareUpdates():
softwareupdatecheck = os.path.join(softwareupdateapp,
"Contents/Resources/SoftwareUpdateCheck")
# record mode of Software Update.app
rawmode = os.stat(softwareupdateapp).st_mode
oldmode = stat.S_IMODE(rawmode)
# set mode of Software Update.app so it won't launch
# yes, this is a hack. So sue me.
newmode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
os.chmod(softwareupdateapp, newmode)
try:
# record mode of Software Update.app
rawmode = os.stat(softwareupdateapp).st_mode
oldmode = stat.S_IMODE(rawmode)
# set mode of Software Update.app so it won't launch
# yes, this is a hack. So sue me.
newmode = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
os.chmod(softwareupdateapp, newmode)
except OSError, e:
munkicommon.display_warning(
'Error with os.stat(Softare Update.app): %s', str(e))
munkicommon.display_warning('Skipping Apple SUS check.')
return -2
cmd = [ softwareupdatecheck ]
elif osvers > 9:
@@ -167,11 +172,24 @@ def checkForSoftwareUpdates():
oldverbose = munkicommon.verbose
munkicommon.verbose = oldverbose + 1
# now check for updates
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
try:
# now check for updates
proc = subprocess.Popen(cmd, shell=False, bufsize=-1,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
except OSError, e:
munkicommon.display_warning('Error with Popen(%s): %s', cmd, str(e))
munkicommon.display_warning('Skipping Apple SUS check.')
# if 10.5.x, safely revert the chmod from above.
if osvers == 9:
try:
# put mode back for Software Update.app
os.chmod(softwareupdateapp, oldmode)
except OSError:
pass
return -3
while True:
output = proc.stdout.readline().decode('UTF-8')
if munkicommon.munkistatusoutput: