xl: Introduce children[].description and xl_report_child_exitstatus
authorIan Jackson <ian.jackson@eu.citrix.com>
Mon, 14 Oct 2013 15:13:19 +0000 (16:13 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Fri, 21 Mar 2014 14:35:52 +0000 (14:35 +0000)
We record the descriptive string for the child in the children[]
array, and use it when reporting the exit status.

The only functional change is that the message reported for the
migration child is changed from "migration target process" to
"migration transport process".

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <Ian.Campbell@citrix.com>
tools/libxl/xl.c
tools/libxl/xl.h
tools/libxl/xl_cmdimpl.c

index 1d157fe48f872950bafdc7967e65b91731e144b4..527b4c596539c48fb8fa2a82210ea293295af09f 100644 (file)
@@ -189,12 +189,13 @@ void postfork(void)
     xl_ctx_alloc();
 }
 
-pid_t xl_fork(xlchildnum child) {
+pid_t xl_fork(xlchildnum child, const char *description) {
     xlchild *ch = &children[child];
     int i;
 
     assert(!ch->pid);
     ch->reaped = 0;
+    ch->description = description;
 
     ch->pid = fork();
     if (ch->pid == -1) {
@@ -238,6 +239,13 @@ int xl_child_pid(xlchildnum child)
     return ch->pid;
 }
 
+void xl_report_child_exitstatus(xentoollog_level level,
+                                xlchildnum child, pid_t pid, int status)
+{
+    libxl_report_child_exitstatus(ctx, level, children[child].description,
+                                  pid, status);
+}
+
 static int xl_reaped_callback(pid_t got, int status, void *user)
 {
     int i;
index 280d39cca0037235b85ca6f1e49545599446dc2e..40a42b31bee692a5864b54023f0e3540935d34ff 100644 (file)
@@ -130,6 +130,7 @@ typedef struct {
     pid_t pid; /* 0: not in use */
     int reaped; /* valid iff pid!=0 */
     int status; /* valid iff reaped */
+    const char *description; /* valid iff pid!=0 */
 } xlchild;
 
 typedef enum {
@@ -139,7 +140,8 @@ typedef enum {
 
 extern xlchild children[child_max];
 
-pid_t xl_fork(xlchildnum); /* like fork, but prints and dies if it fails */
+pid_t xl_fork(xlchildnum, const char *description);
+    /* like fork, but prints and dies if it fails */
 void postfork(void); /* needed only if we aren't going to exec right away */
 
 /* Handles EINTR.  Clears out the xlchild so it can be reused. */
@@ -147,6 +149,10 @@ pid_t xl_waitpid(xlchildnum, int *status, int flags);
 
 int xl_child_pid(xlchildnum); /* returns 0 if child struct is not in use */
 
+void xl_report_child_exitstatus(xentoollog_level level,
+                                xlchildnum child, pid_t pid, int status);
+    /* like libxl_report_child_exitstatus, but uses children[].description */
+
 /* global options */
 extern int autoballoon;
 extern int run_hotplug_scripts;
index e19b1cfc90f7c1f71dd8fa165f2495dae500660c..0c2eca3da23cd89ededdcae42478c1de5f29996a 100644 (file)
@@ -220,8 +220,8 @@ static void vncviewer_child_report(void)
         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);
+            xl_report_child_exitstatus(XTL_ERROR, child_vncviewer,
+                                       got, status);
     }
 }
 
@@ -229,7 +229,7 @@ static void autoconnect_vncviewer(uint32_t domid, int autopass)
 {
     vncviewer_child_report();
 
-    pid_t pid = xl_fork(child_vncviewer);
+    pid_t pid = xl_fork(child_vncviewer, "vncviewer child");
     if (pid)
         return;
 
@@ -435,7 +435,7 @@ static int do_daemonize(char *name)
     int nullfd, ret = 0;
     int status = 0;
 
-    child1 = xl_fork(child_waitdaemon);
+    child1 = xl_fork(child_waitdaemon, "domain monitoring daemon");
     if (child1) {
         got_child = xl_waitpid(child_waitdaemon, &status, 0);
         if (got_child != child1) {
@@ -1991,8 +1991,8 @@ static void console_child_report(void)
         if (got < 0)
             perror("xl: warning, failed to waitpid for console child");
         else if (status)
-            libxl_report_child_exitstatus(ctx, XTL_ERROR, "console child",
-                                          xl_child_pid(child_console), status);
+            xl_report_child_exitstatus(XTL_ERROR, child_console,
+                                       got, status);
     }
 }
 
@@ -2005,7 +2005,7 @@ static void autoconnect_console(libxl_ctx *ctx_ignored,
 
     console_child_report();
 
-    pid_t pid = xl_fork(child_console);
+    pid_t pid = xl_fork(child_console, "console child");
     if (pid)
         return;
 
@@ -3525,7 +3525,7 @@ static pid_t create_migration_child(const char *rune, int *send_fd,
     MUST( libxl_pipe(ctx, sendpipe) );
     MUST( libxl_pipe(ctx, recvpipe) );
 
-    child = xl_fork(child_migration);
+    child = xl_fork(child_migration, "migration transport process");
 
     if (!child) {
         dup2(sendpipe[0], 0);
@@ -3586,9 +3586,8 @@ static void migration_child_report(int recv_fd) {
 
         if (child == migration_child) {
             if (status)
-                libxl_report_child_exitstatus(ctx, XTL_INFO,
-                                              "migration target process",
-                                              migration_child, status);
+                xl_report_child_exitstatus(XTL_INFO, child_migration,
+                                           migration_child, status);
             break;
         }
         if (child == -1) {