[X2Go-Commits] [x2goserver] 02/02: 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
Thu Jul 24 06:39:33 CEST 2014
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 513206befc64d1f2618d19d4afe7cfdb9f332f77
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 | 4 +++
x2goserver/bin/x2gostartagent | 3 ++
x2goserver/lib/x2gormforward | 59 +++++++++++++++++++++++++++++++++++++
x2goserver/sbin/x2gocleansessions | 2 ++
6 files changed, 73 insertions(+)
diff --git a/debian/changelog b/debian/changelog
index 72deb4c..b58bcad 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -70,6 +70,8 @@ x2goserver (4.0.1.16-0x2go1) UNRELEASED; urgency=low
- Fix x2gostartagent failures if kbd is not "auto". Remove comma at end of
options file.
- 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 DePaulo <mikedep333 at gmail.com> Thu, 23 Apr 2014 17:49:00 -0500
diff --git a/x2goserver/bin/x2golistsessions b/x2goserver/bin/x2golistsessions
index 93d4c07..efbf8f2 100755
--- a/x2goserver/bin/x2golistsessions
+++ b/x2goserver/bin/x2golistsessions
@@ -31,6 +31,8 @@ use x2godbwrapper;
use x2gologlevel;
+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(x2gologlevel()) );
@@ -123,6 +125,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 c06eea7..d3ee51f 100755
--- a/x2goserver/bin/x2goresume-session
+++ b/x2goserver/bin/x2goresume-session
@@ -89,6 +89,9 @@ 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" ]
then
@@ -255,6 +258,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 7293a0e..f9bd600 100755
--- a/x2goserver/bin/x2gostartagent
+++ b/x2goserver/bin/x2gostartagent
@@ -65,6 +65,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]}'`
@@ -251,6 +252,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 7fc4172..fe39cf8 100755
--- a/x2goserver/sbin/x2gocleansessions
+++ b/x2goserver/sbin/x2gocleansessions
@@ -214,6 +214,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