[PATCHv2 2/3] command: don't mix RunAsync and daemons

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
---

v2: new patch

 src/util/command.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/util/command.c b/src/util/command.c
index 7b4337f..3a8ffae 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -41,6 +41,11 @@
     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"),
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]