mirror of
https://github.com/apple/container.git
synced 2026-07-12 12:37:02 +00:00
fd2de35440
- 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>
76 lines
2.1 KiB
Bash
Executable File
76 lines
2.1 KiB
Bash
Executable File
#! /bin/bash -f
|
|
# Copyright © 2025-2026 Apple Inc. and the container project authors.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
ALL_DOMAINS=false
|
|
|
|
usage() {
|
|
echo "Usage: $0 [-a] [-h]"
|
|
echo "Stop container services"
|
|
echo
|
|
echo "Options:"
|
|
echo "a Stop container services in all launchd domains."
|
|
echo "h Show this help message."
|
|
echo
|
|
exit 1
|
|
}
|
|
|
|
while getopts ":ah" arg; do
|
|
case "$arg" in
|
|
a)
|
|
ALL_DOMAINS=true
|
|
;;
|
|
h)
|
|
usage
|
|
;;
|
|
*)
|
|
echo "Invalid option: -${OPTARG}"
|
|
usage
|
|
;;
|
|
esac
|
|
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" 2>/dev/null || true
|
|
done
|
|
done
|
|
else
|
|
domain_string=""
|
|
|
|
launchd_domain=$(launchctl managername)
|
|
|
|
if [[ "$launchd_domain" == "System" ]]; then
|
|
domain_string="system"
|
|
elif [[ "$launchd_domain" == "Aqua" ]]; then
|
|
domain_string="gui/$(id -u)"
|
|
elif [[ "$launchd_domain" == "Background" ]]; then
|
|
domain_string="user/$(id -u)"
|
|
else
|
|
echo "Unsupported launchd domain. Exiting"
|
|
exit 1
|
|
fi
|
|
|
|
launchctl list | grep -e 'com\.apple\.container\W' | awk '{print $3}' \
|
|
| xargs -I % sh -c 'launchctl bootout '"$domain_string"'/% 2>/dev/null || true'
|
|
fi
|