mirror of https://github.com/wolfSSL/wolfssh.git
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 startedpull/1256/head
parent
b3f4630f3f
commit
0efb0174b2
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue