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