dhcp-client: Fix computation of timeouts.
authorBen Pfaff <blp@nicira.com>
Tue, 14 Oct 2008 22:51:26 +0000 (15:51 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 14 Oct 2008 23:14:13 +0000 (16:14 -0700)
The "min_timeout" variable maintained by the DHCP client is measured
in seconds from the time the state was entered, but dhclient_wait()
was interpreting it as seconds from now.  This made the DHCP client wait
much longer than necessary in some cases.

lib/dhcp-client.c

index db0bb0b..5e54017 100644 (file)
@@ -800,7 +800,13 @@ void
 dhclient_wait(struct dhclient *cli)
 {
     if (cli->min_timeout != UINT_MAX) {
-        poll_timer_wait(sat_mul(cli->min_timeout, 1000));
+        time_t now = time_now();
+        unsigned int wake = sat_add(cli->state_entered, cli->min_timeout);
+        if (wake <= now) {
+            poll_immediate_wake();
+        } else {
+            poll_timer_wait(sat_mul(sat_sub(wake, now), 1000));
+        }
     }
     /* Reset timeout to 1 second.  This will have no effect ordinarily, because
      * dhclient_run() will typically set it back to a higher value.  If,