[libvirt] [PATCH]lxc: goto cleanup if lxcContainerBuildInitCmd returns NULL

Daniel P. Berrange berrange at redhat.com
Mon Sep 30 08:50:57 UTC 2013


On Mon, Sep 30, 2013 at 04:20:14PM +0800, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> 
> We should goto cleanup directly
> if lxcContainerBuildInitCmd returns NULL,
> which would avoid lots of unnecessary works.
> 
> Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
> ---
>  src/lxc/lxc_container.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
> index 3fdf397..f03f236 100644
> --- a/src/lxc/lxc_container.c
> +++ b/src/lxc/lxc_container.c
> @@ -1820,7 +1820,10 @@ static int lxcContainerChild(void *data)
>      if ((hasReboot = lxcContainerHasReboot()) < 0)
>          goto cleanup;
>  
> -    cmd = lxcContainerBuildInitCmd(vmDef);
> +    if (!(cmd = lxcContainerBuildInitCmd(vmDef))) {
> +        VIR_DEBUG("Failed to build init cmd for container");
> +        goto cleanup;
> +    }
>      virCommandWriteArgLog(cmd, 1);

This is not required - the virCommand APIs are designed to handle
NULL for cmd - they do delayed error reporting.


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