fix(bash): zstart --detached no longer hangs on the tracking FIFO

Detached mode forked the long-lived server while it still inherited the
ztokens tracking fds (the capture FIFO on 1/2, saved stdout/stderr on
3/4). The parent's EXIT-trap footer runs `tee` on that FIFO and waits for
EOF, which never came while the server held it open - so `zstart
--detached` (and zstartd / zrestart --detached) hung instead of
returning. detach() now redirects stdin<-/dev/null, stdout/stderr->log
and closes fd 3/4 before exec'ing the server. Verified on WSL: detached
returns in 0s and the server still boots.
This commit is contained in:
KellyMichels 2026-07-23 18:41:47 -05:00
parent c4bf4a15af
commit e64829f97c

View File

@ -44,7 +44,13 @@ warn_if_privileged_port() { # <port>
detach() { # <key> <workdir> <cmd...> detach() { # <key> <workdir> <cmd...>
local key="$1" dir="$2"; shift 2 local key="$1" dir="$2"; shift 2
local log="/tmp/zstart-${key}.log" local log="/tmp/zstart-${key}.log"
( cd "$dir" && nohup "$@" >"$log" 2>&1 & ) # Sever every fd tied to this shell before exec'ing the long-lived server:
# stdin<-/dev/null, stdout/stderr->log, and CLOSE the ztokens tracking fds
# (3/4 = saved stdout/stderr; 1/2 fed the capture FIFO). If the server keeps
# any open, the parent's EXIT-trap footer (a `tee` on the FIFO) never gets
# EOF and `zstart --detached` hangs instead of returning.
( cd "$dir" && exec </dev/null >"$log" 2>&1 3>&- 4>&-; exec nohup "$@" ) &
disown 2>/dev/null || true
ok "Started in detached mode (logs: $log)." ok "Started in detached mode (logs: $log)."
dim "Use zkill $key to stop it." dim "Use zkill $key to stop it."
} }