xl: fork before execing vncviewer
authorIan Campbell <ian.campbell@citrix.com>
Fri, 27 Sep 2013 10:16:22 +0000 (11:16 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Thu, 3 Oct 2013 12:39:53 +0000 (13:39 +0100)
Otherwise we don't daemonize to monitor the domain.

Heavily cargo-culted from autoconnect-console and only compile tested.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Tested-by: Olaf Hering <olaf@aepfle.de>
tools/libxl/xl.h
tools/libxl/xl_cmdimpl.c

index e72a7d21277b7f3ba016fc7940f3646a2988195a..e005c393da07341aeccb78bc276eb2cef82ea2b3 100644 (file)
@@ -128,7 +128,7 @@ typedef struct {
 } xlchild;
 
 typedef enum {
-    child_console, child_waitdaemon, child_migration,
+    child_console, child_waitdaemon, child_migration, child_vncviewer,
     child_max
 } xlchildnum;
 
index 642b130864991c740a2ad31ae15ac76b6b1dcf64..a91b42744c9f762ef2bc14855853503e54071cce 100644 (file)
@@ -194,6 +194,37 @@ static int vncviewer(uint32_t domid, int autopass)
     return 1;
 }
 
+static void vncviewer_child_report(void)
+{
+    if (xl_child_pid(child_vncviewer)) {
+        int status;
+        pid_t got = xl_waitpid(child_vncviewer, &status, 0);
+        if (got < 0)
+            perror("xl: warning, failed to waitpid for vncviewer child");
+        else if (status)
+            libxl_report_child_exitstatus(ctx, XTL_ERROR, "vncviewer child",
+                                          xl_child_pid(child_vncviewer), status);
+    }
+}
+
+static void autoconnect_vncviewer(uint32_t domid, int autopass)
+{
+    vncviewer_child_report();
+
+    pid_t pid = xl_fork(child_vncviewer);
+    if (pid < 0) {
+        perror("unable to fork vncviewer");
+        return;
+    } else if (pid > 0)
+        return;
+
+    postfork();
+
+    sleep(1);
+    vncviewer(domid, autopass);
+    _exit(1);
+}
+
 static int acquire_lock(void)
 {
     int rc;
@@ -2093,7 +2124,7 @@ start:
         goto out;
 
     if (dom_info->vnc)
-        vncviewer(domid, vncautopass);
+        autoconnect_vncviewer(domid, vncautopass);
 
     if (need_daemon) {
         char *fullname, *name;