]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Fix incorrect timeout handling of do_reboot_and_check()
authorYuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Fri, 4 Jul 2014 17:35:09 +0000 (02:35 +0900)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 7 Jul 2014 14:13:57 +0000 (10:13 -0400)
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@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_stop.c

index cb2fee0896cd5310101bb7ed1e583c48fb525d87..705453266e40d79e87b47776504e8a751c31bed4 100644 (file)
@@ -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: