[lxc-devel] [PATCH] lxc-cmd-stop: two fixes

Stéphane Graber stgraber at ubuntu.com
Mon Apr 13 21:48:54 UTC 2015


On Mon, Apr 13, 2015 at 09:19:47PM +0000, Serge Hallyn wrote:
> These are two fixes for long, long-standing bugs.
> 
> 1. When we stop a container from the lxc_cmd stop handler, we kill its
> init task, then we unfreeze the container to make sure it receives the
> signal.  When that unfreeze succeeds, we were immediately returning 0,
> without sending a response to the invoker.
> 
> 2. lxc_cmd returns the length of the field received.  In the case of
> an lxc_cmd_stop this is 16.  But a comment claims we expect no response,
> only a 0.  In fact the handler does send a response, which may or may
> not include an error.  So don't call an error just because we got back a
> response.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

> ---
>  src/lxc/commands.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/src/lxc/commands.c b/src/lxc/commands.c
> index b70ee72..c2354af 100644
> --- a/src/lxc/commands.c
> +++ b/src/lxc/commands.c
> @@ -608,11 +608,13 @@ int lxc_cmd_stop(const char *name, const char *lxcpath)
>  		return -1;
>  	}
>  
> -	/* we do not expect any answer, because we wait for the connection to be
> -	 * closed
> -	 */
> -	if (ret > 0) {
> -		ERROR("failed to stop '%s': %s", name, strerror(-cmd.rsp.ret));
> +	if (!ret) {
> +		WARN("'%s' has stopped before replying with success", name);
> +		return -1;
> +	}
> +
> +	if (cmd.rsp.ret != 0) {
> +		ERROR("Container %s:%s had an error stopping", lxcpath, name);
>  		return -1;
>  	}
>  
> @@ -637,11 +639,12 @@ static int lxc_cmd_stop_callback(int fd, struct lxc_cmd_req *req,
>  		 * deadlock us
>  		 */
>  		if (cgroup_unfreeze(handler))
> -			return 0;
> +			goto out;
>  		ERROR("Failed to unfreeze %s:%s", handler->lxcpath, handler->name);
>  		rsp.ret = -1;
>  	}
>  
> +out:
>  	return lxc_cmd_rsp_send(fd, &rsp);
>  }
>  
> -- 
> 2.1.4
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150413/bf021e53/attachment.sig>


More information about the lxc-devel mailing list