Re: [PATCH 4/6] command: Add virCommandExec helper

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

 



On Fri, May 06, 2011 at 01:26:09PM -0400, Cole Robinson wrote:
> 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
> 
> Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
> ---
>  src/libvirt_private.syms |    1 +
>  src/util/command.c       |   22 ++++++++++++++++++++++
>  src/util/command.h       |   10 ++++++++++
>  3 files changed, 33 insertions(+), 0 deletions(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index d89b191..6e96692 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -106,6 +106,7 @@ virCommandAddEnvPassCommon;
>  virCommandAddEnvString;
>  virCommandClearCaps;
>  virCommandDaemonize;
> +virCommandExec;
>  virCommandFree;
>  virCommandNew;
>  virCommandNewArgList;
> diff --git a/src/util/command.c b/src/util/command.c
> index ff4869d..78586e8 100644
> --- a/src/util/command.c
> +++ b/src/util/command.c
> @@ -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.
> diff --git a/src/util/command.h b/src/util/command.h
> index 69e9169..aa5136b 100644
> --- a/src/util/command.h
> +++ b/src/util/command.h
> @@ -256,6 +256,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
>   * command. Returns 0 if the command executed,

ACK


Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|

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