]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
command: Add virCommandExec helper
authorCole Robinson <crobinso@redhat.com>
Fri, 6 May 2011 14:37:36 +0000 (10:37 -0400)
committerCole Robinson <crobinso@redhat.com>
Tue, 10 May 2011 17:15:50 +0000 (13:15 -0400)
Actually execs the argv/env we've generated, replacing the current process.
Kind of has a limited usage, but allows us to use virCommand in LXC
driver to launch the 'init' process

src/libvirt_private.syms
src/util/command.c
src/util/command.h

index 528fcdc0889db2fb236ebaa12f86d20cbce6d61c..7e5b1d7e9262910e55fde5ced269523e01409ec7 100644 (file)
@@ -107,6 +107,7 @@ virCommandAddEnvPassCommon;
 virCommandAddEnvString;
 virCommandClearCaps;
 virCommandDaemonize;
+virCommandExec;
 virCommandFree;
 virCommandNew;
 virCommandNewArgList;
index ff4869dceb51546af98c839b570ae7860cc31509..78586e8157e31c489eec9f62dbca79e344f061ae 100644 (file)
@@ -980,6 +980,28 @@ cleanup:
     return ret;
 }
 
+/*
+ * Exec the command, replacing the current process. Meant to be called
+ * after already forking / cloning, so does not attempt to daemonize or
+ * preserve any FDs.
+ *
+ * Returns -1 on any error executing the command.
+ * Will not return on success.
+ */
+int virCommandExec(virCommandPtr cmd)
+{
+    if (!cmd ||cmd->has_error == ENOMEM) {
+        virReportOOMError();
+        return -1;
+    }
+    if (cmd->has_error) {
+        virCommandError(VIR_ERR_INTERNAL_ERROR, "%s",
+                        _("invalid use of command API"));
+        return -1;
+    }
+
+    return execve(cmd->args[0], cmd->args, cmd->env);
+}
 
 /*
  * Run the command and wait for completion.
index 69e9169ea46b49455940b68294cd162f173d3384..aa5136b2dd62f36873a9df56b908478f8fd275e1 100644 (file)
@@ -255,6 +255,16 @@ char *virCommandToString(virCommandPtr cmd) ATTRIBUTE_RETURN_CHECK;
  */
 char *virCommandTranslateStatus(int exitstatus) ATTRIBUTE_RETURN_CHECK;
 
+/*
+ * Exec the command, replacing the current process. Meant to be called
+ * after already forking / cloning, so does not attempt to daemonize or
+ * preserve any FDs.
+ *
+ * Returns -1 on any error executing the command.
+ * Will not return on success.
+ */
+int virCommandExec(virCommandPtr cmd) ATTRIBUTE_RETURN_CHECK;
+
 /*
  * Run the command and wait for completion.
  * Returns -1 on any error executing the