[X2Go-Commits] x2goserver.git - release/4.0.0.x (branch) updated: 4.0.0.7-5-g80ff699

X2Go dev team git-admin at x2go.org
Fri Jan 3 18:00:37 CET 2014


The branch, release/4.0.0.x has been updated
       via  80ff6997550749a64dd5db5684acbd47a4127ab3 (commit)
      from  08a2780f1448da0fd00e68f11177b1ca1672da04 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 80ff6997550749a64dd5db5684acbd47a4127ab3
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Sat Dec 28 22:34:42 2013 +0100

    Avoid one argument system calls and backticks in x2gocleansessions and x2golistsessions_root.
    
    Conflicts (resolved by Mike Gabriel):
    	debian/control
    	x2goserver/sbin/x2gocleansessions

-----------------------------------------------------------------------

Summary of changes:
 debian/changelog                      |    2 ++
 debian/control                        |    1 +
 x2goserver/sbin/x2gocleansessions     |   29 ++++++++++++++++++-----------
 x2goserver/sbin/x2golistsessions_root |   20 ++++++++++++++------
 4 files changed, 35 insertions(+), 17 deletions(-)

The diff of changes is:
diff --git a/debian/changelog b/debian/changelog
index 932b33c..c48b5c1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -7,6 +7,8 @@ x2goserver (4.0.0.8-0x2go1) UNRELEASED; urgency=low
     - Improve parsing of the NX session.log file where unexpected extra logging
       takes place during session suspension/resumption. Thanks to Gerald Richter
       for finding this!!! (Fixes: #356).
+    - Avoid one argument system calls and backticks in x2gocleansessions and
+      x2golistsessions_root.
 
  -- Mike Gabriel <mike.gabriel at das-netzwerkteam.de>  Thu, 28 Nov 2013 16:14:32 +0100
 
diff --git a/debian/control b/debian/control
index 30b1c82..8765c11 100644
--- a/debian/control
+++ b/debian/control
@@ -28,6 +28,7 @@ Depends:
  libdbd-pg-perl,
  libdbd-sqlite3-perl,
  libfile-basedir-perl,
+ libfile-readbackwards-perl,
  adduser,
  xauth,
  psmisc,
diff --git a/x2goserver/sbin/x2gocleansessions b/x2goserver/sbin/x2gocleansessions
index b935a98..21059fb 100755
--- a/x2goserver/sbin/x2gocleansessions
+++ b/x2goserver/sbin/x2gocleansessions
@@ -23,6 +23,7 @@
 use strict;
 use Sys::Hostname;
 use Sys::Syslog qw( :standard :macros );
+use File::ReadBackwards;
 
 my $x2go_lib_path=`x2gopath libexec`;
 use lib `x2gopath lib`;
@@ -51,17 +52,23 @@ sub check_pid
 	return 0;
 }
 
-sub check_stat
+sub is_suspended
 {
 	my $sess=shift;
 	my $user=shift;
 	my $log="/tmp/.x2go-${user}/session-C-${sess}.log";
-	my $text=`grep Session: $log 2>/dev/null|tail -1`;
-	if ($text =~ m/Session suspended/)
+	my $log_line;
+	my $log_file = File::ReadBackwards->new( $log ) or return 0;
+	while( defined( $log_line = $log_file->readline ) ) {
+		next if ( ! ( $log_line =~ m/^Session:/ ) );
+		last;
+	}
+	$log_file->close();
+	if ($log_line =~ m/Session suspended/)
 	{
-		return 0;
+		return 1;
 	}
-	return 1;
+	return 0;
 }
 
 sub catch_term
@@ -103,25 +110,25 @@ elsif ($pid == 0 )
 			{
 				syslog('debug', "@sinfo[1] is blocked");
 				syslog('debug', "@sinfo[1]: unmounting all shares");
-				system( "su @sinfo[11] -c \"export HOSTNAME && x2goumount-session @sinfo[1]\" 2> /dev/null");
+				system( "su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
 			}
 			elsif (! check_pid (@sinfo[0], at sinfo[1], at sinfo[12]))
 			{
-				system("su @sinfo[11] -c \"$x2go_lib_path/x2gochangestatus 'F' @sinfo[1] \" > /dev/null");
+				system("su", "@sinfo[11]", "-c", "$x2go_lib_path/x2gochangestatus 'F' @sinfo[1]");
 				syslog('debug', "@sinfo[1], pid @sinfo[0] does not exist, changing status from @sinfo[4] to F");
 				syslog('debug', "@sinfo[1]: unmounting all shares");
-				system( "su @sinfo[11] -c \"export HOSTNAME && x2goumount-session @sinfo[1]\" 2> /dev/null");
+				system("su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
 			}
 			else
 			{ 
 				if (@sinfo[4]eq 'R')
 				{
-					if (!check_stat(@sinfo[1], at sinfo[11]))
+					if (is_suspended(@sinfo[1], at sinfo[11]))
 					{
-						system("su @sinfo[11] -c  \"$x2go_lib_path/x2gochangestatus 'S' @sinfo[1] \" > /dev/null");
+						system("su", "@sinfo[11]", "-c", "$x2go_lib_path/x2gochangestatus S @sinfo[1]");
 						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]\" 2> /dev/null");
+						system("su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
 					}
 				}
 			}
diff --git a/x2goserver/sbin/x2golistsessions_root b/x2goserver/sbin/x2golistsessions_root
index a3b7ea6..56d1781 100755
--- a/x2goserver/sbin/x2golistsessions_root
+++ b/x2goserver/sbin/x2golistsessions_root
@@ -22,25 +22,33 @@
 use strict;
 use Sys::Hostname;
 use Sys::Syslog qw( :standard :macros );
+use File::ReadBackwards;
 
 use lib `x2gopath lib`;
 use x2gologlevel;
 
+
 openlog($0,'cons,pid','user');
 setlogmask( LOG_UPTO(x2gologlevel()) );
 
 
-sub check_stat
+sub is_suspended
 {
 	my $sess=shift;
 	my $user=shift;
 	my $log="/tmp/.x2go-${user}/session-C-${sess}.log";
-	my $text=`tail -1 $log 2>/dev/null`;
-	if ($text =~ m/Session suspended/)
+	my $log_line;
+	my $log_file = File::ReadBackwards->new( $log ) or return 0;
+	while( defined( $log_line = $log_file->readline ) ) {
+		next if ( ! ( $log_line =~ m/^Session:/ ) );
+		last;
+	}
+	$log_file->close();
+	if ($log_line =~ m/Session suspended/)
 	{
-		return 0;
+		return 1;
 	}
-	return 1;
+	return 0;
 }
 
 my $x2go_lib_path = `x2gopath libexec`;
@@ -68,7 +76,7 @@ for (my $i=0;$i<@outp;$i++)
 	{ 
 		if (@sinfo[4]eq 'R')
 		{
-			if (!check_stat(@sinfo[1], at sinfo[11]))
+			if (is_suspended(@sinfo[1], at sinfo[11]))
 			{
 				system("su - @sinfo[11] -c \"$x2go_lib_path/x2gochangestatus 'S' @sinfo[1]\" > /dev/null");
 				@outp[$i] =~ s/\|R\|/\|S\|/;


hooks/post-receive
-- 
x2goserver.git (X2Go Server)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "x2goserver.git" (X2Go Server).




More information about the x2go-commits mailing list