Always exit Xvnc whenever the user exits the window manager, and provide a -fg switch to allow Xvnc to run in the foreground (necessary for some grid computing environments)


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4315 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/unix/vncserver b/unix/vncserver
index 41e5603..0fbed19 100755
--- a/unix/vncserver
+++ b/unix/vncserver
@@ -122,7 +122,7 @@
 # Check command line options
 
 &ParseOptions("-geometry",1,"-depth",1,"-pixelformat",1,"-name",1,"-kill",1,
-	      "-help",0,"-h",0,"--help",0,"-fp",1,"-list",0);
+	      "-help",0,"-h",0,"--help",0,"-fp",1,"-list",0,"-fg",0);
 
 &Usage() if ($opt{'-help'} || $opt{'-h'} || $opt{'--help'});
 
@@ -306,7 +306,15 @@
 }
 $ENV{VNCDESKTOP}= $desktopName;
 
-system("$vncUserDir/xstartup >> " . &quotedString($desktopLog) . " 2>&1 &");
+if ($opt{'-fg'}) {
+    system("$vncUserDir/xstartup >> " . &quotedString($desktopLog) . " 2>&1");
+    if (kill 0, `cat $pidFile`) {
+        $opt{'-kill'} = ':'.$displayNumber;
+        &Kill();
+    }
+} else {
+    system("($vncUserDir/xstartup; $0 -kill :$displayNumber) >> " . &quotedString($desktopLog) . " 2>&1 &");
+}
 
 exit;
 
@@ -527,6 +535,7 @@
 	"                 [-geometry <width>x<height>]\n".
 	"                 [-pixelformat rgbNNN|bgrNNN]\n".
 	"                 [-fp <font-path>]\n".
+	"                 [-fg]\n".
 	"                 <Xvnc-options>...\n\n".
 	"       $prog -kill <X-display>\n\n".
 	"       $prog -list\n\n");