[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 14:25:18 UTC 2014
Quoting Rodrigo Vaz (rodrigo at heroku.com):
> I managed to make lxc-start return the container's exit code, I'm not sure
> if this could break something else and I appreciate any comment.
Hi,
we can't change the return value of lxcapi_start, because that would
change the stable API.
What about adding something like 'int err_value' or 'int exit_value'
to the lxc_container struct, and having lxc_start.c, if it gets
false back from c->start(), extracting the err_value and returning
that?
> Signed-off-by: Rodrigo Sampaio Vaz <rodrigo at heroku.com>
> ---
> src/lxc/lxc_start.c | 5 ++---
> src/lxc/lxccontainer.c | 8 ++++----
> src/lxc/lxccontainer.h | 4 ++--
> 3 files changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
> index 1d8145f..0f4649c 100644
> --- a/src/lxc/lxc_start.c
> +++ b/src/lxc/lxc_start.c
> @@ -328,9 +328,8 @@ int main(int argc, char *argv[])
> if (my_args.close_all_fds)
> c->want_close_all_fds(c, true);
>
> - err = c->start(c, 0, args) ? 0 : 1;
> -
> - if (err) {
> + err = c->start(c, 0, args);
> + if (err > 0) {
> ERROR("The container failed to start.");
> if (my_args.daemonize)
> ERROR("To get more details, run the container in foreground mode.");
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 62e38d7..dc89f33 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -547,7 +547,7 @@ static bool am_single_threaded(void)
> * I can't decide if it'd be more convenient for callers if we accept
> '...',
> * or a null-terminated array (i.e. execl vs execv)
> */
> -static bool lxcapi_start(struct lxc_container *c, int useinit, char *
> const argv[])
> +static int lxcapi_start(struct lxc_container *c, int useinit, char * const
> argv[])
> {
> int ret;
> struct lxc_conf *conf;
> @@ -683,15 +683,15 @@ reboot:
> }
>
> if (daemonize)
> - exit (ret == 0 ? true : false);
> + exit (ret);
> else
> - return (ret == 0 ? true : false);
> + return (ret);
> }
>
> /*
> * note there MUST be an ending NULL
> */
> -static bool lxcapi_startl(struct lxc_container *c, int useinit, ...)
> +static int lxcapi_startl(struct lxc_container *c, int useinit, ...)
> {
> va_list ap;
> char **inargs = NULL;
> diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
> index 1d0628a..303f426 100644
> --- a/src/lxc/lxccontainer.h
> +++ b/src/lxc/lxccontainer.h
> @@ -189,7 +189,7 @@ struct lxc_container {
> *
> * \return \c true on success, else \c false.
> */
> - bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
> + int (*start)(struct lxc_container *c, int useinit, char * const argv[]);
>
> /*!
> * \brief Start the container (list variant).
> @@ -204,7 +204,7 @@ struct lxc_container {
> * arguments are specified via a list rather than an array of
> * pointers.
> */
> - bool (*startl)(struct lxc_container *c, int useinit, ...);
> + int (*startl)(struct lxc_container *c, int useinit, ...);
>
> /*!
> * \brief Stop the container.
> --
> 2.0.1
>
>
>
>
> On Tue, Jul 1, 2014 at 6:36 PM, Rodrigo Vaz <rodrigo at heroku.com> wrote:
>
> > Hi,
> >
> > I've started testing lxc 1.0.4 on our environment with ubuntu trusty
> > images and found an issue with the exit code of lxc-start.
> >
> > On lxc 0.9.0 the exit code matches the container:
> >
> > vagrant at vagrant-ubuntu-trusty-64:~$ sudo lxc-start -l debug -o lxc.log -n
> > u1 -- bash -c 'echo TEST && sleep 10 && exit 143'
> > TEST
> > vagrant at vagrant-ubuntu-trusty-64:~$ echo $?
> > 143
> >
> > Running the same test on lxc 1.0.4:
> >
> > root at runtime.21 ~# lxc-start -l debug -o lxc.log -n u1 -- bash -c 'echo
> > TEST && sleep 10 && exit 143'
> > TEST
> > lxc-start: The container failed to start.
> > lxc-start: Additional information can be obtained by setting the --logfile
> > and --log-priority options.
> > root at runtime.21 ~# echo $?
> > 1
> >
> > lxc.log says:
> >
> > lxc-start 1404250316.378 INFO lxc_error - child <18118> ended on
> > error (143)
> > lxc-start 1404250316.378 WARN lxc_conf - failed to remove
> > interface '(null)'
> > lxc-start 1404250316.382 ERROR lxc_start_ui - The container
> > failed to start.
> > lxc-start 1404250316.382 ERROR lxc_start_ui - Additional
> > information can be obtained by setting the --logfile and --log-priority
> > options.
> >
> > This was reproducible on the same machine using lxc 0.9.0 and 1.0.4.
> >
> > Has anything changed recently regarding exit codes?
> >
> > Regards,
> >
> > Rodrigo.
> >
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
More information about the lxc-devel
mailing list