[X2Go-Commits] [x2goserver] 09/33: 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:19:23 CET 2018


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

x2go pushed a commit to branch master
in repository x2goserver.

commit 97c9988516e91ac519ce44b71fc093649918a24a
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.
    
    Cherry-picked from release/4.0.1.x branch.
---
 debian/changelog              | 11 +++++++++++
 x2goserver/bin/x2gostartagent | 12 +++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 80d0a06..115dee0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -280,6 +280,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 8205cd1..e603939 100755
--- a/x2goserver/bin/x2gostartagent
+++ b/x2goserver/bin/x2gostartagent
@@ -547,6 +547,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
 	# unset LD_LIBRARY_PATH for the case when x2gostartagent started from x2godesktopsharing
 	unset LD_LIBRARY_PATH
@@ -562,7 +563,6 @@ fi
 ln -s "${SESSION_DIR}" "${X2GO_ROOT}/C-${SESSION_NAME}"
 
 X2GO_AGENT_PID="${!}"
-X2GO_AGENT_RETVAL="${?}"
 
 if [[ -n "${SHADREQ_USER}" ]]; then
 	"${X2GO_LIB_PATH}/x2gosyslog" "${0}" 'info' "creating new shadow session: ${SESSION_NAME} ${X2GO_COOKIE} ${X2GO_AGENT_PID} ${X2GO_CLIENT} ${GR_PORT} ${SOUND_PORT} ${FS_PORT} ${SHADREQ_USER}"
@@ -577,16 +577,22 @@ if [ "${X2GO_SET_KBD}" == "0" ] || [ "${X2GO_KBD_TYPE}" != "auto" ]; then
 	mkdir -p "${SESSION_DIR}/keyboard"
 fi
 
-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
 
 echo "${X2GO_PORT}"

--
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