launchd: only use --wait on macOS 26 and later
This commit is contained in:
parent
74b38179ac
commit
ebc87daabc
1 changed files with 26 additions and 10 deletions
|
|
@ -179,6 +179,9 @@ in
|
|||
home.activation.setupLaunchAgents =
|
||||
lib.hm.dag.entryAfter [ "writeBoundary" ] # Bash
|
||||
''
|
||||
# Get the OS version to see if we can use --wait
|
||||
version="$(/usr/bin/sw_vers --productVersion | cut -d. -f 1)"
|
||||
|
||||
# Disable errexit to ensure we process all agents even if some fail
|
||||
set +e
|
||||
|
||||
|
|
@ -230,17 +233,30 @@ in
|
|||
|
||||
verboseEcho "Stopping agent '$domain/$agentName'..."
|
||||
local bootout_output
|
||||
if bootout_output=$(run /bin/launchctl bootout --wait "$domain/$agentName" 2>&1); then
|
||||
return 0
|
||||
else
|
||||
# Only show warning if it's not the common "No such process" error
|
||||
if [[ "$bootout_output" != *"No such process"* ]]; then
|
||||
warnEcho "Failed to stop agent '$domain/$agentName': $bootout_output"
|
||||
return 1
|
||||
else
|
||||
verboseEcho "Agent '$domain/$agentName' was not running"
|
||||
return 2
|
||||
|
||||
if [[ "$version" -ge "26" ]]; then
|
||||
if bootout_output=$(run /bin/launchctl bootout --wait "$domain/$agentName" 2>&1); then
|
||||
# --wait already makes sure it was unloaded (BUT we can only use it in >=26)
|
||||
return 0
|
||||
fi
|
||||
else
|
||||
if bootout_output=$(run /bin/launchctl bootout "$domain/$agentName" 2>&1); then
|
||||
# Otherwise on <26 give the system a moment to fully unload the agent
|
||||
run sleep 1
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# At this point we know exit code is not 0 because otherwise we
|
||||
# would have returned by now
|
||||
|
||||
# Only show warning if it's not the common "No such process" error
|
||||
if [[ "$bootout_output" != *"No such process"* ]]; then
|
||||
warnEcho "Failed to stop agent '$domain/$agentName': $bootout_output"
|
||||
return 1
|
||||
else
|
||||
verboseEcho "Agent '$domain/$agentName' was not running"
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue