[libvirt] [PATCH 5/6] lxc: container: Convert <init> exec to virCommand

Daniel P. Berrange berrange at redhat.com
Tue May 10 09:48:18 UTC 2011


On Fri, May 06, 2011 at 01:26:10PM -0400, Cole Robinson wrote:
> 
> Signed-off-by: Cole Robinson <crobinso at redhat.com>
> ---
>  src/lxc/lxc_container.c |   33 ++++++++++-----------------------
>  1 files changed, 10 insertions(+), 23 deletions(-)
> 
> diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
> index af453f3..4b31479 100644
> --- a/src/lxc/lxc_container.c
> +++ b/src/lxc/lxc_container.c
> @@ -54,6 +54,7 @@
>  #include "veth.h"
>  #include "uuid.h"
>  #include "files.h"
> +#include "command.h"
>  
>  #define VIR_FROM_THIS VIR_FROM_LXC
>  
> @@ -103,33 +104,19 @@ struct __lxc_child_argv {
>   */
>  static int lxcContainerExecInit(virDomainDefPtr vmDef)
>  {
> -    char *uuidenv, *nameenv;
>      char uuidstr[VIR_UUID_STRING_BUFLEN];
> +    virCommandPtr cmd;
>  
>      virUUIDFormat(vmDef->uuid, uuidstr);
>  
> -    if (virAsprintf(&uuidenv, "LIBVIRT_LXC_UUID=%s", uuidstr) < 0) {
> -        virReportOOMError();
> -        return -1;
> -    }
> -    if (virAsprintf(&nameenv, "LIBVIRT_LXC_NAME=%s", vmDef->name) < 0) {
> -        virReportOOMError();
> -        return -1;
> -    }
> +    cmd = virCommandNew(vmDef->os.init);
>  
> -    const char *const argv[] = {
> -        vmDef->os.init,
> -        NULL,
> -    };
> -    const char *const envp[] = {
> -        "PATH=/bin:/sbin",
> -        "TERM=linux",
> -        uuidenv,
> -        nameenv,
> -        NULL,
> -    };
> +    virCommandAddEnvString(cmd, "PATH=/bin:/sbin");
> +    virCommandAddEnvString(cmd, "TERM=linux");
> +    virCommandAddEnvPair(cmd, "LIBVIRT_LXC_UUID", uuidstr);
> +    virCommandAddEnvPair(cmd, "LIBVIRT_LXC_NAME", vmDef->name);
>  
> -    return execve(argv[0], (char **)argv,(char**)envp);
> +    return virCommandExec(cmd);

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




More information about the libvir-list mailing list