From 536e51c87441134691eece776d2e9e65c72ed6da Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 16 Sep 2026 15:49:05 -0700 Subject: [PATCH] wolfsshd: keep the registry when grep fails Dropping a stopped daemon from the run registry now installs the rewritten file only when grep either kept lines or matched none. Any other status is grep failing, and the empty file it leaves behind would become the registry, losing every other daemon's pid. - that registry is what the end-of-run sweep works from, so blanking it strands whatever else the run started --- apps/wolfsshd/test/start_sshd.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/wolfsshd/test/start_sshd.sh b/apps/wolfsshd/test/start_sshd.sh index 0f442fb1..d703490d 100755 --- a/apps/wolfsshd/test/start_sshd.sh +++ b/apps/wolfsshd/test/start_sshd.sh @@ -254,10 +254,21 @@ stop_wolfsshd() { if ! wolfsshd_alive "$PID" \ && [ -n "$WOLFSSHD_TEST_PIDFILE" ] \ && [ -f "$WOLFSSHD_TEST_PIDFILE" ]; then + # Status kept through "|| gstat=$?", not read afterwards: callers + # source this under "set -e", where grep's 1 for a registry that + # held only this pid would end the test. + gstat=0 grep -vx -- "$PID" "$WOLFSSHD_TEST_PIDFILE" \ - > "$WOLFSSHD_TEST_PIDFILE.new" 2>/dev/null || true - mv -f "$WOLFSSHD_TEST_PIDFILE.new" "$WOLFSSHD_TEST_PIDFILE" \ - 2>/dev/null || rm -f "$WOLFSSHD_TEST_PIDFILE.new" + > "$WOLFSSHD_TEST_PIDFILE.new" 2>/dev/null || gstat=$? + # 0 is lines kept, 1 is none kept -- this was the only entry. + # Anything else is grep failing, and the empty file it left would + # install as the registry and lose every other daemon's pid. + if [ "$gstat" -le 1 ]; then + mv -f "$WOLFSSHD_TEST_PIDFILE.new" "$WOLFSSHD_TEST_PIDFILE" \ + 2>/dev/null || rm -f "$WOLFSSHD_TEST_PIDFILE.new" + else + rm -f "$WOLFSSHD_TEST_PIDFILE.new" + fi fi # Cleared so a second call -- an EXIT trap after an explicit stop -- is