mirror of
https://github.com/kellymichels/zscripts-token-savers
synced 2026-10-07 07:18:18 +00:00
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:
parent
c4bf4a15af
commit
e64829f97c
@ -44,7 +44,13 @@ warn_if_privileged_port() { # <port>
|
||||
detach() { # <key> <workdir> <cmd...>
|
||||
local key="$1" dir="$2"; shift 2
|
||||
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)."
|
||||
dim "Use zkill $key to stop it."
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user