[lxc-devel] [PATCH] make the container exit code propagate to lxc-start exit code when appropriate

Serge Hallyn serge.hallyn at ubuntu.com
Thu Jul 3 18:21:20 UTC 2014


Quoting Rodrigo Vaz (rodrigo at heroku.com):
> Hi Serge,
> 
> Thanks for the comment and it makes a lot of sense, here is the V2 patch.

Thanks, just one more comment,

> Signed-off-by: Rodrigo Sampaio Vaz <rodrigo at heroku.com>
> ---
>  src/lxc/lxc_start.c    | 2 ++
>  src/lxc/lxccontainer.c | 1 +
>  src/lxc/lxccontainer.h | 3 +++
>  3 files changed, 6 insertions(+)
> 
> diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
> index 1d8145f..6212422 100644
> --- a/src/lxc/lxc_start.c
> +++ b/src/lxc/lxc_start.c
> @@ -336,6 +336,8 @@ int main(int argc, char *argv[])
>   ERROR("To get more details, run the container in foreground mode.");
>   ERROR("Additional information can be obtained by setting the "
>        "--logfile and --log-priority options.");
> +        lxc_container_put(c);
> +        return c->exit_value;

You should grab the error value before doing the lxc_container_put().
So perhaps

	err = c->exit_value;
	lxc_container_put(c);
	return err;

>   }
> 
>  out:
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 62e38d7..cb26fff 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -669,6 +669,7 @@ static bool lxcapi_start(struct lxc_container *c, int
> useinit, char * const argv
>  reboot:
>   conf->reboot = 0;
>   ret = lxc_start(c->name, argv, conf, c->config_path);
> +    c->exit_value = ret;
> 
>   if (conf->reboot) {
>   INFO("container requested reboot");
> diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
> index 1d0628a..0fb8eb1 100644
> --- a/src/lxc/lxccontainer.h
> +++ b/src/lxc/lxccontainer.h
> @@ -106,6 +106,9 @@ struct lxc_container {
>   /*! Last error number */
>   int error_num;

(Hm, this is intersting, error_num shows up nowhere else in the source.)

> 
> +    /*! Container exit code */
> +    int exit_value;
> +
>   /*! Whether container wishes to be daemonized */
>   bool daemonize;
> 
> -- 
> 2.0.1


More information about the lxc-devel mailing list