Quoting Rodrigo Vaz ([email protected]): > 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 <[email protected]> > --- > 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 <[email protected]> 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@vagrant-ubuntu-trusty-64:~$ sudo lxc-start -l debug -o lxc.log -n > > u1 -- bash -c 'echo TEST && sleep 10 && exit 143' > > TEST > > vagrant@vagrant-ubuntu-trusty-64:~$ echo $? > > 143 > > > > Running the same test on lxc 1.0.4: > > > > [email protected] ~# 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. > > [email protected] ~# 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 > [email protected] > http://lists.linuxcontainers.org/listinfo/lxc-devel _______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
