From nobody Sat Aug 10 00:00:30 2024 X-Original-To: dev-commits-src-main@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 4WggsC2SYyz5SpLv; Sat, 10 Aug 2024 00:00:31 +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 4WggsC09lQz547C; Sat, 10 Aug 2024 00:00:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723248031; 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=Eq9OlDIPn/Tj6SxZkAmbLyUphU/7mhYnmAcsdh8vbA0=; b=cwMZuPoTzUgiGyGynotH2YUdBEswVf5sVhheffdNsM4OszS1FtxKXN+ekmsC2dDJyp19Jd 9uvyc64dG/KC/BDcrmRPi/uIh13EJD+ea9hF8p2tZzbh7eDxgzRWZOhwFG4/t0Mq7rKko/ VE0afMxuleGVBAaCCKSN6CoUPL1rDj5FHMaoApZU6k46TEfawwcICXO2hzP1qLhKoSjW08 QN6TT3JGlw+II4EVcC9uHymVZWkIm/8ixt6DVpAoeais73SY7e3NVoEv2+DJs77af5vLx4 /1RbTDeXPaVdAwnaIrxwkJmsOBqzrUt0oQ4bm8GHpZBpvgTLGykM7PbsgajZ0A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1723248031; a=rsa-sha256; cv=none; b=aO00CvnHxWROaNecoV6KhgxL1Bd7rpN1aaJRG7cUzECgd2lKAKs+SGiDURwJqkMPC45WdN /jLK877yOQiOnVBur1qlw5Cheix6IHzZcqBcM2BFYH3W2gj5whHFb0w4nVqD2mVe3U4HkP CAhe+HuLLpqhgM6E1cfbROxe0iASCsK2If5OAmyJgYKwWPfpWRd+a6Jp8GuDPje85QrlVF 50RjofLTV1NaD9P6O2iyzWiGw3H6TpeYeV51fQo7qKsaXCs1JAbFVnMogklZS26iqmvN65 DqNStcvJoee7O/j8NHWGxfBEQSakfTBZzFIEw1+HsGj6nkmGWxLxEgguxtLr+w== 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=1723248031; 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=Eq9OlDIPn/Tj6SxZkAmbLyUphU/7mhYnmAcsdh8vbA0=; b=vEkXGeyNQS/TUJNfL+fhATzbusOQPWLgv41n4LOfoIsXY8bc7DfOEGHFoj9NW3hBV50r8v PAOtjhlMvkqjSI/o/ljYK1Oj01rcOEjIG7Dkv5y6Zng+8h+sBt3lXKJjeYTZZRzmRhgoXs lETeTq8U9Hbe4MCmauPbiW1vwR7iPjICoE+uTytgVsVVPukJF4i1YjnnlWIHwKCAKcLmv+ g2CpFbis1bjd9mXWssRym/pZzphpoeyGj3CyPzdblp1Lrx1yHWgKM66yScQT5/KyJUbKUJ 4DgcZr+K7OvbiCKV8dPpOVy2g7jR23MfhgCaGc+83bO4z3WjVNM2VYmzVZN0sQ== 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 4WggsB4pLCzdGy; Sat, 10 Aug 2024 00:00:30 +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 47A00U3d054411; Sat, 10 Aug 2024 00:00:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47A00Um8054408; Sat, 10 Aug 2024 00:00:30 GMT (envelope-from git) Date: Sat, 10 Aug 2024 00:00:30 GMT Message-Id: <202408100000.47A00Um8054408@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Colin Percival Subject: git: 16a235f23c06 - main - dhclient: Switch timeouts from time_t to timespec List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 16a235f23c066d27b3a53c66cf6aa329be07cdb9 Auto-Submitted: auto-generated The branch main has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=16a235f23c066d27b3a53c66cf6aa329be07cdb9 commit 16a235f23c066d27b3a53c66cf6aa329be07cdb9 Author: Isaac Cilia Attard AuthorDate: 2024-07-08 05:43:09 +0000 Commit: Colin Percival CommitDate: 2024-08-09 21:45:06 +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 --- 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 a80c5bd8f23e..5d3c6aa6c990 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 3108fe4365d1..8a0f1406afc7 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -154,7 +154,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++; @@ -172,7 +173,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); @@ -187,10 +188,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; @@ -218,6 +219,7 @@ another: if (count == -1) { if (errno == EAGAIN || errno == EINTR) { time(&cur_time); + time_now.tv_sec = cur_time; continue; } else error("poll: %m"); @@ -225,6 +227,7 @@ another: /* Get the current time... */ time(&cur_time); + time_now.tv_sec = cur_time; i = 0; for (l = protocols; l; l = l->next) { @@ -355,7 +358,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; @@ -394,7 +404,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; @@ -402,7 +412,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;