ensure-container-stopped.sh: don't fail on launchctl errors (#1461)

- Fixes #1281. Supersedes #1306.
- When `-a` runs as a regular user (such as via
  `brew install container`), two launchctl failures
  bubble up as a non-zero exit and break Homebrew's
  post-install:
  - `bootout` against `system` requires root.
  - `launchctl print` lists Mach endpoint names that
    aren't loaded jobs, so `bootout` returns
    `No such process` on them.
- Skip `system` when not root, and treat individual
  `bootout` failures as non-fatal. Same fix applied to
  the non-`-a` `xargs` pipeline.

Signed-off-by: Patrick Linnane <patrick@linnane.io>
This commit is contained in:
Patrick Linnane
2026-04-29 19:42:49 -07:00
committed by GitHub
parent bfe587b8e8
commit fd2de35440
+6 -2
View File
@@ -44,11 +44,14 @@ done
if $ALL_DOMAINS; then
uid=$(id -u)
for domain in "gui/$uid" "user/$uid" "system"; do
if [ "$domain" = "system" ] && [ "$uid" -ne 0 ]; then
continue
fi
launchctl print "$domain" 2>/dev/null \
| grep -oE 'com\.apple\.container\.[^ ]+' \
| sort -u \
| while read -r service; do
launchctl bootout "$domain/$service"
launchctl bootout "$domain/$service" 2>/dev/null || true
done
done
else
@@ -67,5 +70,6 @@ else
exit 1
fi
launchctl list | grep -e 'com\.apple\.container\W' | awk '{print $3}' | xargs -I % launchctl bootout $domain_string/%
launchctl list | grep -e 'com\.apple\.container\W' | awk '{print $3}' \
| xargs -I % sh -c 'launchctl bootout '"$domain_string"'/% 2>/dev/null || true'
fi