From nobody Wed Mar 27 11:26:18 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 4V4PWH3Nhmz5FHwQ; Wed, 27 Mar 2024 11:26:19 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V4PWH0JwBz4bkv; Wed, 27 Mar 2024 11:26:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711538779; 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=8vjOsVo6IXjjI4m7rgwR6YDhOu2SkSMs7CTGP/kOhsg=; b=IqlLE/L0TpkR3Xvg7SBJ01+ynf2ZWGnNPxgnSeGAZKbfNOYuv4960zmSOws+/LsmnLqMDs BUEDE4a4W+dIcNYsUxXX9YLh/xA5Adp7MdOtfqZpJ1FzVM8I6Z+HylW0MH6bgZ1pWFfRvy Ueg7Q4BsBgbsdqOCLK+b0cmhvjKyJnP8UIzhLoawwzudMKuiHpetNL35GgNZmJSyvC6gzq rLoNSlEJbNt0m0f96GvQFFHshe1bizY1iNgbtZHGbLcTaiohzNelU8/d8Dy14CzKTZancL Y2P5h3E87RoaolBPETX7HPqBabc4AAKnxgeaPqE7LafbAiAacrCymUkTTS3x4g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711538779; a=rsa-sha256; cv=none; b=aZj3E0vhLZ22E/LC6c9kJOQRohjehU/ZP394cV8EoRrNBtKMMapUA4MV1Wfkhke9z7FlwK /PCBt3tVFH6Ct+1UDD1pX8xsB6e2LQ8bxD65qXhN5jXDzwAc1UuZp2Ub98IxtbyoEoK4lD 3rvfCLkNQutlxxTcRnL1OV0WEEqgE+bTxskDxaIrVqbU4ch+vNanFayZGpGiuGaz2gD8Q/ XsTBuhx5fUAAY9hw6XM2UOrR5R+AkuV0N9SoQ4nvX5oXQXuZfduEHTqmx9LtZ/rHa6dg0f IDYmwvJ0h+Yo5EA6JqUgTApgi7v/hurew8oGZH/sIl4jYoNize9J738IfflxRA== 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=1711538779; 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=8vjOsVo6IXjjI4m7rgwR6YDhOu2SkSMs7CTGP/kOhsg=; b=ARSQXgvk1MCcOf9BJfIfPsX9cZIKxZ2SLn/rcjhWFKMCx+tB1kk2vMWRewU1HTYs/EFqV9 IXt2AeUTE4WFMm0RWLHKysD3auwNhsSQ8Z4nQZLjZ0OZJPigJdPGnI1gUoU6cNvWe2RGzK brn8Niwa9SEtss4F5c5xOavbmd1MaKyTNHhpZb22v/b6ltL2UAzuYS7+NW0hIKytxgo1Gy L4n4vDATyExZmIwrimuczU0eqSbcGNXqBvWMaL/C2OyUX1CYGzOMUID4jNNvpQDcjqL7pA k1ujtpQHUZtUxdFLpStl1w1JVaFbErxKnUn1dDffzDsDp3Qb0gXOWm4mNl5lig== 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 4V4PWG710Pzj2K; Wed, 27 Mar 2024 11:26:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42RBQIEu003797; Wed, 27 Mar 2024 11:26:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42RBQI1t003794; Wed, 27 Mar 2024 11:26:18 GMT (envelope-from git) Date: Wed, 27 Mar 2024 11:26:18 GMT Message-Id: <202403271126.42RBQI1t003794@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: aa69e0f21263 - main - touch: Allow setting the timestamp to -1. 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: aa69e0f212630bd6d4ec1c3c54e117be16653e8a Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=aa69e0f212630bd6d4ec1c3c54e117be16653e8a commit aa69e0f212630bd6d4ec1c3c54e117be16653e8a Author: Dag-Erling Smørgrav AuthorDate: 2024-03-27 10:03:40 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-03-27 10:03:40 +0000 touch: Allow setting the timestamp to -1. Note that VFS internally interprets a timestamp of -1 as “do not set”, so this has no effect, but at least touch won't incorrectly reject the given date / time (1969-12-31 23:59:59 UTC) as invalid. While here, fix some style issues. MFC after: 1 week Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D44504 --- usr.bin/touch/touch.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c index b43420e4f3ef..70257e320a60 100644 --- a/usr.bin/touch/touch.c +++ b/usr.bin/touch/touch.c @@ -232,7 +232,7 @@ stime_arg1(const char *arg, struct timespec *tvp) } yearset = 0; - switch(strlen(arg)) { + switch (strlen(arg)) { case 12: /* CCYYMMDDhhmm */ t->tm_year = ATOI2(arg); t->tm_year *= 100; @@ -263,15 +263,17 @@ stime_arg1(const char *arg, struct timespec *tvp) } t->tm_isdst = -1; /* Figure out DST. */ + t->tm_yday = -1; tvp[0].tv_sec = tvp[1].tv_sec = mktime(t); - if (tvp[0].tv_sec == -1) + if (t->tm_yday == -1) goto terr; tvp[0].tv_nsec = tvp[1].tv_nsec = 0; return; terr: - errx(1, "out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]"); + errx(1, "out of range or illegal time specification: " + "[[CC]YY]MMDDhhmm[.SS]"); } static void @@ -296,10 +298,11 @@ stime_arg2(const char *arg, int year, struct timespec *tvp) } t->tm_isdst = -1; /* Figure out DST. */ + t->tm_yday = -1; tvp[0].tv_sec = tvp[1].tv_sec = mktime(t); - if (tvp[0].tv_sec == -1) - errx(1, - "out of range or illegal time specification: MMDDhhmm[yy]"); + if (t->tm_yday == -1) + errx(1, "out of range or illegal time specification: " + "MMDDhhmm[yy]"); tvp[0].tv_nsec = tvp[1].tv_nsec = 0; } @@ -339,13 +342,17 @@ stime_darg(const char *arg, struct timespec *tvp) if (*p != '\0') goto bad; + t.tm_yday = -1; tvp[0].tv_sec = isutc ? timegm(&t) : mktime(&t); + if (t.tm_yday == -1) + goto bad; tvp[1] = tvp[0]; return; bad: - errx(1, "out of range or illegal time specification: YYYY-MM-DDThh:mm:SS[.frac][tz]"); + errx(1, "out of range or illegal time specification: " + "YYYY-MM-DDThh:mm:SS[.frac][tz]"); } /* Calculate a time offset in seconds, given an arg of the format [-]HHMMSS. */