[X2Go-Commits] x2goserver.git - master (branch) updated: 3.1.1.3-323-g5c939ac

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


The branch, master has been updated
       via  5c939ac5aabf296c32adc33326335f1f6b7cc556 (commit)
      from  a550eb7a5dc58acee577343c6d6031d394b79f3b (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 5c939ac5aabf296c32adc33326335f1f6b7cc556
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Mon Dec 30 00:30:58 2013 +0100

    Start working on an abstraction layer (as Perl package X2Go::Server::Agent) that handles all (NX) agent specific actions. Move duplicate code into that new Perl package.

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

Summary of changes:
 X2Go/{Config.pm => Server/Agent.pm}                |   45 ++++-----
 .../Server/Agent/NX.pm                             |   99 +++++++++-----------
 X2Go/Utils.pm                                      |   23 ++++-
 debian/changelog                                   |    3 +
 debian/libx2go-server-perl.install                 |    4 +
 x2goserver.spec                                    |    3 +
 x2goserver/bin/x2golistsessions                    |   22 +----
 x2goserver/bin/x2golistshadowsessions              |   22 +----
 x2goserver/sbin/x2gocleansessions                  |   64 +++----------
 x2goserver/sbin/x2golistsessions_root              |   27 +-----
 10 files changed, 121 insertions(+), 191 deletions(-)
 copy X2Go/{Config.pm => Server/Agent.pm} (58%)
 copy x2goserver/bin/x2golistshadowsessions => X2Go/Server/Agent/NX.pm (57%)
 mode change 100755 => 100644

The diff of changes is:
diff --git a/X2Go/Config.pm b/X2Go/Server/Agent.pm
similarity index 58%
copy from X2Go/Config.pm
copy to X2Go/Server/Agent.pm
index d058753..8e9b00f 100644
--- a/X2Go/Config.pm
+++ b/X2Go/Server/Agent.pm
@@ -1,5 +1,3 @@
-#!/usr/bin/perl
-
 # Copyright (C) 2007-2013 X2Go Project - http://wiki.x2go.org
 #
 # This program is free software; you can redistribute it and/or modify
@@ -20,41 +18,46 @@
 # Copyright (C) 2007-2013  Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
 # Copyright (C) 2007-2013  Heinz-Markus Graesing <heinz-m.graesing at obviously-nice.de>
 
-package X2Go::Config;
+package X2Go::Server::Agent;
 
 =head1 NAME
 
-X2Go::Config - X2Go Config package for Perl
+X2Go::Server::Agent - X2Go Server Agent package for Perl
 
 =head1 DESCRIPTION
 
-X2Go::Config Perl package for X2Go components.
+X2Go::Server::Agent Perl package for X2Go::Server.
 
 =cut
 
 use strict;
-use Config::Simple;
+use X2Go::Utils qw( load_module );
+
+# TODO: when other agents may come into play, the AGENT var has to be read from config file or
+# somehow else...
+my $DEFAULT_AGENT="NX";
+my $AGENT=$DEFAULT_AGENT;
+my $agent_module = "X2Go::Server::Agent::$AGENT";
+load_module $agent_module;
 
 use base 'Exporter';
-our @EXPORT = ( 'get_config', 'get_sqlconfig', );
 
-my $Config;
-my $SqlConfig;
+our @EXPORT=( 'session_has_terminated', 'session_is_running', 'session_is_suspended' );
+
+
 
-sub get_config {
-	if (! defined $Config) {
-		$Config = new Config::Simple(syntax=>'ini');
-		$Config->read('/etc/x2go/x2goserver.conf' );
-	}
-	return $Config;
+sub session_has_terminated {
+	return $agent_module->session_has_terminated(@_);
 }
 
-sub get_sqlconfig {
-	if (! defined $SqlConfig) {
-		$SqlConfig = new Config::Simple(syntax=>'ini');
-		$SqlConfig->read('/etc/x2go/x2gosql/sql' );
-	}
-	return $SqlConfig;
+
+sub session_is_running {
+	return $agent_module->session_is_running(@_);
+}
+
+
+sub session_is_suspended {
+	return $agent_module->session_is_suspended(@_);
 }
 
 1;
diff --git a/x2goserver/bin/x2golistshadowsessions b/X2Go/Server/Agent/NX.pm
old mode 100755
new mode 100644
similarity index 57%
copy from x2goserver/bin/x2golistshadowsessions
copy to X2Go/Server/Agent/NX.pm
index 163dcbc..3bdf7bf
--- a/x2goserver/bin/x2golistshadowsessions
+++ b/X2Go/Server/Agent/NX.pm
@@ -1,5 +1,3 @@
-#!/usr/bin/perl
-
 # Copyright (C) 2007-2013 X2Go Project - http://wiki.x2go.org
 #
 # This program is free software; you can redistribute it and/or modify
@@ -20,38 +18,41 @@
 # Copyright (C) 2007-2013  Oleksandr Shneyder <oleksandr.shneyder at obviously-nice.de>
 # Copyright (C) 2007-2013  Heinz-Markus Graesing <heinz-m.graesing at obviously-nice.de>
 
+package X2Go::Server::Agent;
+
+=head1 NAME
+
+X2Go::Server::Agent - X2Go Server Agent package for Perl
+
+=head1 DESCRIPTION
+
+X2Go::Server::Agent Perl package for X2Go::Server.
+
+=cut
+
 use strict;
-use Sys::Hostname;
+use DBI;
+use POSIX;
 use Sys::Syslog qw( :standard :macros );
 
-use File::ReadBackwards;
+use X2Go::Log qw( loglevel );
 
-use X2Go::Server::DB qw(db_listshadowsessions db_listshadowsessions_all);
-use X2Go::Log qw(loglevel);
-
-openlog($0,'cons,pid','user');
 setlogmask( LOG_UPTO(loglevel()) );
 
-if ( @ARGV ) {
-	syslog('info', "x2golistshadowsessions has been called with options: @ARGV");
-} else {
-	# hiding normal x2golistshadowsessions calls into debug loglevel
-	syslog('debug', "x2golistshadowsessions has been called with no option");
-}
 
-
-sub is_suspended
+sub session_has_terminated
 {
         my $sess=shift;
-        my $log="$ENV{'HOME'}/.x2go/C-${sess}.log";
+        my $user=shift;
+        my $log="/tmp/.x2go-${user}/session-C-${sess}.log";
         my $log_line;
-        my $log_file = File::ReadBackwards->new( $log ) or return 0;
+        my $log_file = File::ReadBackwards->new( $log ) or return 1;
         while( defined( $log_line = $log_file->readline ) ) {
                 next if ( ! ( $log_line =~ m/^Session:/ ) );
                 last;
         }
         $log_file->close();
-        if ($log_line =~ m/Session suspended/)
+        if ($log_line =~ m/Session terminated/)
         {
                 return 1;
         }
@@ -59,45 +60,35 @@ sub is_suspended
 }
 
 
-my $serv=shift;
-if( ! $serv)
+sub session_is_suspended
 {
-	$serv=hostname;
+        my $sess=shift;
+        my $user=shift;
+        my $log="/tmp/.x2go-${user}/session-C-${sess}.log";
+        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 1;
+        }
+        return 0;
 }
 
-my @outp;
-if($serv eq "--all-servers")
-{
-	@outp=db_listshadowsessions_all();
-}
-else
-{
-	@outp=db_listshadowsessions($serv);
-}
 
-for (my $i=0;$i<@outp;$i++)
+sub session_is_running
 {
-	@outp[$i] =~ s/ //g;
-	@outp[$i] =~ s/\*/ /g;
-	my @sinfo=split('\\|',"@outp[$i]");
-	if (@sinfo[4]eq 'F')
-	{
-		print "@outp[$i]\n";
-	}
-	else
-	{ 
-		if (@sinfo[4]eq 'R')
-		{
-			if(is_suspended(@sinfo[1]))
-			{
-				db_changestatus( 'S', @sinfo[1] );
-				@outp[$i] =~ s/\|R\|/\|S\|/;
-				system( "x2goumount-session","@sinfo[1]");
-			}
-		}
-		print "@outp[$i]\n";
-	}
+        my $sess=shift;
+        my $user=shift;
+        if (!session_is_suspended($sess, $user) && !session_has_terminated($sess, $user))
+        {
+                return 1;
+        }
+        return 0;
 }
 
-# closing syslog 
-closelog;
+1;
\ No newline at end of file
diff --git a/X2Go/Utils.pm b/X2Go/Utils.pm
index 355d3d4..923d449 100644
--- a/X2Go/Utils.pm
+++ b/X2Go/Utils.pm
@@ -37,7 +37,21 @@ X2Go::Utils Perl package.
 use strict;
 use base 'Exporter';
 
-our @EXPORT = ('source_environment', 'clups', 'sanitizer', );
+our @EXPORT = ( 'source_environment', 'clups', 'sanitizer',
+                'load_module',
+                'system_capture_merged_output', 'system_capture_stdout_output' );
+
+use Sys::Syslog qw( :standard :macros );
+use Capture::Tiny qw ( :all );
+
+sub load_module {
+	for (@_) {
+		(my $file = "$_.pm") =~ s{::}{/}g;
+		require $file;
+		import $_;
+	}
+}
+
 
 sub source_environment {
 	my $name = shift;
@@ -60,6 +74,7 @@ sub source_environment {
 	}
 }
 
+
 # Over-zealous string sanitizer that makes perl strict and  perl -T happy...
 sub sanitizer {
 	my $type   = $_[0];
@@ -96,6 +111,7 @@ sub sanitizer {
 	}
 }
 
+
 sub clups {
 	my $string = "@_";
 	$string =~ s/\n//g;
@@ -104,17 +120,20 @@ sub clups {
 	return $string;
 }
 
+
 sub system_capture_stdout_output {
 	my $cmd = shift;
 	my @args = @_;
+	syslog("debug", "executing external command ,,$cmd'' with args: ".join(",", @args));
 	return capture_stdout { system( $cmd, @args ); };
 }
 
+
 sub system_capture_merged_output {
 	my $cmd = shift;
 	my @args = @_;
+	syslog("debug", "executing external command ,,$cmd'' with args: ".join(",", @args));
 	return capture_merged { system( $cmd, @args ); };
 }
 
-
 1;
diff --git a/debian/changelog b/debian/changelog
index 979576c..16b9851 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -39,6 +39,9 @@ x2goserver (4.1.0.0-0x2go1) UNRELEASED; urgency=low
       calls.
     - Avoid one argument system calls and backticks in SupeReNicer.
     - Handle situations in SupeReNicer where the agent PID is not set.
+    - Start working on an abstraction layer (as Perl
+      package X2Go::Server::Agent) that handles all (NX) agent specific actions.
+      Move duplicate code into that new Perl package.
   * debian/control:
     + Package X2Go::Log in separate package: libx2go-log-perl.
     + Package X2Go::Server::DB in separate package: libx2go-server-db-perl.
diff --git a/debian/libx2go-server-perl.install b/debian/libx2go-server-perl.install
index 1ff3e8d..2ba83aa 100644
--- a/debian/libx2go-server-perl.install
+++ b/debian/libx2go-server-perl.install
@@ -2,7 +2,11 @@ usr/share/perl5/X2Go/Config.pm
 usr/share/perl5/X2Go/Server.pm
 usr/share/perl5/X2Go/SupeReNicer.pm
 usr/share/perl5/X2Go/Utils.pm
+usr/share/perl5/X2Go/Server/Agent*
+usr/share/perl5/X2Go/Utils.pm
 usr/share/man/man3/X2Go::Config.*
 usr/share/man/man3/X2Go::Server.*
 usr/share/man/man3/X2Go::SupeReNicer.*
 usr/share/man/man3/X2Go::Utils.*
+usr/share/man/man3/X2Go::Server::Agent.*
+usr/share/man/man3/X2Go::Server::Agent::*
diff --git a/x2goserver.spec b/x2goserver.spec
index 59edf21..5875999 100644
--- a/x2goserver.spec
+++ b/x2goserver.spec
@@ -416,10 +416,13 @@ exit 0
 %{perl_vendorlib}/X2Go/Server.pm
 %{perl_vendorlib}/X2Go/SupeReNicer.pm
 %{perl_vendorlib}/X2Go/Utils.pm
+%{perl_vendorlib}/X2Go/Server/Agent*
 %{_mandir}/man3/X2Go::Config.*
 %{_mandir}/man3/X2Go::Server.*
 %{_mandir}/man3/X2Go::SupeReNicer.*
 %{_mandir}/man3/X2Go::Utils.*
+%{_mandir}/man3/X2Go::Agent.*
+%{_mandir}/man3/X2Go::Agent::*
 
 
 %files -n perl-X2Go-Server-DB
diff --git a/x2goserver/bin/x2golistsessions b/x2goserver/bin/x2golistsessions
index 2a9e548..6f44f56 100755
--- a/x2goserver/bin/x2golistsessions
+++ b/x2goserver/bin/x2golistsessions
@@ -27,6 +27,7 @@ use Sys::Syslog qw( :standard :macros );
 use File::ReadBackwards;
 
 use X2Go::Server::DB qw(db_listsessions db_listsessions_all db_changestatus);
+use X2Go::Server::Agent qw(session_is_suspended);
 use X2Go::Log qw(loglevel);
 
 openlog($0,'cons,pid','user');
@@ -40,25 +41,6 @@ if ( @ARGV ) {
 }
 
 
-sub is_suspended
-{
-	my $sess=shift;
-	my $log="$ENV{'HOME'}/.x2go/C-${sess}.log";
-	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 1;
-	}
-	return 0;
-}
-
-
 my $serv=shift;
 if( ! $serv)
 {
@@ -88,7 +70,7 @@ for (my $i=0;$i<@outp;$i++)
 	{ 
 		if (@sinfo[4]eq 'R')
 		{
-			if(is_suspended(@sinfo[1]))
+			if(session_is_suspended(@sinfo[1]), @sinfo[11])
 			{
 				db_changestatus( 'S', @sinfo[1] );
 				@outp[$i] =~ s/\|R\|/\|S\|/;
diff --git a/x2goserver/bin/x2golistshadowsessions b/x2goserver/bin/x2golistshadowsessions
index 163dcbc..7880d53 100755
--- a/x2goserver/bin/x2golistshadowsessions
+++ b/x2goserver/bin/x2golistshadowsessions
@@ -27,6 +27,7 @@ use Sys::Syslog qw( :standard :macros );
 use File::ReadBackwards;
 
 use X2Go::Server::DB qw(db_listshadowsessions db_listshadowsessions_all);
+use X2Go::Server::Agent qw(session_is_suspended);
 use X2Go::Log qw(loglevel);
 
 openlog($0,'cons,pid','user');
@@ -40,25 +41,6 @@ if ( @ARGV ) {
 }
 
 
-sub is_suspended
-{
-        my $sess=shift;
-        my $log="$ENV{'HOME'}/.x2go/C-${sess}.log";
-        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 1;
-        }
-        return 0;
-}
-
-
 my $serv=shift;
 if( ! $serv)
 {
@@ -88,7 +70,7 @@ for (my $i=0;$i<@outp;$i++)
 	{ 
 		if (@sinfo[4]eq 'R')
 		{
-			if(is_suspended(@sinfo[1]))
+			if(session_is_suspended(@sinfo[1]), @sinfo[11])
 			{
 				db_changestatus( 'S', @sinfo[1] );
 				@outp[$i] =~ s/\|R\|/\|S\|/;
diff --git a/x2goserver/sbin/x2gocleansessions b/x2goserver/sbin/x2gocleansessions
index 8daffcd..797c5cd 100755
--- a/x2goserver/sbin/x2gocleansessions
+++ b/x2goserver/sbin/x2gocleansessions
@@ -33,6 +33,8 @@ my $x2go_lib_path = `x2gopath libexec`;
 use X2Go::Config qw( get_config );
 use X2Go::Log qw( loglevel );
 use X2Go::SupeReNicer qw( superenice );
+use X2Go::Server::Agent qw( session_is_suspended session_is_running session_has_terminated );
+use X2Go::Server::DB qw( dbsys_rmsessionsroot );
 
 openlog($0,'cons,pid','user');
 setlogmask( LOG_UPTO(loglevel()) );
@@ -56,55 +58,6 @@ sub check_pid
 	return 0;
 }
 
-sub has_terminated
-{
-	my $sess=shift;
-	my $user=shift;
-	my $log="/tmp/.x2go-${user}/session-C-${sess}.log";
-	my $log_line;
-	my $log_file = File::ReadBackwards->new( $log ) or return 1;
-	while( defined( $log_line = $log_file->readline ) ) {
-		next if ( ! ( $log_line =~ m/^Session:/ ) );
-		last;
-	}
-	$log_file->close();
-	if ($log_line =~ m/Session terminated/)
-	{
-		return 1;
-	}
-	return 0;
-}
-
-sub is_suspended
-{
-	my $sess=shift;
-	my $user=shift;
-	my $log="/tmp/.x2go-${user}/session-C-${sess}.log";
-	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 1;
-	}
-	return 0;
-}
-
-sub is_running
-{
-	my $sess=shift;
-	my $user=shift;
-	if (!is_suspended($sess, $user) && !has_terminated($sess, $user))
-	{
-		return 1;
-	}
-	return 0;
-}
-
 sub catch_term
 {
 	unlink("/var/run/x2goserver.pid");
@@ -180,6 +133,13 @@ elsif ($pid == 0 )
 
 			my @sinfo=split('\\|',"@outp[$i]");
 
+			# clean up invalid sessions from the session
+			if ( ( ! @sinfo[0] ) && ( $remembered_sessions_since{ @sinfo[1] } ge 10 ) )
+			{
+				dbsys_rmsessionsroot(@sinfo[1]);
+				next;
+			}
+
 			if (defined $remembered_sessions_since{ @sinfo[1] } && ($remembered_sessions_status{ @sinfo[1] } =~m/@sinfo[4]/ ))
 			{
 				$remembered_sessions_since{ @sinfo[1] } += 2;
@@ -215,7 +175,7 @@ elsif ($pid == 0 )
 			{
 				if ( (@sinfo[4] eq 'R') && ( $remembered_sessions_since{ @sinfo[1] } ge 2 ))
 				{
-					if (is_suspended(@sinfo[1], at sinfo[11]))
+					if (session_is_suspended(@sinfo[1], at sinfo[11]))
 					{
 						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");
@@ -225,7 +185,7 @@ elsif ($pid == 0 )
 				}
 				if (@sinfo[4] eq 'S')
 				{
-					if (is_running(@sinfo[1], at sinfo[11]))
+					if (session_is_running(@sinfo[1], at sinfo[11]))
 					{
 						syslog('debug', "@sinfo[1]: unmounting all shares");
 						system("su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
@@ -235,7 +195,7 @@ elsif ($pid == 0 )
 				}
 				if (@sinfo[4] eq 'T')
 				{
-					if (!has_terminated(@sinfo[1], at sinfo[11]))
+					if (!session_has_terminated(@sinfo[1], at sinfo[11]))
 					{
 						syslog('debug', "@sinfo[1]: unmounting all shares");
 						system("su", "@sinfo[11]", "-c", "export HOSTNAME && x2goumount-session @sinfo[1]");
diff --git a/x2goserver/sbin/x2golistsessions_root b/x2goserver/sbin/x2golistsessions_root
index 3ae90e2..b4c659c 100755
--- a/x2goserver/sbin/x2golistsessions_root
+++ b/x2goserver/sbin/x2golistsessions_root
@@ -26,30 +26,13 @@ use Sys::Syslog qw( :standard :macros );
 use File::ReadBackwards;
 
 use X2Go::Log qw(loglevel);
+use X2Go::Utils qw(system_capture_stdout_output);
+use X2Go::Server::Agent qw(session_is_suspended);
 
 openlog($0,'cons,pid','user');
 setlogmask( LOG_UPTO(loglevel()) );
 
-sub is_suspended
-{
-	my $sess=shift;
-	my $user=shift;
-	my $log="/tmp/.x2go-${user}/session-C-${sess}.log";
-	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 1;
-	}
-	return 0;
-}
-
-my $x2go_lib_path = `x2gopath libexec`;
+my $x2go_lib_path = system_capture_stdout_output("x2gopath", "libexec");
 
 my $uname;
 
@@ -59,7 +42,7 @@ if ( ! $serv)
 	$serv=hostname;
 }
 
-my $outp=`$x2go_lib_path/x2golistsessions_sql $serv 2>/dev/null`;
+my $outp=system_capture_stdout_output("$x2go_lib_path/x2golistsessions_sql","$serv");
 
 my @outp=split("\n","$outp");
 
@@ -74,7 +57,7 @@ for (my $i=0;$i<@outp;$i++)
 	{ 
 		if (@sinfo[4]eq 'R')
 		{
-			if (is_suspended(@sinfo[1], at sinfo[11]))
+			if (session_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