From e64829f97c7c1d8803e698783e3b26d8350092c1 Mon Sep 17 00:00:00 2001 From: KellyMichels Date: Thu, 23 Jul 2026 18:41:47 -0500 Subject: [PATCH] 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. --- bash/zstart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bash/zstart b/bash/zstart index e90c2ce..7780e87 100644 --- a/bash/zstart +++ b/bash/zstart @@ -44,7 +44,13 @@ warn_if_privileged_port() { # detach() { # 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 "$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." }