[FreeNX-kNX] When suspending a session, why are the /var/lib/nxserver/db/running/sessionId{} files sometimes not written properly (0 byted) ?
Sabuj Pattanayek
sabujp at gmail.com
Thu Mar 22 23:48:52 UTC 2012
Hi all,
I noticed that sometimes after suspending a session, or perhaps if the
client is just closed on the other end (e.g. logout, client crash,
client reboot, etc), the /var/lib/nxserver/db/running/sessionId{} file
for that session on the nx server sometimes is not written properly (0
byted). Anyone know why this happens or if there's a fix? For now I've
written this perl script which will re-generate the sessionId file for
you :
#!/usr/bin/perl
# Author : Sabuj Pattanayek (sabujp at gmail.com)
# Purpose : Recovers a running NX session file that has been 0 byted.
Basically this is caused by some bug in freenx that sometimes fails to
properly write the session save file when it's suspended so that the
user can resume a session.
# Date : 20120322
use Cwd;
#%sessionIdsH = map { $_ => "" } `ps aux | grep -v ' grep ' | grep -i
$ENV{USER} | grep nxagent | awk -F' ' '{print \$23}' | awk -F'-'
'{print \$4}' | awk -F'/' '{print \$1}'`;
@sessionProcs = `ps aux | grep -v ' grep ' | grep $ENV{USER} | grep nxagent`;
foreach $sessionProc (@sessionProcs) {
chomp($sessionProc);
(@procItems) = split(/\s+/, $sessionProc);
# session name
$sessionName = $procItems[18];
# options file
$optionsFile = $procItems[22];
# session start
if ($optionsFile =~ /(.+?)\/options/) {
$statsFile = $1."/stats";
}
$startTime = (stat $statsFile)[10];
$humanStartTime = scalar localtime($startTime);
# sessionId and port
if ($optionsFile =~ /C-.+?-(\d+)-(.+?)\/options/) {
$port = $1;
$sessionId = $2;
}
# grab these from the option file
$optionLine = `cat $optionsFile`;
if ($optionLine =~ /geometry=(.+?),/) {
$geometry = $1;
$screenInfo = $geometry."x32+render";
}
else {
die "Something is wrong with the options file : $optionsFile , it
may not be possible to recover this session\n";
}
# shadow cookie
if ($optionLine =~ /cookie=(.+?),/) {
$cookie = $1;
}
# session type (unix-$something, e.g. unix-kde, unix-gnome)
if ($optionLine =~ /type=(.+?),/) {
$sessionType = "unix-".$1;
}
#print "ID: $sessionId Session Name: $sessionName Display: $port
Start Time: $humanStartTime\n";
$sessionsH{$sessionId} = [$sessionName, $startTime, $humanStartTime,
$port, $geometry, $screenInfo, $cookie, $sessionType];
}
if ($ARGV[0] eq "") {
print "Specify an NX sessionId that you want to recover.\n";
print "These are the running sessions you have:\n";
foreach $sessionId (keys(%sessionsH)) {
print "sessionId: $sessionId sessionType:
${$sessionsH{$sessionId}}[7] startTime: ${$sessionsH{$sessionId}}[2].
To recover this session run \"recovernx $sessionId\"\n";
}
exit(-1);
}
$recoverId = $ARGV[0];
if (defined($sessionsH{$recoverId})) {
die "Couldn't create session file: $!\n" unless open($outFile,
">sessionId\{$recoverId\}");
print $outFile "sessionName=".${$sessionsH{$recoverId}}[0]."\n";
print $outFile "display=".${$sessionsH{$recoverId}}[3]."\n";
print $outFile "status=Suspended\n";
print $outFile "startTime=".${$sessionsH{$recoverId}}[1]."\n";
print $outFile "foreignAddress=-\n";
print $outFile "sessionRootlessMode=0\n";
print $outFile "type=".${$sessionsH{$recoverId}}[7]."\n";
print $outFile "sessionId=$recoverId\n";
print $outFile "creationTime=".${$sessionsH{$recoverId}}[1]."\n";
print $outFile "userName=$ENV{USER}\n";
print $outFile "serverPid=\n";
print $outFile "screeninfo=".${$sessionsH{$recoverId}}[5]."\n";
print $outFile "geometry=".${$sessionsH{$recoverId}}[4]."\n";
print $outFile "host=127.0.0.1\n";
print $outFile "shadowcookie=".${$sessionsH{$recoverId}}[6]."\n";
close($outFile);
$pwd = cwd;
print "Please tell the admin to put the file
$ENV{HOSTNAME}:$pwd/\sessionId\{$recoverId\} into the
$ENV{HOSTNAME}:/var/lib/nxserver/db/running directory\n";
}
else {
die "You gave an incorrect sessionId, or a sessionId that doesn't
belong to your user account. If you're running this as root, run it as
the user who needs to recover the NX session instead\n";
}
More information about the FreeNX-kNX
mailing list