-----Original Message-----
From: Daniel P. Berrange [mailto:berrange@redhat.com]
Sent: Monday, September 30, 2013 4:51 PM
To: Chen Hanxiao
Cc: libvir-list(a)redhat.com
Subject: Re: [libvirt] [PATCH]lxc: goto cleanup if lxcContainerBuildInitCmd
returns NULL
On Mon, Sep 30, 2013 at 04:20:14PM +0800, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao(a)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(a)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.
Thanks, I see.
I just don't want lxcContainerChild to have finished all preparation
and then find nothing to do due to an OOM occurred :)