[PATCH 01/16] remote_driver: Convert virExecDaemonize usage to virCommand

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

 



And drop the now unused virExecDaemonize

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/libvirt_private.syms   |    1 -
 src/remote/remote_driver.c |   18 ++++++-----
 src/util/util.c            |   73 +-------------------------------------------
 src/util/util.h            |    9 -----
 4 files changed, 11 insertions(+), 90 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7e5b1d7..4c4f65d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -909,7 +909,6 @@ virEnumToString;
 virEventAddHandle;
 virEventRemoveHandle;
 virExec;
-virExecDaemonize;
 virExecWithHook;
 virFileAbsPath;
 virFileDeletePid;
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 09736d9..1072f9f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -83,6 +83,7 @@
 #include "event.h"
 #include "ignore-value.h"
 #include "files.h"
+#include "command.h"
 
 #define VIR_FROM_THIS VIR_FROM_REMOTE
 
@@ -326,8 +327,8 @@ static int
 remoteForkDaemon(void)
 {
     const char *daemonPath = remoteFindDaemonPath();
-    const char *const daemonargs[] = { daemonPath, "--timeout=30", NULL };
-    pid_t pid;
+    virCommandPtr cmd = NULL;
+    int ret;
 
     if (!daemonPath) {
         remoteError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -335,13 +336,14 @@ remoteForkDaemon(void)
         return -1;
     }
 
-    if (virExecDaemonize(daemonargs, NULL, NULL,
-                         &pid, -1, NULL, NULL,
-                         VIR_EXEC_CLEAR_CAPS,
-                         NULL, NULL, NULL) < 0)
-        return -1;
+    cmd = virCommandNewArgList(daemonPath, "--timeout", "30", NULL);
+    virCommandClearCaps(cmd);
+    virCommandDaemonize(cmd);
 
-    return 0;
+    ret = virCommandRun(cmd, NULL);
+    virCommandFree(cmd);
+
+    return ret;
 }
 #endif
 
diff --git a/src/util/util.c b/src/util/util.c
index 4c50fcb..1d0c2cc 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -443,8 +443,7 @@ cleanup:
  * @flags possible combination of the following:
  *        VIR_EXEC_NONE     : Default function behavior
  *        VIR_EXEC_NONBLOCK : Set child process output fd's as non-blocking
- *        VIR_EXEC_DAEMON   : Daemonize the child process (don't use directly,
- *                            use virExecDaemonize wrapper)
+ *        VIR_EXEC_DAEMON   : Daemonize the child process
  * @hook optional virExecHook function to call prior to exec
  * @data data to pass to the hook function
  * @pidfile path to use as pidfile for daemonized process (needs DAEMON flag)
@@ -789,57 +788,6 @@ virExec(const char *const*argv,
                            flags, NULL, NULL, NULL);
 }
 
-/*
- * See __virExec for explanation of the arguments.
- *
- * This function will wait for the intermediate process (between the caller
- * and the daemon) to exit. retpid will be the pid of the daemon, which can
- * be checked for example to see if the daemon crashed immediately.
- *
- * Returns 0 on success
- *         -1 if initial fork failed (will have a reported error)
- *         -2 if intermediate process failed
- *         (won't have a reported error. pending on where the failure
- *          occured and when in the process occured, the error output
- *          could have gone to stderr or the passed errfd).
- */
-int virExecDaemonize(const char *const*argv,
-                     const char *const*envp,
-                     const fd_set *keepfd,
-                     pid_t *retpid,
-                     int infd, int *outfd, int *errfd,
-                     int flags,
-                     virExecHook hook,
-                     void *data,
-                     char *pidfile) {
-    int ret;
-    int childstat = 0;
-
-    ret = virExecWithHook(argv, envp, keepfd, retpid,
-                          infd, outfd, errfd,
-                          flags | VIR_EXEC_DAEMON,
-                          hook, data, pidfile);
-
-    /* __virExec should have set an error */
-    if (ret != 0)
-        return -1;
-
-    /* Wait for intermediate process to exit */
-    while (waitpid(*retpid, &childstat, 0) == -1 &&
-                   errno == EINTR);
-
-    if (childstat != 0) {
-        char *str = virCommandTranslateStatus(childstat);
-        virUtilError(VIR_ERR_INTERNAL_ERROR,
-                     _("Intermediate daemon process status unexpected: %s"),
-                     NULLSTR(str));
-        VIR_FREE(str);
-        ret = -2;
-    }
-
-    return ret;
-}
-
 /**
  * @argv NULL terminated argv to run
  * @status optional variable to return exit status in
@@ -984,25 +932,6 @@ virExecWithHook(const char *const*argv ATTRIBUTE_UNUSED,
 }
 
 int
-virExecDaemonize(const char *const*argv ATTRIBUTE_UNUSED,
-                 const char *const*envp ATTRIBUTE_UNUSED,
-                 const fd_set *keepfd ATTRIBUTE_UNUSED,
-                 pid_t *retpid ATTRIBUTE_UNUSED,
-                 int infd ATTRIBUTE_UNUSED,
-                 int *outfd ATTRIBUTE_UNUSED,
-                 int *errfd ATTRIBUTE_UNUSED,
-                 int flags ATTRIBUTE_UNUSED,
-                 virExecHook hook ATTRIBUTE_UNUSED,
-                 void *data ATTRIBUTE_UNUSED,
-                 char *pidfile ATTRIBUTE_UNUSED)
-{
-    virUtilError(VIR_ERR_INTERNAL_ERROR,
-                 "%s", _("virExecDaemonize is not implemented for WIN32"));
-
-    return -1;
-}
-
-int
 virFork(pid_t *pid)
 {
     *pid = -1;
diff --git a/src/util/util.h b/src/util/util.h
index 9d8df06..482294f 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -58,15 +58,6 @@ int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
  * after fork() but before execve() */
 typedef int (*virExecHook)(void *data);
 
-int virExecDaemonize(const char *const*argv,
-                     const char *const*envp,
-                     const fd_set *keepfd,
-                     pid_t *retpid,
-                     int infd, int *outfd, int *errfd,
-                     int flags,
-                     virExecHook hook,
-                     void *data,
-                     char *pidfile) ATTRIBUTE_RETURN_CHECK;
 int virExecWithHook(const char *const*argv,
                     const char *const*envp,
                     const fd_set *keepfd,
-- 
1.7.4.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]