From: Yuto KAWAMURA(kawamuray) Date: Fri, 4 Jul 2014 17:35:09 +0000 (+0900) Subject: Fix incorrect timeout handling of do_reboot_and_check() X-Git-Tag: lxc-1.1.0.alpha1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5bb2a6e87f48262744012d868265727e84f9ad9d;p=thirdparty%2Flxc.git Fix incorrect timeout handling of do_reboot_and_check() 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) Acked-by: Serge E. Hallyn --- diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c index cb2fee089..705453266 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: