From 4040288732932a373555b8d9ebad4b6bd5135ae0 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 14 Oct 2008 15:51:26 -0700 Subject: [PATCH] dhcp-client: Fix computation of timeouts. 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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index db0bb0bd1..5e54017df 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -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, -- 2.43.0