I wrote a small patch to vncserver (tested on Slackware 8 and RedHat 7.2) to
allow no more then 2 sessions per users based on the existence of
~/.vnc/$host:*.pid its a really small patch that anyone could have written
but I figured someone else out there might find it useful. I wrote it
because we have hundreds of users that would start multiple sessions on our
X App servers hammering them to the ground. ... anyway I hope at least
someone out there likes it ... use at your own risk I can not make any
guarantees as what it may or may not do to your system :)

----------------------------- cut -------------------------------------
--- /usr/bin/vncserver  Tue Jul 24 03:28:26 2001
+++ vncserver   Thu Dec 13 11:27:35 2001
@@ -101,6 +101,84 @@
     }
 }
 
+# Check to see if the user already has a desktop
+$limit = "2";
+
+use File::Basename;
+@list = <$vncUserDir/$host:*.pid>;
+
+sub vnckill {
+    foreach $desk (@list) {
+       ($name,$dir,$ext) = fileparse($desk,'\..*');
+       @disp = ":" . (split /:/, $name)[1];
+       foreach $display (@disp) {
+           print "Are you sure you want to close $name? [yes/no]: ";
+           chomp($confirm = <STDIN>);
+
+           if ($confirm =~ /yes/i) {
+               print "executing: vncserver -kill \:$nume\n";
+               system ('vncserver', '-kill', $display);
+           } elsif ($confirm =~ /no/i) {
+               print "Please remember to close your session(s) when
finished.\n";
+           } else {
+               while (($confirm !~ /yes/i) && ($confirm !~ /no/i)) {
+                   print "Confirm close $name? type [yes/no]: ";
+                   chomp($confirm = <STDIN>);
+                   if ($confirm =~ /yes/i) {
+                       $kill = 1;
+                       print "executing: vncserver -kill $display\n";
+                       system ('vncserver', '-kill', $display);
+                   } elsif ($confirm =~ /no/i) {
+                       print "Please remember to close your session(s) when
finished.\n";
+                   }
+               }
+           }
+       }
+    }
+}
+
+$nume = $#list + 1;
+
+if (@list) {
+    print "$ENV{USER} currently has $nume desktop(s) running at:\n\n";
+    foreach $desk (@list) {
+       ($name,$dir,$ext) = fileparse($desk,'\..*');
+       print "\t$name\n";
+    }
+
+    if ($nume >= $limit) {
+       print "\nYou're maxed out on desktops; Connect to one of the above
sessions or, \n";
+       print "please close unnecessary desktops (e.g., vncserver -kill
\:$nume)\n";
+       print "\nKill all and start a new desktop? [y/N]: ";
+       chomp($ans = <STDIN>);
+       if ($ans =~ /y/i) {
+           vnckill();
+           if ($kill != "1") {
+               exit 0;
+           }
+       } elsif ($ans =~ /n/i) {
+           print "Please remember to close your session(s) when
finished.\n";
+           exit 0;
+       } else {
+           print "exiting\n";
+           exit 1;
+       }
+    } else {
+       print "\nPlease connect to an existing desktop or kill the
desktop(s); \n";
+       print "(e.g., vncserver -kill \:$nume)\n";
+       print "\n[K]ill all and start new, or [S]tart new desktop anyway?:
[k/s]: ";
+       chomp($ans = <STDIN>);
+       if ($ans =~ /k/i) {
+           vnckill();
+       } elsif ($ans =~ /s/i) { 
+           print "Please remember to close your session(s) when
finished.\n";
+       } else {
+           print "exiting\n";
+           exit 1;
+       }
+    }
+}
+
 # Find display number.
 
 if ((@ARGV > 0) && ($ARGV[0] =~ /^:(\d+)$/)) {
----------------------------------- cut
----------------------------------------

=================================
 John Celoria
 Unix Administrator
 Rogue Wave Software; http://www.roguewave.com
=================================
---------------------------------------------------------------------
To unsubscribe, mail [EMAIL PROTECTED] with the line:
'unsubscribe vnc-list' in the message BODY
See also: http://www.uk.research.att.com/vnc/intouch.html
---------------------------------------------------------------------

Reply via email to