From 2ad5266b37cdf5336db513cea87ff67efb906af4 Mon Sep 17 00:00:00 2001 From: Nuno Goncalves Date: Wed, 22 Dec 2010 23:14:01 +0000 Subject: [PATCH] sshtunnel: bug fix SVN-Revision: 24807 --- net/sshtunnel/files/initd_sshtunnel | 21 +++++++++++++-------- net/sshtunnel/files/sshtunnel.sh | 5 +++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/net/sshtunnel/files/initd_sshtunnel b/net/sshtunnel/files/initd_sshtunnel index 3c8c26465..3e585634d 100644 --- a/net/sshtunnel/files/initd_sshtunnel +++ b/net/sshtunnel/files/initd_sshtunnel @@ -135,11 +135,11 @@ load_server() { [ -n "$error" ] && { logger -p user.err -t "sshtunnel" "tunnels to $server not started - $error"; return; } [ "$count" -eq 0 ] && { logger -p user.err -t "sshtunnel" "tunnels to $server not started - no tunnels defined"; return; } - append_params CheckHostIP Compression CompressionLevel IdentityFile LogLevel PKCS11Provider ServerAliveCountMax ServerAliveInterval StrickHostKeyChecking TCPKeepAlive VerifyHostKeyDNS + append_params CheckHostIP Compression CompressionLevel IdentityFile LogLevel PKCS11Provider ServerAliveCountMax ServerAliveInterval StrictHostKeyChecking TCPKeepAlive VerifyHostKeyDNS ARGS="$ARGS_options -o ExitOnForwardFailure=yes -o BatchMode=yes -nN $ARGS_tunnels $user@$hostname" /usr/bin/sshtunnel.sh "$ARGS" "$retrydelay" "$server" & - echo $! >> "$PIDFILE".pids + echo $! >> "${PIDFILE}.pids" logger -p user.info -t "sshtunnel" "started tunnels to $server (pid=$!;retrydelay=$retrydelay)" } @@ -150,13 +150,18 @@ stop() { while read pid do - start-stop-daemon -K -p "$PIDFILE"_"$pid".pid - kill $pid + kill "$pid" # kill mother process first + + [ -f "${PIDFILE}_${pid}.pid" ] && { # if ssh was running, kill it also (mother process could be in retry wait) + start-stop-daemon -K -p "${PIDFILE}_${pid}.pid" + rm "${PIDFILE}_${pid}.pid" + } + logger -p daemon.info -t "sshtunnel[$pid]" "tunnel stopped" - rm "$PIDFILE"_"$pid".pid - done < "$PIDFILE".pids + + done < "${PIDFILE}.pids" - rm "$PIDFILE".pids + rm "${PIDFILE}.pids" logger -p user.info -t "sshtunnel" "all tunnels stopped" else @@ -165,7 +170,7 @@ stop() { } start() { - [ -f "$PIDFILE".pids ] && stop + [ -f "${PIDFILE}.pids" ] && stop config_load sshtunnel if [ -n "$(uci show sshtunnel.@server[0])" ] # at least one server section exists diff --git a/net/sshtunnel/files/sshtunnel.sh b/net/sshtunnel/files/sshtunnel.sh index 77a8d6fc0..0ff18a6a2 100644 --- a/net/sshtunnel/files/sshtunnel.sh +++ b/net/sshtunnel/files/sshtunnel.sh @@ -10,11 +10,12 @@ while true do logger -p daemon.info -t "sshtunnel[$$][$server]" "connection started" - start-stop-daemon -S -p "$PIDFILE"_"$$".pid -mx ssh -- $args &>/tmp/log/sshtunnel_$$ + start-stop-daemon -S -p "${PIDFILE}_${$}.pid" -mx ssh -- $args &>/tmp/log/sshtunnel_$$ logger -p daemon.err -t "sshtunnel[$$][$server]" < /tmp/log/sshtunnel_$$ rm /tmp/log/sshtunnel_$$ logger -p daemon.info -t "sshtunnel[$$][$server]" "ssh exited with code $?, retrying in $retrydelay seconds" - + rm "${PIDFILE}_${$}.pid" + sleep "$retrydelay" & wait done -- 2.30.2