#!/usr/bin/perl # We'd love to run this with -T but Utils.pm and probably DB.pm too need some work before that can happen.. ######################################################################################################################## # # Copyright (C) 2013-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) 2013-2014 Guangzhou Nianguan Electronics Technology Co.Ltd. # ######################################################################################################################### # # Hopefully this solves the issues pretaining to the #302 session resume bug. # If so, we dedicate this bugfix to the Logitech D250 Keyboard who's servicelife came to an abrupt end due to this bug. # ######################################################################################################################### use strict; use Sys::Hostname; use IO::Socket; use X2Go::Utils qw( sanitizer ); use X2Go::Server::DB qw(db_listsessions); my $doRetryCnt = 5; my $X2GoSID = requireX2GOSID_argvenvdie(); my @X2GoSesINFO = getSessionInfo($X2GoSID); if (@X2GoSesINFO[1] eq $X2GoSID) { while ($doRetryCnt > 0) { $doRetryCnt--; if (itsUP($X2GoSesINFO[8])) { exit; } sleep 1; } } ######################################################################################################## # Only SUBS past this point....: (Any Utils.pm candidates?) sub requireX2GOSID_argvenvdie { # Return X2Go SID from either ARGV[0] or ENV.... terminates on failure. # If this ends up moving to Utils.pm, renaming may be a good idea. if (sanitizer("x2gosid",@ARGV[0])) { return sanitizer("x2gosid",@ARGV[0]); } elsif (sanitizer("x2gosid",$ENV{'X2GO_SESSION'})) { return sanitizer("x2gosid",$ENV{'X2GO_SESSION'}); } else { die "No X2Go Session ID in ARGV or ENV!\n"; } } sub itsUP { # Simple sub for checking if the port is up on localhost... # If this ends up moving to Utils.pm, renaming may be a good idea. my $portNum = sanitizer("num",$_[0]) or die "Port number not a number '$_[0]'?"; my $socket = IO::Socket::INET->new( PeerAddr => 'localhost', PeerPort => $portNum, Proto => 'tcp'); if (defined $socket) { print $socket "\n"; $socket->close; return 1; } else { return 0; } } sub getSessionInfo { # Simple sub to get X2GoSessionINFO from the database (kind of like greping it out of "x2golistsessions" without cranking another perl script)... # If this ends up moving to Utils.pm, renaming may be a good idea. my $theX2GoSID = $_[0]; foreach my $sessionLine (db_listsessions(hostname)) { if ($sessionLine =~ /$theX2GoSID/) { return split(/\|/,$sessionLine); } } return 0; }