From nobody Tue Aug 20 05:02:12 2024 X-Original-To: dev-commits-src-branches@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 4Wny4h58Wcz5VFsG; Tue, 20 Aug 2024 05:02:12 +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 4Wny4h4QX7z4QbL; Tue, 20 Aug 2024 05:02:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724130132; 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=S9nX1tfwhy6+LPTp1BPWFpH2JWfwWb8W/+IEfBIeXWg=; b=U+qsPiw4bic3k2UdttdPFIcBg8c+1cKBk3tC1I8k4UenpIrkku4werDQ+Iedw6g5vbjqkX kxAkvC135yOsCRMyPsg3JosthkQVjsfaswq2qkCpzWxpQjBzVFs2G9DJ4krSYv6Slv4+KT AO8fJzK6WCjhZx6ppzcHDLye7WA6WzeCF4pKI1gRgkA6OkLsDhnEeHqbBUTw3hAJj5/2KZ sdK8/RaowIiyMr3zeseEvXMfd3mfF7JHyy8EbuOQ6SgQrBxx7jClpmU69rTELSLj+yW0n2 pk6hN0DL2Q3CFeSzjy/Hn1ssH05XuwHRBLMOHiQ2twnF5BkXIBTLu83Fb2B+JQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724130132; a=rsa-sha256; cv=none; b=Hxz/Xfke7DlcX+G2x3PyMWUrHsT26tJDMpHrgAYCEABckvrszoM7igP5fPqjH/m4c3OGH8 B8bu/D1u354ZugKRBlR0iQfAstI7JOu4fonwjA+pzp40VFf7170S+BISnqWFagITeWZ/Uv n2xhC1emYiGcaf+Z63O2tCxXHDbD/RF1SUhfmq/rWAckJmS6ZAQ/EgQ9IeswKzD6MAFsor WJ6rHWLGjsU2ljJ31qJQOksobbLc6MQ6g7+Dzvza70wdI8pKnSwMTvG2ssQIIzRwIzH70B Buw+mH/gy4NF83j/oLrCv7sES7+eNqXUksbLPpl82OR7VXj68DkqVsemXpTXdQ== 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=1724130132; 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=S9nX1tfwhy6+LPTp1BPWFpH2JWfwWb8W/+IEfBIeXWg=; b=xX1Y2iX3eKamu5GHkcn4d56CvhCeFIthBPaLvw13/aF7eUtmBtqHxVxtuTzHLf7GgOVDLl QpbZneNlGjjkB9zTTlfJcyrfBx70m481j/VHG1kWj2B478lvVzWJX21meOKghwLkqPXrnI c9DDVtoEJ8CWuxlAY5A/6TlSsUlNiPLaPWs5DeoIY4xT1YxghYr0SnL3c8GGU+k575xxT6 ybXU009BNavXQ+z9hQ1DKIi7qRlANkE53+Q25RWKXbWIEjEr+z23Jv5C8pYl8Wr9w6eodw 0/lPLvvVcVITnzdWidwovSB0vdfmjqFnboSvuPdQ4RpHjLwLx7ha/c3xX6nKjQ== 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 4Wny4h3ZTLzn6m; Tue, 20 Aug 2024 05:02:12 +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 47K52CmR072155; Tue, 20 Aug 2024 05:02:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47K52CL7072152; Tue, 20 Aug 2024 05:02:12 GMT (envelope-from git) Date: Tue, 20 Aug 2024 05:02:12 GMT Message-Id: <202408200502.47K52CL7072152@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: d854b4b2aa2b - stable/13 - dhclient: Use clock_gettime() instead of time() List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: d854b4b2aa2b8b60e7fbca07e9637d035318aad5 Auto-Submitted: auto-generated The branch stable/13 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=d854b4b2aa2b8b60e7fbca07e9637d035318aad5 commit d854b4b2aa2b8b60e7fbca07e9637d035318aad5 Author: Isaac Cilia Attard AuthorDate: 2024-07-08 06:23:00 +0000 Commit: Colin Percival CommitDate: 2024-08-20 04:58:35 +0000 dhclient: Use clock_gettime() instead of time() Change the use of time() to clock_gettime() to have millisecond-accurate rather than second-accurate timeouts. 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 f0a38976b01e15956fdba48f8b58db22d0af1f7e) --- sbin/dhclient/dhclient.c | 3 ++- sbin/dhclient/dispatch.c | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 1a39ab1517c2..27e027646ef6 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -446,7 +446,8 @@ main(int argc, char *argv[]) log_perror = 0; tzset(); - time(&cur_time); + clock_gettime(CLOCK_MONOTONIC, &time_now); + cur_time = time_now.tv_sec; inaddr_broadcast.s_addr = INADDR_BROADCAST; inaddr_any.s_addr = INADDR_ANY; diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index e6b06d8616c8..78d94804468b 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -56,6 +56,10 @@ #define assert_aligned(p, align) assert((((uintptr_t)p) & ((align) - 1)) == 0) static struct protocol *protocols; +static const struct timespec timespec_intmax_ms = { + .tv_sec = INT_MAX / 1000, + .tv_nsec = (INT_MAX % 1000) * 1000000 +}; static struct timeout *timeouts; static struct timeout *free_timeouts; static int interfaces_invalidated; @@ -202,9 +206,9 @@ another: * negative timeout and blocking indefinitely. */ 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; + if (timespeccmp(&howlong, ×pec_intmax_ms, >)) + howlong = timespec_intmax_ms; + to_msec = howlong.tv_sec * 1000 + howlong.tv_nsec / 1000000; } else to_msec = -1; @@ -231,16 +235,16 @@ another: /* Not likely to be transitory... */ if (count == -1) { if (errno == EAGAIN || errno == EINTR) { - time(&cur_time); - time_now.tv_sec = cur_time; + clock_gettime(CLOCK_MONOTONIC, &time_now); + cur_time = time_now.tv_sec; continue; } else error("poll: %m"); } /* Get the current time... */ - time(&cur_time); - time_now.tv_sec = cur_time; + clock_gettime(CLOCK_MONOTONIC, &time_now); + cur_time = time_now.tv_sec; i = 0; for (l = protocols; l; l = l->next) {