[openssh-commits] [openssh] 01/01: upstream: rewrite this test to use a multiplexed ssh session so we can

git+noreply at mindrot.org git+noreply at mindrot.org
Wed Jan 11 11:54:24 AEDT 2023


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit d888de06c5e4d7dbf2f2b85f2b5bf028c570cf78
Author: djm at openbsd.org <djm at openbsd.org>
Date:   Wed Jan 11 00:51:27 2023 +0000

    upstream: rewrite this test to use a multiplexed ssh session so we can
    
    control its lifecycle without risk of race conditions; fixes some of the
    Github integration tests for openssh-portable
    
    OpenBSD-Regress-ID: 5451cad59ba0d43ae9eeda48ec80f54405fee969
---
 regress/dynamic-forward.sh | 58 +++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/regress/dynamic-forward.sh b/regress/dynamic-forward.sh
index 55f69219..5a4aa6d8 100644
--- a/regress/dynamic-forward.sh
+++ b/regress/dynamic-forward.sh
@@ -3,18 +3,18 @@
 
 tid="dynamic forwarding"
 
-FWDPORT=`expr $PORT + 1`
-
-cp $OBJ/ssh_config $OBJ/ssh_config.orig
-
-proxycmd="$OBJ/netcat -x 127.0.0.1:$FWDPORT -X"
-trace "will use ProxyCommand $proxycmd"
-
 # This is a reasonable proxy for IPv6 support.
 if ! config_defined HAVE_STRUCT_IN6_ADDR ; then
 	SKIP_IPV6=yes
 fi
 
+FWDPORT=`expr $PORT + 1`
+make_tmpdir
+CTL=${SSH_REGRESS_TMP}/ctl-sock
+cp $OBJ/ssh_config $OBJ/ssh_config.orig
+proxycmd="$OBJ/netcat -x 127.0.0.1:$FWDPORT -X"
+trace "will use ProxyCommand $proxycmd"
+
 start_ssh() {
 	direction="$1"
 	arg="$2"
@@ -22,32 +22,31 @@ start_ssh() {
 	error="1"
 	trace "start dynamic -$direction forwarding, fork to background"
 	(cat $OBJ/ssh_config.orig ; echo "$arg") > $OBJ/ssh_config
-	while [ "$error" -ne 0 -a "$n" -lt 3 ]; do
-		n=`expr $n + 1`
-		${REAL_SSH} -F $OBJ/ssh_config -f -vvv -E$TEST_SSH_LOGFILE \
-		    -$direction $FWDPORT -oExitOnForwardFailure=yes \
-		    somehost exec sh -c \
-			\'"echo \$\$ > $OBJ/remote_pid; exec sleep 444"\'
-		error=$?
-		if [ "$error" -ne 0 ]; then
-			trace "forward failed attempt $n err $error"
-			sleep $n
-		fi
-	done
-	if [ "$error" -ne 0 ]; then
-		fatal "failed to start dynamic forwarding"
+	${REAL_SSH} -vvvnNfF $OBJ/ssh_config -E$TEST_SSH_LOGFILE \
+	    -$direction $FWDPORT -oExitOnForwardFailure=yes \
+	    -oControlMaster=yes -oControlPath=$CTL somehost
+	r=$?
+	test $r -eq 0 || fatal "failed to start dynamic forwarding $r"
+	if ! ${REAL_SSH} -qF$OBJ/ssh_config -O check \
+	     -oControlPath=$CTL somehost >/dev/null 2>&1 ; then
+		fatal "forwarding ssh process unresponsive"
 	fi
 }
 
 stop_ssh() {
-	if [ -f $OBJ/remote_pid ]; then
-		remote=`cat $OBJ/remote_pid`
-		trace "terminate remote shell, pid $remote"
-		if [ $remote -gt 1 ]; then
-			kill -HUP $remote
-		fi
-	else
-		fail "no pid file: $OBJ/remote_pid"
+	test -S $CTL || return
+	if ! ${REAL_SSH} -qF$OBJ/ssh_config -O exit \
+	     -oControlPath=$CTL >/dev/null somehost >/dev/null ; then
+		fatal "forwarding ssh process did not respond to close"
+	fi
+	n=0
+	while [ "$n" -lt 20 ] ; do
+		test -S $CTL || break
+		sleep 1
+		n=`expr $n + 1`
+	done
+	if test -S $CTL ; then
+		fatal "forwarding ssh process did not exit"
 	fi
 }
 
@@ -75,6 +74,7 @@ check_socks() {
 }
 
 start_sshd
+trap "stop_ssh" EXIT
 
 for d in D R; do
 	verbose "test -$d forwarding"

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list