From nobody Thu May 04 05:42:39 2023 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 4QBjQ75nWxz49htP; Thu, 4 May 2023 05:42:39 +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 4QBjQ74z3yz3pp6; Thu, 4 May 2023 05:42:39 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683178959; 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=UnvXM8pIwWfcbLCSigw/TzlYtLLeSFJh+ozbMAB0Uk4=; b=YCA+ugn+BoHNxFl+l6DWfDrcKZRpXYFMaMPYOGOsm+/uOhUluuB/MZVu5jQHLhpUuY8B9J sV9ZcR9SmGrbt4Y8zwByeoPFicxhSPja2HKMdiydcMC69SScdoIoo76Np7OjARCb1v1ZB+ HswZIohQnAb8PcrwsewbkoLrBK/xW8n7OkK4fSup+E+Ibu1NEoy4XWJcSObBLBTU0lMo91 n1DvaTmYHg2mwjpT2xvC9p6jJXKEv7HBbpUCqncd6m6c1wU0R56Anjne0E5jcEktRm1owH 46sUNKXpKsszV5e5X5x5tGqeun8nYr8BVBUpM9uBc8y5GIeLE/U9lPWGzg1nfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683178959; 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=UnvXM8pIwWfcbLCSigw/TzlYtLLeSFJh+ozbMAB0Uk4=; b=CiwjNUZZ7F0OIoHFk39D2Sb+JyDB98omX4Qr7i/dAiZocztGD2WVxtn8+7yJNWF2VPoc3r 0cc9rEdSxgyb7GpS/p+ZLLBbU2ZRGLH8gxBjIihN+UpjNiJTU/ZB86wMblGxmeBzErAFAo y8VzhzovUVtzKH1R3OqdVpcQXt6NJjrzvHfUCcwtgaFuwhOGha1TpofWpVgkr/5QOiSb5q geLqkOVwdqVBmGKt1NB3fEP0A/KkcoM6C0oOM3yRb9i/OfRNBMwo6rZHWUWoVADw5H3zUE YAxSQmhnEaqD1mQBxXd316fDUCt/dWzkpGOdZrCNhZyVymKdecHinJcLVMJT6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683178959; a=rsa-sha256; cv=none; b=rOv0PkLJBZ4BespeYJ2BEQYqzpqKYeBuIZ9ktiPz4MdErNpQiSL687GA5Qi/C+0paXDNbJ Eze6AnUOzWxS0j5HAd73VSX68oUMRwL69zRTJRMq7N1+DnUVUOLOVRIK6v5agRAc9BlRSE bbUUd0RsYoTnJ8KSyt0mM5BwduR3yDoPfjpPEuah6RnoRQZw2ZNJ18OcmcBqeUQBVV/Ekj LYSnHr2xng9+5dnKvysVXGpV8N9cYJlSLK5D08qm8OScarNo/Bt0zZSVgUjYVsQruZNucv GObD6/yAJ3bcCUj2xcIYVxNYBxYHqjxLQFSJtf7h2Vxf1TApqJMDyjFN+WYvOw== 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 4QBjQ742Mxz10md; Thu, 4 May 2023 05:42:39 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 3445gdA9080191; Thu, 4 May 2023 05:42:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3445gdGU080190; Thu, 4 May 2023 05:42:39 GMT (envelope-from git) Date: Thu, 4 May 2023 05:42:39 GMT Message-Id: <202305040542.3445gdGU080190@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eugene Grosbein Subject: git: f7398d2d0ab6 - stable/13 - logger(1): MFC: fix timestamps in case of long run 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: eugen X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f7398d2d0ab6b22d88296f7daff48ed3fe74aa56 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=f7398d2d0ab6b22d88296f7daff48ed3fe74aa56 commit f7398d2d0ab6b22d88296f7daff48ed3fe74aa56 Author: Eugene Grosbein AuthorDate: 2023-04-27 16:43:16 +0000 Commit: Eugene Grosbein CommitDate: 2023-05-04 05:41:55 +0000 logger(1): MFC: fix timestamps in case of long run An example: ( echo test; sleep 2; echo test2 ) | logger -h /var/run/log Before fix, logger assigned same timestamp to both records. Fixes: 65547fb33db901a9f352aacb0ed45ce68b0bd275 Reported by: Vadim Goncharov (cherry picked from commit 83fd35b3f3fa580d2b99874abd1f67ee61dcb659) --- usr.bin/logger/logger.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/usr.bin/logger/logger.c b/usr.bin/logger/logger.c index 1ce8d81db6f6..32fda60717d6 100644 --- a/usr.bin/logger/logger.c +++ b/usr.bin/logger/logger.c @@ -198,22 +198,23 @@ main(int argc, char *argv[]) if (host == NULL) cap_openlog(capsyslog, tag, logflags, 0); - (void )time(&now); - (void )ctime_r(&now, tbuf); - tbuf[19] = '\0'; - timestamp = tbuf + 4; - if (hostname == NULL) { hostname = hbuf; (void )gethostname(hbuf, MAXHOSTNAMELEN); *strchrnul(hostname, '.') = '\0'; } + timestamp = tbuf + 4; + /* log input line if appropriate */ if (argc > 0) { char *p, *endp; size_t len; + (void )time(&now); + (void )ctime_r(&now, tbuf); + tbuf[19] = '\0'; + for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) { len = strlen(*argv); if (p + len > endp && p > buf) { @@ -235,9 +236,14 @@ main(int argc, char *argv[]) logmessage(pri, timestamp, hostname, tag, socks, nsock, buf); } else - while (fgets(buf, sizeof(buf), stdin) != NULL) + while (fgets(buf, sizeof(buf), stdin) != NULL) { + (void )time(&now); + (void )ctime_r(&now, tbuf); + tbuf[19] = '\0'; + logmessage(pri, timestamp, hostname, tag, socks, nsock, buf); + } exit(0); }