[PATCHv2 2/3] util: introduce virWaitPid

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

 



* src/util/util.h (virWaitPid): New prototype.
* src/util/util.c (virWaitPid): Implement it.
* src/util/command.c (virCommandWait): Use it.
* src/libvirt_private.syms: Export it.
---

Should I convert over most remaining instances of waitpid() and
add a 'make syntax-check' entry?  The only place that can't
convert is lxc_controller.c (it uses WNOHANG instead of 0), but
lxc is already Linux-specific, so it can be exempted from a
syntax-check.

 src/libvirt_private.syms |    1 +
 src/util/command.c       |    3 +--
 src/util/util.c          |   20 ++++++++++++++++++++
 src/util/util.h          |    5 +++++
 4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b24ca70..840588a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -862,6 +862,7 @@ virStrcpy;
 virStrncpy;
 virTimestamp;
 virVasprintf;
+virWaitPid;


 # uuid.h
diff --git a/src/util/command.c b/src/util/command.c
index f9d475e..257b9cb 100644
--- a/src/util/command.c
+++ b/src/util/command.c
@@ -1204,8 +1204,7 @@ virCommandWait(virCommandPtr cmd, int *exitstatus)


     /* Wait for intermediate process to exit */
-    while ((ret = waitpid(cmd->pid, &status, 0)) == -1 &&
-           errno == EINTR);
+    ret = virWaitPid(cmd->pid, &status);

     if (ret == -1) {
         virReportSystemError(errno, _("unable to wait for process %d"),
diff --git a/src/util/util.c b/src/util/util.c
index 1b5bc68..7eb8662 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -876,7 +876,19 @@ virRunWithHook(const char *const*argv,
     return ret;
 }

+/* Perform a blocking wait for the child process to complete, and put
+ * the child's exit status in *status.  Return 0 if successful, -1 on
+ * failure to wait.  */
+int virWaitPid(pid_t pid, int *status)
+{
+    int ret;
+    while ((ret = waitpid(pid, status, 0) == -1) && errno == EINTR);
+
+    return ret < 0 ? -1 : 0;
+}
+
 #else /* WIN32 */
+# include <process.h>

 int virSetCloseExec(int fd ATTRIBUTE_UNUSED)
 {
@@ -940,6 +952,14 @@ virFork(pid_t *pid)
     return -1;
 }

+/* Perform a blocking wait for the child process to complete, and put
+ * the child's exit status in *status.  Return 0 if successful, -1 on
+ * failure to wait.  */
+int virWaitPid(pid_t pid, int *status)
+{
+    return _cwait(status, pid, 0) < 0 ? -1 : 0;
+}
+
 #endif /* WIN32 */

 int
diff --git a/src/util/util.h b/src/util/util.h
index ef4fc13..16f7f54 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -53,6 +53,11 @@ enum {
 int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
 int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;

+/* Perform a blocking wait for the child process to complete, and put
+ * the child's exit status in *status.  Return 0 if successful, -1 on
+ * failure to wait.  */
+int virWaitPid(pid_t pid, int *status);
+
 /* This will execute in the context of the first child
  * after fork() but before execve() */
 typedef int (*virExecHook)(void *data);
-- 
1.7.3.2

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