]> xenbits.xensource.com Git - libvirt.git/commitdiff
command: don't mix RunAsync and daemons
authorEric Blake <eblake@redhat.com>
Wed, 23 Mar 2011 23:42:27 +0000 (17:42 -0600)
committerEric Blake <eblake@redhat.com>
Fri, 25 Mar 2011 11:34:48 +0000 (05:34 -0600)
It doesn't make sense to run a daemon without synchronously
waiting for the child process to reply whether the daemon has
been kicked off and pidfile written yet.

* src/util/command.c (VIR_EXEC_RUN_SYNC): New constant.
(virCommandRun): Set temporary flag.
(virCommandRunAsync): Use it to prevent async runs of intermediate
child when spawning asynchronous daemon grandchild.

src/util/command.c

index 7b4337f410314d8d97a7a9a7b95a1833fd521226..3a8ffaea77beb42e9d1b52f4bebb9b25f75fc51a 100644 (file)
     virReportErrorHelper(NULL, VIR_FROM_NONE, code, __FILE__,           \
                          __FUNCTION__, __LINE__, __VA_ARGS__)
 
+enum {
+    /* Internal-use extension beyond public VIR_EXEC_ flags */
+    VIR_EXEC_RUN_SYNC = 0x40000000,
+};
+
 struct _virCommand {
     int has_error; /* ENOMEM on allocation failure, -1 for anything else.  */
 
@@ -1050,6 +1055,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
         }
     }
 
+    cmd->flags |= VIR_EXEC_RUN_SYNC;
     if (virCommandRunAsync(cmd, NULL) < 0) {
         if (cmd->inbuf) {
             int tmpfd = infd[0];
@@ -1139,6 +1145,7 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
     int ret;
     char *str;
     int i;
+    bool synchronous = false;
 
     if (!cmd || cmd->has_error == ENOMEM) {
         virReportOOMError();
@@ -1150,6 +1157,9 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
         return -1;
     }
 
+    synchronous = cmd->flags & VIR_EXEC_RUN_SYNC;
+    cmd->flags &= ~VIR_EXEC_RUN_SYNC;
+
     /* Buffer management can only be requested via virCommandRun.  */
     if ((cmd->inbuf && cmd->infd == -1) ||
         (cmd->outbuf && cmd->outfdptr != &cmd->outfd) ||
@@ -1166,6 +1176,11 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
         return -1;
     }
 
+    if (!synchronous && (cmd->flags & VIR_EXEC_DAEMON)) {
+        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
+                        _("daemonized command cannot use virCommandRunAsync"));
+        return -1;
+    }
     if (cmd->pwd && (cmd->flags & VIR_EXEC_DAEMON)) {
         virCommandError(VIR_ERR_INTERNAL_ERROR,
                         _("daemonized command cannot set working directory %s"),