]> xenbits.xensource.com Git - libvirt.git/commitdiff
remote_driver: Convert virExecDaemonize usage to virCommand
authorCole Robinson <crobinso@redhat.com>
Fri, 6 May 2011 15:23:57 +0000 (11:23 -0400)
committerCole Robinson <crobinso@redhat.com>
Fri, 13 May 2011 18:19:08 +0000 (14:19 -0400)
And drop the now unused virExecDaemonize

src/libvirt_private.syms
src/remote/remote_driver.c
src/util/util.c
src/util/util.h

index c98efdcfaf965b684a51fa7e9f8565aa716adc26..21a65ad601762fa94053ef251af27a8845287e6c 100644 (file)
@@ -915,7 +915,6 @@ virEnumToString;
 virEventAddHandle;
 virEventRemoveHandle;
 virExec;
-virExecDaemonize;
 virExecWithHook;
 virFileAbsPath;
 virFileDeletePid;
index 2fd25e425f473b30da206efdf191ca5a9bf14117..37a7b48c69c65434cc3c6095601bd6803a5d7064 100644 (file)
@@ -83,6 +83,7 @@
 #include "event.h"
 #include "ignore-value.h"
 #include "files.h"
+#include "command.h"
 
 #define VIR_FROM_THIS VIR_FROM_REMOTE
 
@@ -319,8 +320,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",
@@ -328,13 +329,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
 
index 01ba771a2af07d2eeeefe1c2590652f16a8d9f20..3b5ef0045423893e2a7f751e73fcd52348b77c90 100644 (file)
@@ -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
@@ -983,25 +931,6 @@ virExecWithHook(const char *const*argv ATTRIBUTE_UNUSED,
     return -1;
 }
 
-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)
 {
index 9d8df06714de6d5530dc6527802dc3de9f4da632..482294f303d5e8c819a141b73bd91d411339b236 100644 (file)
@@ -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,