From nobody Tue Aug 20 05:02:10 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Wny4f2g61z5VG0q; Tue, 20 Aug 2024 05:02:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wny4f1yfMz4QgV; Tue, 20 Aug 2024 05:02:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724130130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iAVE/cr2fjbTk76HaCNZBRMQ/f/yHTLP4G2jbvJCTPw=; b=Wbb3Tm/aPLsXfd3Y+lyz33kJj4w/e3tZnmJd4MmrVFK10yc0m/IlvOrhwenvg5gfuf8QHc WkGD9CmTWPJKSZVN7g+teMUeoIH/UaVHhnXhxMTjyGN5a1HuttJGlK3ByUF7ECkPkOI3g+ NRkQVaFTWhYQ089dGN5Hnk/6nrbup9URcLGdcZ2lflf7D83VO+GJEzqci5z65FA88SVzmY M5U3lUkD5ezxZ4mz7V6o5pW+pBuHPzQO/yaVam02GuwgB+TG+WIcN1zyHF28znMjvrWhdU gNets6P7jtCEszpU/6ZIdWMKCK+8r29L7c9w95SOAKMgFfxoLC3Ct46DwppNvw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724130130; a=rsa-sha256; cv=none; b=colKg4j8GzfzCACL31mJDic1XkZNrMXHmhcARBfEubkpuU+hbt0UGYJWEv+uhE5xwZ4afI 3u5gLhLkHfUwaX2882xjZ7SoQO9BSs/qFewCiuPsyQw33iqXTdbdcAYW6XLW6l902ev/qf 2qOGozDTaerN7lnrGcajrbA9xOv3QbY2Js+Yl4ja/YNtCQL1KuAlcQK60Lzlz4t33WCFUM OyXeOYcX2lWw6Nbxr4O2gskfe8lyMojdUfZoCzdyDWpFzktbYKLKv6Mv35lisAjQ7xmAvD eYhSAccWhTT7kSjxszQxlwRzTqtyEz+SHm4FHABewo98JemqBW+BTE1ZPwIUgg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724130130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iAVE/cr2fjbTk76HaCNZBRMQ/f/yHTLP4G2jbvJCTPw=; b=DDIOvkH3Bnpybp/nfXsjvR+qbMyt/G0YxCdOZAcF+KUTNvg0zjeP0TtyKtcmeCca0pvJhw cz8gnRizZF/UNlAciq+SKcRUjAmM4SVGHloCp/jjPvZuOcbBRdJZB9i0pIrgYpguG2jxLI OFzVLezShnIoLEGKImlf4QD2DBeNhThfLHwsUmjrg3KTC/F0KCeYwVjeB5SglLl2TQBiA3 AIu+o5XdttUoAL3FvsfrLUnfraMJ7CVKRHDuLocRl0fowc/QYa56zWd7Rx063GcT6XiR1l PQ31LhdZ5jU9CLrzsEKTY7KmHW7e844jPHdR9h8QUgXnnEBaBvm6ciRf8JlLfw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Wny4f1Ysmzn6l; Tue, 20 Aug 2024 05:02:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47K52AJp072061; Tue, 20 Aug 2024 05:02:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47K52AMB072058; Tue, 20 Aug 2024 05:02:10 GMT (envelope-from git) Date: Tue, 20 Aug 2024 05:02:10 GMT Message-Id: <202408200502.47K52AMB072058@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: ce9a5b417909 - stable/13 - dhclient: Switch timeouts from time_t to timespec List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ce9a5b417909d2617b6580df1e25136394b928a0 Auto-Submitted: auto-generated The branch stable/13 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=ce9a5b417909d2617b6580df1e25136394b928a0 commit ce9a5b417909d2617b6580df1e25136394b928a0 Author: Isaac Cilia Attard AuthorDate: 2024-07-08 05:43:09 +0000 Commit: Colin Percival CommitDate: 2024-08-20 04:58:35 +0000 dhclient: Switch timeouts from time_t to timespec Introduce a new function, add_timeout_timespec(), to use timespec structs to handle timeouts. Make add_timeout() into a wrapper for the latter function to retain compatibility with the rest of the codebase. No functional change intended. Sponsored by: Google LLC (GSoC 2024) Signed-off-by: Isaac Cilia Attard MFC after: 10 days Reviwed by: cperciva, brooks, Tom Hukins, Alexander Ziaee Pull Request: https://github.com/freebsd/freebsd-src/pull/1368 (cherry picked from commit 16a235f23c066d27b3a53c66cf6aa329be07cdb9) --- sbin/dhclient/dhcpd.h | 3 ++- sbin/dhclient/dispatch.c | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 33c34c9ca9df..8e4c1344843a 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -218,7 +218,7 @@ struct interface_info { struct timeout { struct timeout *next; - time_t when; + struct timespec when; void (*func)(void *); void *what; }; @@ -320,6 +320,7 @@ void reinitialize_interfaces(void); void dispatch(void); void got_one(struct protocol *); void add_timeout(time_t, void (*)(void *), void *); +void add_timeout_timespec(struct timespec, void (*)(void *), void *); void cancel_timeout(void (*)(void *), void *); void add_protocol(const char *, int, void (*)(struct protocol *), void *); void remove_protocol(struct protocol *); diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 7347736cc787..c02cb2c52796 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -166,7 +166,8 @@ dispatch(void) int count, live_interfaces, i, to_msec, nfds = 0; struct protocol *l; struct pollfd *fds; - time_t howlong; + struct timespec howlong; + struct timespec time_now = { .tv_sec = cur_time, .tv_nsec = 0 }; for (l = protocols; l; l = l->next) nfds++; @@ -184,7 +185,7 @@ another: if (timeouts) { struct timeout *t; - if (timeouts->when <= cur_time) { + if (timespeccmp(&timeouts->when, &time_now, <=)) { t = timeouts; timeouts = timeouts->next; (*(t->func))(t->what); @@ -199,10 +200,10 @@ another: * int for poll, while not polling with a * negative timeout and blocking indefinitely. */ - howlong = timeouts->when - cur_time; - if (howlong > INT_MAX / 1000) - howlong = INT_MAX / 1000; - to_msec = howlong * 1000; + timespecsub(&timeouts->when, &time_now, &howlong); + if (howlong.tv_sec > INT_MAX / 1000) + howlong.tv_sec = INT_MAX / 1000; + to_msec = howlong.tv_sec * 1000; } else to_msec = -1; @@ -230,6 +231,7 @@ another: if (count == -1) { if (errno == EAGAIN || errno == EINTR) { time(&cur_time); + time_now.tv_sec = cur_time; continue; } else error("poll: %m"); @@ -237,6 +239,7 @@ another: /* Get the current time... */ time(&cur_time); + time_now.tv_sec = cur_time; i = 0; for (l = protocols; l; l = l->next) { @@ -367,7 +370,14 @@ active: } void -add_timeout(time_t when, void (*where)(void *), void *what) +add_timeout(time_t when_s, void (*where)(void *), void *what) +{ + struct timespec when = { .tv_sec = when_s, .tv_nsec = 0 }; + add_timeout_timespec(when, where, what); +} + +void +add_timeout_timespec(struct timespec when, void (*where)(void *), void *what) { struct timeout *t, *q; @@ -406,7 +416,7 @@ add_timeout(time_t when, void (*where)(void *), void *what) /* Now sort this timeout into the timeout list. */ /* Beginning of list? */ - if (!timeouts || timeouts->when > q->when) { + if (!timeouts || timespeccmp(&timeouts->when, &q->when, >)) { q->next = timeouts; timeouts = q; return; @@ -414,7 +424,7 @@ add_timeout(time_t when, void (*where)(void *), void *what) /* Middle of list? */ for (t = timeouts; t->next; t = t->next) { - if (t->next->when > q->when) { + if (timespeccmp(&t->next->when, &q->when, >)) { q->next = t->next; t->next = q; return;