[X2Go-Commits] [x2goserver] 06/27: x2goserver/bin/x2gostartagent: checking for the exit status of a variable assignment isn't helping us in finding out if x2goagent is still running.

git-admin at x2go.org git-admin at x2go.org
Wed Jan 10 00:17:57 CET 2018


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 5c1e0b2b65e456c0c091eb4d368d78de97223517
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Tue Jan 2 03:48:02 2018 +0100

    x2goserver/bin/x2gostartagent: checking for the exit status of a variable assignment isn't helping us in finding out if x2goagent is still running.
    
    Even otherwise, the exit status would be useless since we spawn
    x2goagent in the background.
    
    Better check if the PID still exists and error out if it's gone.
    
    There certainly is potential for race conditions (i.e., x2goagent
    started, then exited, then another process took its place). On Linux,
    this situation is unlikely to happen, since PIDs are only recycled once
    the maximum PID value is reached, meaning that enough processes to
    overflow the PID + to get to the original PID value need to be spawned
    in a very short amount of time.
    
    Unlikely, but not impossible.
---
 debian/changelog              | 11 +++++++++++
 x2goserver/bin/x2gostartagent | 12 +++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index e9b706a..4614bc3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -21,6 +21,17 @@ x2goserver (4.0.1.23-0x2go1) UNRELEASED; urgency=medium
       variable usage.
     - x2goserver/bin/x2gostartagent: make shellcheck happy by referencing
       "${SAVED_DISPLAY}" once.
+    - x2goserver/bin/x2gostartagent: checking for the exit status of a
+      variable assignment isn't helping us in finding out if x2goagent is
+      still running. Even otherwise, the exit status would be useless since we
+      spawn x2goagent in the background. Better check if the PID still exists
+      and error out if it's gone. There certainly is potential for race
+      conditions (i.e., x2goagent started, then exited, then another process
+      took its place). On Linux, this situation is unlikely to happen, since
+      PIDs are only recycled once the maximum PID value is reached, meaning
+      that enough processes to overflow the PID + to get to the original PID
+      value need to be spawned in a very short amount of time. Unlikely, but
+      not impossible.
   * x2goserver.spec:
     - RPMify x2goserver-xsession description.
     - Remove qt4 stuff, we're not using the framework here.
diff --git a/x2goserver/bin/x2gostartagent b/x2goserver/bin/x2gostartagent
index 2fe3d85..ad8d635 100755
--- a/x2goserver/bin/x2gostartagent
+++ b/x2goserver/bin/x2gostartagent
@@ -512,6 +512,7 @@ fi
 # but gets in the way of our persistent session scheme.
 loginctl "enable-linger" &>"/dev/null" || :
 
+X2GO_AGENT_PID="0"
 if [ "${X2GO_STYPE}" == "S" ]; then
 	# set NX_TEMP to /tmp, make sure x2goagent starts when pam_tmpdir.so is in use
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "debug" "started nxagent: NX_TEMP=/tmp x2goagent X2GO_NXAGENT_OPTIONS ('${X2GO_NXAGENT_OPTIONS}') NOLISTOPT ('${NOLISTOPT}') X2GODPIOPTION_ ('${X2GODPIOPTION_}') -SESSION_TYPE ('-${SESSION_TYPE}') -auth \"XAUTHORITY\" ('\"${XAUTHORITY}\"') -shadow SHADOW_DESKTOP ('${SHADOW_DESKTOP}') -shadowmode SHADOW_MODE ('${SHADOW_MODE}') agent_geometry ('${agent_geometry}') -name \"SESSION_WINDOW_TITLE\" ('\"${SESSION_WINDOW_TITLE}\"') \"NX_AGENT\" ('\"${NX_AGEN [...]
@@ -525,17 +526,22 @@ fi
 ln -s "${SESSION_DIR}" "${X2GO_ROOT}/C-${SESSION_NAME}"
 
 X2GO_AGENT_PID="${!}"
-X2GO_AGENT_RETVAL="${?}"
-if [ "${X2GO_AGENT_RETVAL}" -eq "0" ]; then
+if ps -p "${X2GO_AGENT_PID}" &>"/dev/null"; then
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "notice" "successfully started X2Go Agent session with ID ${SESSION_NAME}"
 
 	# run x2goserver-extensions for post-start
 	x2gofeature "X2GO_RUN_EXTENSIONS" &>"/dev/null" && x2goserver-run-extensions "${SESSION_NAME}" "post-start" || true
 else
-	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "ERROR: failed to start X2Go Agent session with ID ${SESSION_NAME}"
+	typeset msg="Failed to start X2Go Agent session with ID ${SESSION_NAME}. X2Go Agent terminated unexpectedly. Aborting session startup."
+	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" "err" "${msg}"
+
+	# Make x2goclient fail.
+	echo "${msg}" >&2
 
 	# run x2goserver-extensions for fail-start
 	x2gofeature "X2GO_RUN_EXTENSIONS" &>"/dev/null" && x2goserver-run-extensions "${SESSION_NAME}" "fail-start" || true
+
+	exit "13"
 fi
 
 "${X2GO_LIB_PATH}/x2gocreatesession" "${X2GO_COOKIE}" "${X2GO_AGENT_PID}" "${X2GO_CLIENT}" "${GR_PORT}" "${SOUND_PORT}" "${FS_PORT}" "${SESSION_NAME}" >"/dev/null"

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2goserver.git


More information about the x2go-commits mailing list