softwareupdate --restart broken when launched by root at loginwindow

Originator:michalm.mac
Number:rdar://FB7587210 Date Originated:18.2.2020
Status:Open Resolved:
Product:macOS Product Version:10.15.2
Classification:Unexpected behavior Reproducible:Always
 
Calling /usr/sbin/softwareupdate --install --all --restart does not restart the computer when following conditions are met:

- Command is launched from root user shell or by launchdaemon.
- Console GUI is sitting at loginwindow. There is no GUI session is logged in.

Problem has been replicated with both 2018 MacBook Air with T2 running Catalina and VMware Fusion VM.

# Steps to reproduce

1. There is a Mac with macOS Catalina 10.15.2 ready to update to 10.15.3
2. Enable Remote Login
3. Logout All GUI Sessions -> Mac screen is showing the loginwindow
4. SSH into the Mac with an admin account

## Case 1: SSH and root shell

5. Get root shell with sudo su -
6. Launch `/usr/sbin/softwareupdate --install --all --restart`
(softwareupdate output in attachment case1_out.txt)

## Case 2: lauchdaemon

5. Create LaunchDaemon:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>test.softwareupdate</string>
	<key>OnDemand</key>
	<true/>
        <key>RunAtLoad</key>
	<true/>	
	<key>ProgramArguments</key>
	<array>
		<string>/usr/sbin/softwareupdate</string>
		<string>--install</string>
		<string>--all</string>
		<string>--restart</string>
	</array>
    <key>StandardOutPath</key>
    <string>/private/tmp/test.softwareupdate.log</string>
    <key>StandardErrorPath</key>
    <string>/private/tmp/test.softwareupdate.log</string>    
</dict>
</plist>

6. Use launchctl to load the daemon: sudo launchctl load /Library/LaunchDaemons/test.softwareupdate.plist
7. Monitor log file: tail -f /private/tmp/test.softwareupdate.log
(softwareupdate output in attachment case2_out.txt)

# Expected behavior 

Mac is restarted and system is updated.

# Actual behavior

Mac is not restarted and it keeps sitting at loginwindow.

# Workaround

Launch softwareupdate over SSH from local admin shell using sudo: `sudo /usr/sbin/softwareupdate --install --all --restart`. Mac is restarted and updated afterwards.

This is however not the solution here.  We can't rely on SSH updating managed Macs. There are widely used tools such Munki running as root which needs to be able to call softwareupdate at the loginwindow and do the proper restart afterward. Working --restart switch is very important because of the T2 machines which require special type of shutdown instead of normal reboot when BridgeOS should be also updated.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!