[lxc-devel] [PATCH] Fix incorrect timeout handling of do_reboot_and_check()
Serge Hallyn
serge.hallyn at ubuntu.com
Mon Jul 7 14:09:13 UTC 2014
Quoting Yuto KAWAMURA(kawamuray) (kawamuray.dadada at gmail.com):
> Currently do_reboot_and_check() is decreasing timeout variable even if
> it is set to -1, so running 'lxc-stop --reboot --timeout=-1 ...' will
> exits immediately at end of second iteration of loop, without waiting
> container reboot.
> Also, there is no need to call gettimeofday if timeout is set to -1, so
> these statements should be evaluated only when timeout is enabled.
>
> Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada at gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
> ---
> src/lxc/lxc_stop.c | 26 +++++++++++++++-----------
> 1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c
> index cb2fee0..7054532 100644
> --- a/src/lxc/lxc_stop.c
> +++ b/src/lxc/lxc_stop.c
> @@ -110,19 +110,23 @@ static int do_reboot_and_check(struct lxc_arguments *a, struct lxc_container *c)
> if (newpid != -1 && newpid != pid)
> return 0;
>
> - ret = gettimeofday(&tv, NULL);
> - if (ret)
> - break;
> - curtime = tv.tv_sec;
> + if (timeout != -1) {
> + ret = gettimeofday(&tv, NULL);
> + if (ret)
> + break;
> + curtime = tv.tv_sec;
> + }
>
> sleep(1);
> - ret = gettimeofday(&tv, NULL);
> - if (ret)
> - break;
> - elapsed_time = tv.tv_sec - curtime;
> - if (timeout != -1 && timeout - elapsed_time <= 0)
> - break;
> - timeout -= elapsed_time;
> + if (timeout != -1) {
> + ret = gettimeofday(&tv, NULL);
> + if (ret)
> + break;
> + elapsed_time = tv.tv_sec - curtime;
> + if (timeout - elapsed_time <= 0)
> + break;
> + timeout -= elapsed_time;
> + }
> }
>
> out:
> --
> 1.8.5.5
>
> _______________________________________________
> 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