[X2Go-Commits] [x2goserver] 03/03: x2goserver/bin/x2gostartagent: convert X2GO_PORT searching algorithm to pure bash and let script fail if no display port is available.

git-admin at x2go.org git-admin at x2go.org
Mon Feb 27 14:15:57 CET 2017


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

x2go pushed a commit to branch release/4.0.1.x
in repository x2goserver.

commit e7164fa6c0998e5817c182dd36439cc9cb4c4301
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Mon Feb 27 14:12:20 2017 +0100

    x2goserver/bin/x2gostartagent: convert X2GO_PORT searching algorithm to pure bash and let script fail if no display port is available.
---
 debian/changelog              |    2 ++
 x2goserver/bin/x2gostartagent |   33 ++++++++++++++++++++++++++++++---
 2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 6a28f25..c40c55d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -6,6 +6,8 @@ x2goserver (4.0.1.21-0x2go1) UNRELEASED; urgency=medium
       nxagent sockets. If the nxagent process already vanished, simply forget
       the remembered session. Otherwise we might delete sockets that have been
       re-assigned to other sessions in the meantime.
+    - x2goserver/bin/x2gostartagent: convert X2GO_PORT searching algorithm to
+      pure bash and let script fail if no display port is available.
   * x2goserver.spec:
     - Add mandatory perl-generators Build-Requires as per
       https://fedoraproject.org/wiki/Changes/Build_Root_Without_Perl
diff --git a/x2goserver/bin/x2gostartagent b/x2goserver/bin/x2gostartagent
index 1b6acce..80849b7 100755
--- a/x2goserver/bin/x2gostartagent
+++ b/x2goserver/bin/x2gostartagent
@@ -254,7 +254,8 @@ ss=$(PATH="$PATH:/usr/sbin:/sbin" type -P ss);
 
 while [ "$OUTPUT"  != "inserted" ]; do
 
-	USED_DISPLAYS=`$X2GO_LIB_PATH/x2gogetdisplays $HOSTNAME`
+	typeset -a used_displays
+	IFS='' read -ar used_displays < <("${X2GO_LIB_PATH}/x2gogetdisplays" "${HOSTNAME}")
 
 	#Get all used in system ports from X2Go database and ss output
 	USED_PORTS=$(
@@ -264,8 +265,34 @@ while [ "$OUTPUT"  != "inserted" ]; do
 	);
 
 	X2GO_PORT=$(($X2GO_PORT + 1))
-	X2GO_PORT=`echo "for(\\$i=$X2GO_PORT;\\$br ne \"true\";\\$i++){ if(\"$USED_DISPLAYS\" =~ m/\\|\\$i\\|/){\\$br=\"false\";}else{\\$br=\"true\";print \\$i;}}"|perl`
-	
+
+	typeset -i search_x2go_port="0"
+
+	# Find the next free port number.
+	for ((search_x2go_port = X2GO_PORT; i <= 59535; ++search_x2go_port)); do
+		typeset -i i="0"
+		typeset -i value_found="0"
+
+		for ((i = 0; i < ${#used_displays[@]}; ++i)); do
+			if [[ "${used_displays[i]}" =~ /|${search_x2go_port}|/ ]]; then
+				# We need to continue with the next port number,
+				# this one is taken.
+				value_found="1"
+				break
+			fi
+		done
+
+		# Searched the array and got nothing? Great, grab that port number!
+		[[ "${value_found}" -eq "0" ]] && break
+	done
+
+	if [[ "${search_x2go_port}" -gt "59535" ]]; then
+		$X2GO_LIB_PATH/x2gosyslog "$0" "err" "no free display number available, cannot start new session"
+		exit -1
+	fi
+
+	X2GO_PORT="${search_x2go_port}"
+
 	#Test if the session is already in use. nxagent uses 6000+DISPLAY to open a port. Therefore this must be tested, too.
 	NX_PORT=$(($X2GO_PORT + 6000))
 	if $ss -lxs 2>/dev/null | egrep "(@|)/tmp/.X11-unix/X${X2GO_PORT}(|-lock) " 1>/dev/null ||

--
Alioth's /srv/git/code.x2go.org/x2goserver.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/x2goserver.git


More information about the x2go-commits mailing list