From nobody Sat Aug 10 00:00:32 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 4WggsF2HXtz5SpZQ; Sat, 10 Aug 2024 00:00:33 +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 4WggsF03XNz549L; Sat, 10 Aug 2024 00:00:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1723248033; 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=guuemTPYS/oH3csIE/7CJ/5xRL7TMueANxFs013FOok=; b=uP2f7keIQPOQ9ce7Q8kixpF4kw2M2HKnspq0dJ99hIOh9hwZ6AQlUsV1FtAbCm5rnsqc3v yO+92/L3c5pN+vTSs/DIwaRaarUUNp32FKy36jlBbPdAYBgPVs9gWXKm+fi/m4nHSSm6C2 kZo5PfShjGDf4b0Y76G+pv47AREDReAoKrMsMb9e1gdghQOwPr9uDmBygjPTz/qNQfsCxa BgF3mmGoybdZ0c9SMetaz0P0xPLlVVY34aXX7m2zJP0ZkhnuIKmzpGwvirQdB3+gadYvHC mbV7dYvIA7BM4CascguEYdTs0MVOPoFOLYzsLGHvzkXGfMCJxQ3zI+IE/LaTDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1723248033; a=rsa-sha256; cv=none; b=n0yc2k4R9XO8qYPkZp5nLmbfiKFP4HUu1R5cnjxCM1Z16M0fTXD46cUceR6MxD8uYV8glJ RZ7tnQAhU2GPSOJhn0WmUgfQc8tDIpvJ1/w75Gd7RRKaKnpMbN/0hecXQ1L3Fvm4X2LLwG la7CznyV/sV4Ok4CsRCEr86Bg4pXJmHURYIUd7uuhXWZu9wvJ0BA1XSxVnzmmWeshNoySA siD44O7jtFoRqXa2IfzmxsX2HaKZ2C82swoVqK2bGXG9mUZIe8KINW/63KF6wt2VJTzAvr sg2SpFRqAseLaNY9XMnlqAIbtntaYyDVpyNNpqFHoBHpuiMHgPQX+/pk6aRUIw== 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=1723248033; 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=guuemTPYS/oH3csIE/7CJ/5xRL7TMueANxFs013FOok=; b=LwlbwAJ73soTwLj0smGVX3sl7O6Mbvj9lHQn+3CWxTvOokH+HYzZ9myOxBuF10xyFZ2KXP Fnd4RCLrvc0S2YjV0XHXSvsv7vx8pvjmc27/UReszOKevKBlBvAcn1xFfZ8lDmHnN2Pb/h zS45KmajpgO555J2DC8TCcdxyjcXfw/J1yxGlu5h6Rh+wJyXJXODd9hlz56Y4K3DATfG5k vY6T0AK61cATLgPoS6shuQAtB+T5WUTVBt0kGL97kdf6AaZ9YjSg93th3aZ8MS3R/NmeYu yAE46jJ+qkyRVtcpZ9OiCWthWs+y3sk8W9OzD13QfZjEu7mm8kS/i2s38jJKQA== 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 4WggsD6n2xzdRj; Sat, 10 Aug 2024 00:00:32 +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 47A00W4h054498; Sat, 10 Aug 2024 00:00:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47A00Wh1054495; Sat, 10 Aug 2024 00:00:32 GMT (envelope-from git) Date: Sat, 10 Aug 2024 00:00:32 GMT Message-Id: <202408100000.47A00Wh1054495@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: f0a38976b01e - main - dhclient: Use clock_gettime() instead of time() 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: f0a38976b01e15956fdba48f8b58db22d0af1f7e Auto-Submitted: auto-generated The branch main has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=f0a38976b01e15956fdba48f8b58db22d0af1f7e commit f0a38976b01e15956fdba48f8b58db22d0af1f7e Author: Isaac Cilia Attard AuthorDate: 2024-07-08 06:23:00 +0000 Commit: Colin Percival CommitDate: 2024-08-09 21:49:39 +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 --- 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 b53a6f6c892f..043f7808bb9d 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 55c495179e24..72230c01a491 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; @@ -190,9 +194,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; @@ -219,16 +223,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) {