diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-19 13:18:34 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-24 11:19:18 +0200 |
commit | 59c9dbe6a3e7caed435b13188cb42354ca577fb4 (patch) | |
tree | 04c02e6ad19eb2c55e00187ad6b01244022fddfb /src | |
parent | qemu: show signal when failing (diff) | |
download | wireguard-monolithic-historical-59c9dbe6a3e7caed435b13188cb42354ca577fb4.tar.xz wireguard-monolithic-historical-59c9dbe6a3e7caed435b13188cb42354ca577fb4.zip |
wg-quick: darwin: support being called from launchd
This causes wg-quick up to wait for the monitor to exit before it exits,
so that launchd can correctly wait on it.
Reported-by: Cameron Palmer <cameron@promon.no>
Diffstat (limited to 'src')
-rwxr-xr-x | src/tools/wg-quick/darwin.bash | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/tools/wg-quick/darwin.bash b/src/tools/wg-quick/darwin.bash index a2b3789..d5dd396 100755 --- a/src/tools/wg-quick/darwin.bash +++ b/src/tools/wg-quick/darwin.bash @@ -81,6 +81,17 @@ parse_options() { shopt -u nocasematch } +detect_launchd() { + unset LAUNCHED_BY_LAUNCHD + local line + while read -r line; do + if [[ $line =~ ^\s*domain\ =\ ]]; then + LAUNCHED_BY_LAUNCHD=1 + break + fi + done < <(launchctl procinfo $$ 2>/dev/null) +} + read_bool() { case "$2" in true) printf -v "$1" 1 ;; @@ -308,7 +319,8 @@ monitor_daemon() { set_dns sleep 2 && kill -ALRM $pid 2>/dev/null & fi - done < <(route -n monitor)) & disown + done < <(route -n monitor)) & + [[ -n $LAUNCHED_BY_LAUNCHD ]] || disown } add_route() { @@ -463,6 +475,7 @@ if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then cmd_usage elif [[ $# -eq 2 && $1 == up ]]; then auto_su + detect_launchd parse_options "$2" cmd_up elif [[ $# -eq 2 && $1 == down ]]; then @@ -482,4 +495,6 @@ else exit 1 fi +[[ -n $LAUNCHED_BY_LAUNCHD ]] && wait + exit 0 |