[X2Go-Commits] [x2goserver] 01/01: Clean user SSHD process if connection between server and client lost. This should fix error "Global request tcpip-forward failed".

git-admin at x2go.org git-admin at x2go.org
Tue Jul 22 13:53:10 CEST 2014


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

x2go pushed a commit to branch master
in repository x2goserver.

commit bf318affee905cf7cdeaa5a248dfd07bc46a8a96
Author: Oleksandr Shneyder <o.shneyder at phoca-gmbh.de>
Date:   Tue Jul 22 13:53:02 2014 +0200

    Clean user SSHD process if connection between server and client lost. This should fix error "Global request tcpip-forward failed".
---
 debian/changelog                  |    2 ++
 x2goserver/bin/x2golistsessions   |    3 ++
 x2goserver/bin/x2goresume-session |    3 ++
 x2goserver/bin/x2gostartagent     |    3 ++
 x2goserver/lib/x2gormforward      |   59 +++++++++++++++++++++++++++++++++++++
 x2goserver/sbin/x2gocleansessions |    2 ++
 6 files changed, 72 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 727bdb4..e1a6e14 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -118,6 +118,8 @@ x2goserver (4.1.0.0-0x2go1.1) UNRELEASED; urgency=low
 
   [ Oleksandr Shneyder ]
   * Set default value for clipboard to "both" in x2gostartagent and x2goresume-session.
+    - Clean user SSHD process if connection between server and client lost. This should fix
+      error "Global request tcpip-forward failed".
 
  -- Mike Gabriel <mike.gabriel at das-netzwerkteam.de>  Fri, 09 May 2014 13:06:24 +0200
 
diff --git a/x2goserver/bin/x2golistsessions b/x2goserver/bin/x2golistsessions
index e5cff26..22c9a0c 100755
--- a/x2goserver/bin/x2golistsessions
+++ b/x2goserver/bin/x2golistsessions
@@ -30,6 +30,8 @@ use X2Go::Server::DB qw(db_listsessions db_listsessions_all db_changestatus);
 use X2Go::Server::Agent qw(session_is_suspended session_is_running);
 use X2Go::Log qw(loglevel);
 
+use X2Go::Utils qw( system_capture_stdout_output is_true );
+my $x2go_lib_path = system_capture_stdout_output("x2gopath", "libexec");
 
 openlog($0,'cons,pid','user');
 setlogmask( LOG_UPTO(loglevel()) );
@@ -79,6 +81,7 @@ for (my $i=0;$i<@outp;$i++)
 				db_changestatus( 'S', @sinfo[1] );
 				@outp[$i] =~ s/\|R\|/\|S\|/;
 				system("x2goumount-session", "@sinfo[1]");
+				system("$x2go_lib_path/x2gormforward", "@sinfo[1]");
 			}
 		}
 		elsif (@sinfo[4]eq 'S')
diff --git a/x2goserver/bin/x2goresume-session b/x2goserver/bin/x2goresume-session
index 8e594ad..e7a4e37 100755
--- a/x2goserver/bin/x2goresume-session
+++ b/x2goserver/bin/x2goresume-session
@@ -90,6 +90,8 @@ do
 	STATE=`$X2GO_LIB_PATH/x2gogetagentstate "$SESSION_NAME"`
 done
 
+$X2GO_LIB_PATH/x2gormforward "$SESSION_NAME"
+
 
 NX_XINERAMA_CONF="$X2GO_ROOT/C-$SESSION_NAME/xinerama.conf"
 if [ -e "$NX_XINERAMA_CONF" ]
@@ -288,6 +290,7 @@ if kill -HUP $X2GO_AGENT_PID &>/dev/null; then
 
 	# run x2goserver-extensions for post-resume
 	x2gofeature X2GO_RUN_EXTENSIONS &>/dev/null && x2goserver-run-extensions "$SESSION_NAME" post-resume || true
+	grep PPid /proc/$PPID/status > $X2GO_ROOT/C-$SESSION_NAME/sshd.pid
 else
 	err_msg="ERROR: failed to resume session with ID $SESSION_NAME"
 	echo "$err_msg" 1>&2
diff --git a/x2goserver/bin/x2gostartagent b/x2goserver/bin/x2gostartagent
index 489638d..1dc0251 100755
--- a/x2goserver/bin/x2gostartagent
+++ b/x2goserver/bin/x2gostartagent
@@ -67,6 +67,7 @@ X2GO_FULLSCREEN=0
 
 XAUTHORITY=${XAUTHORITY:-"$HOME/.Xauthority"}
 
+
 if [ "$X2GO_STYPE" == "S" ]; then
 
 	SHADOW_MODE=`echo $X2GO_CMD |awk '{split($0,a,"XSHAD"); print a[1]}'`
@@ -276,6 +277,8 @@ if [ ! -d "$X2GO_ROOT/ssh" ]; then
 	mkdir "$X2GO_ROOT/ssh"
 fi
 
+grep PPid /proc/$PPID/status > ${SESSION_DIR}/sshd.pid
+
 
 X2GO_COOKIE=`mcookie`
 
diff --git a/x2goserver/lib/x2gormforward b/x2goserver/lib/x2gormforward
new file mode 100755
index 0000000..b15e38f
--- /dev/null
+++ b/x2goserver/lib/x2gormforward
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2007-2014 X2Go Project - http://wiki.x2go.org
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Copyright (C) 2007-2014 Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
+# Copyright (C) 2007-2014 Heinz-Markus Graesing <heinz-m.graesing at obviously-nice.de>
+
+use strict;
+use Sys::Syslog qw( :standard :macros );
+
+use X2Go::Log qw(loglevel);
+
+openlog($0,'cons,pid','user');
+setlogmask( LOG_UPTO(loglevel()) );
+
+my $session=shift or die;
+
+my $pidfile="/tmp/.x2go-".getpwuid($>)."/C-$session/sshd.pid";
+if( ! -e $pidfile)
+{
+	#pid file not exists, forwarding already removed
+	exit 0;
+}
+
+open(F,"<$pidfile");
+my $output=<F>;
+close(F);
+
+unlink($pidfile);
+
+my @words=split(" ",$output);
+my $process=@words[@words-1];
+
+$output=`ps ax|grep $process`;
+
+if($output =~ m/sshd/)
+{
+	#terminate process
+	syslog('debug', "Terminating SSHD process: $process");
+	kill 'TERM', $process;
+}
+
+# closing syslog
+closelog;
diff --git a/x2goserver/sbin/x2gocleansessions b/x2goserver/sbin/x2gocleansessions
index 0171cc0..db95e82 100755
--- a/x2goserver/sbin/x2gocleansessions
+++ b/x2goserver/sbin/x2gocleansessions
@@ -188,6 +188,8 @@ elsif ($pid == 0 )
 						syslog('debug', "@sinfo[1] is suspended, changing status from @sinfo[4] to S");
 						syslog('debug', "@sinfo[1]: unmounting all shares");
 						system("su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
+						#remove port forwarding
+						system("su", "@sinfo[11]", "-c", "$x2go_lib_path/x2gormforward @sinfo[1]");
 					}
 				}
 				if (@sinfo[4] eq 'S')

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


More information about the x2go-commits mailing list