[patch] option for vncserver to allow more traditional exiting of X

Richard L. Hamilton rlhamil "at" mindwarp.smart.net
Tue, 04 Sep 2001 14:38:52 +0000

The attached patch adds a -wait option to the (Unix) vncserver
script, for those who wish exit from twm, CDE logout, etc. to
cause Xvnc to be terminated (and its client(s), too).  The vncserver
script itself also does not exit until then if the -wait option is used.

For this to work, the $HOME/.vnc/xstartup script _must_ have
as its last line whatever invokes the window manager (or whatever)
that one will exit eventually, _without_ a terminating ampersand ("&").
That is, the command to wait on must not be backgrounded.

If one doesn't already have a $HOME/.vnc/xstartup file, the changes
will also cause the twm line to have (without -wait) or not have (with -wait)
the terminating ampersand put in.  Of course, it could be left off and
it probably wouldn't matter anyway, since (without -wait) the command in
vncserver that invokes $HOME/.vnc/xstartup does so in background.

Since I'm presently using CDE, instead of "twm", my xstartup file ends

test -x /etc/dt/config/Xsetup || /usr/dt/config/Xsetup

which seems to be taking care of everything except the definitions of
the copy/paste keys.  In particular, logging out of CDE causes dtsession
to terminate, which in turn causes the Xsession script to exit, and with
the new -wait option, causes Xvnc to be killed.   Without -wait (or
in the original), the first logout attempt would go to the correct dtsession,
but killing it wouldn't affect the server or the CDE window manager.
Subsequent attempts would (when using the viewer while sitting at a local
CDE desktop) communicate with another instance of dtsession altogether;
presumably if it weren't running, the exit attempt would fail with no
ToolTalk client listening for the corresponding message.

Anyway, anyone else think this -wait option is useful?  AFAIK, without
using it, it doesn't break any kind of compatibility.  And with it,
one can get the sort of behavior that I (and others I stumbled across
searching Usenet prior to finding this mailing list) seem to want.

If it is useful, someone more comfortable with perl than I am might
wish to pretty it up a bit; my concern was with getting the desired
effect with the least amount of changes, not with Good Perl Scripting

ftp> get |fortune
377 I/O error: smart remark generator failed

Bogonics: the primary language inside the Beltway

mailto:rlhamil "at" mindwarp.smart.net  http://www.smart.net/~rlhamil
*** vncserver.orig	Tue Sep  4 08:38:53 2001
--- vncserver	Tue Sep  4 08:40:34 2001
*** 39,51 ****
  $vncUserDir = "$ENV{HOME}/.vnc";
  $xauthorityFile = "$ENV{HOME}/.Xauthority";
- $defaultXStartup
-     = ("#!/bin/sh\n\n".
-        "xrdb \$HOME/.Xresources\n".
-        "xsetroot -solid grey\n".
-        "xterm -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n".
-        "twm &\n");
  chop($host = `uname -n`);
--- 39,44 ----
*** 52,63 ****
  # Check command line options
! 	      "-help",0,"-h",0,"--help",0);
  &Usage() if ($opt{'-help'} || $opt{'-h'} || $opt{'--help'});
  &Kill() if ($opt{'-kill'});
  # Uncomment this line if you want default geometry, depth and pixelformat
  # to match the current X display:
  # &GetXDisplayDefaults();
--- 45,70 ----
  # Check command line options
! 	      "-help",0,"-h",0,"--help",0,"-wait",0);
  &Usage() if ($opt{'-help'} || $opt{'-h'} || $opt{'--help'});
  &Kill() if ($opt{'-kill'});
+ if ($opt{'-wait'}) {
+     $background='';
+ }
+ else {
+     $background='&';
+ }
+ $defaultXStartup
+     = ("#!/bin/sh\n\n".
+        "xrdb \$HOME/.Xresources\n".
+        "xsetroot -solid grey\n".
+        "xterm -geometry 80x24+10+10 -ls -title \"\$VNCDESKTOP Desktop\" &\n".
+        "twm $background\n");
  # Uncomment this line if you want default geometry, depth and pixelformat
  # to match the current X display:
  # &GetXDisplayDefaults();
*** 191,197 ****
  $ENV{VNCDESKTOP}= $desktopName;
! system("$vncUserDir/xstartup >> " . &quotedString($desktopLog) . " 2>&1 &");
--- 198,207 ----
  $ENV{VNCDESKTOP}= $desktopName;
! system("$vncUserDir/xstartup >> " . &quotedString($desktopLog) . " 2>&1 $background");
! if ($opt{'-wait'}) {
!     system("vncserver -kill :$displayNumber");
! }
To unsubscribe, send a message with the line: unsubscribe vnc-list
to majordomo "at" uk.research.att.com
See also: http://www.uk.research.att.com/vnc/intouch.html