From nobody Tue Aug 20 04:58:17 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 4Wny09695Vz5VFp1; Tue, 20 Aug 2024 04:58:17 +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 4Wny094VsLz4NWH; Tue, 20 Aug 2024 04:58:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724129897; 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=Yc+WN6p4TPBrMUq9qUCXeYqPk1/k8WNDgBkJDoZ3LYU=; b=wMe7l75fAS1wRmXh66IyDVp/e9b9Zb4/xZ2MA8k8POXNGV04vmVI7U68I7FVHV/qxa8NCa sbqqCyGauo8C8G4BlX9IbviEtBb43RXYBEqNbkiUY3Nc9DfRbTstqtt2H8fXXUCDuvwQ6E GwocnK1SNHviLs0LSRS68AC5Q1qVIEQfZBHtODfyblTho9lMj9m56SlucP/imc9c27hS1s crVT2MLWOgxZ4dvrO3SAjS0j41mYXXCixMJH9qEtCPyT/n3kqhvbgoc98+At5w5m8euB+j HV1JyaInK2+jTWqkfa/UlKAfhyX0UjUnLOwyB6ZYSumfsglH0KnzjylBWYOEWw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724129897; a=rsa-sha256; cv=none; b=i343PuVvBHkKUassoIx7VMyzgqdL90lUWck7tg58b32CU0fmjMu4C0DeZ7udW6uStWbsUg 6/vFOQeBKb0LntR7PxA25SYHd0Ev6ZyipzM/1j+u3IdNxMLITy3ZKreGcbcIU+9ZMkdQNC pKlNfiQ94T339LHE6ui7UDuZOwRw5scIDgzH3J4SMCkDp5n3JQG1IgowPjUxtjAaarY8ED V9yBQjHxrtmnwYfp8RDhjqwukoM+/4ZoB6p7y8VzpDPPN9b1Uae3gR8+UuFdaXD77ZxrsC 1eTBuEc8RRsntN5AfaOnl6zSYbChMUx17PEebLgPDE8+0TNNBZSHQ0L1drGOyw== 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=1724129897; 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=Yc+WN6p4TPBrMUq9qUCXeYqPk1/k8WNDgBkJDoZ3LYU=; b=sNcE0v6bdAeD00l+yG+ZqzIFxzupLxjOLc0sRby4DPaBYNHbzQZduXR5GlgT1JbG7myllG c92TzrK8PxrZicm/XKAV3JJrvDihJ9a02UimUyogT6rG6LvqRpohoGJYLTwf9lbvvJliap 36OMkh0a2PyNk5Gjqpr0UreYeAq/eFW43nFo0nkiY3apA1wC2LJwbtm2w55+07mnOxArbe Gv8whDOEblJtckFBn5bX7iVvS28OZl8PO6EUrQVyDjh5fxIP2lKKBY/rWdcKQ60wBQ4Jy3 wg3mwe8ODcXX3PYeS0Z6idCbEwB5JugGZKzFHg8m9i/jzQkkbJO4SutM9w5LLQ== 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 4Wny093lGPzlqn; Tue, 20 Aug 2024 04:58:17 +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 47K4wHZa054216; Tue, 20 Aug 2024 04:58:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47K4wHr9054213; Tue, 20 Aug 2024 04:58:17 GMT (envelope-from git) Date: Tue, 20 Aug 2024 04:58:17 GMT Message-Id: <202408200458.47K4wHr9054213@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: 7ee68314d368 - stable/14 - dhclient: Use clock_gettime() instead of time() 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/14 X-Git-Reftype: branch X-Git-Commit: 7ee68314d36856b349457204ea938a302b4d17a4 Auto-Submitted: auto-generated The branch stable/14 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=7ee68314d36856b349457204ea938a302b4d17a4 commit 7ee68314d36856b349457204ea938a302b4d17a4 Author: Isaac Cilia Attard AuthorDate: 2024-07-08 06:23:00 +0000 Commit: Colin Percival CommitDate: 2024-08-20 04:57:08 +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 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 fecc9a5fa5b4..9b31a8395e0c 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; @@ -191,9 +195,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; @@ -220,16 +224,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) {