From nobody Thu Apr 27 16:47:57 2023 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 4Q6hW20jj5z47Pb0; Thu, 27 Apr 2023 16:47:58 +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 4Q6hW2056vz3kGY; Thu, 27 Apr 2023 16:47:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682614078; 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=kXTAY2dtxkCx4cfxRgY16gkZmZ8D9eoTwebEc38t4EQ=; b=Bkp5qkFvTOjoDepQ0BQXuXZZG8ZhQqoAM6M4c5Y7+Ws60jIhF3UN6FVqbnKuG9z1+iqMtV XS3VXfqKJkraVnGKXku95mcYdnKamGoWt/vC3/1jdXk7jsVieGPDx3yqoNVGLh36y27QEF N4lJQ/7uebWVuCiOSORbnEak5GcL2a/ACaBjGrjt6JTDIxC+ciNxB0jmMbs5cA1q8dlW+Q wKz/H4GzYfDLY+V451vrY9svgtAFn2an1D+j1AZXGV8uSN3r7giARC+iJU7kUAe/u7OiGv HFTuv9Ia9scJeMf15568f9tdhpJ9671lchSTYEgQBBPl/7FaQNZPt2jUc4hsjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682614078; 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=kXTAY2dtxkCx4cfxRgY16gkZmZ8D9eoTwebEc38t4EQ=; b=LxArcASHz/bzWMriaGHzQejzgWwPLSV1jzAvtw4mqm6ow44pltTDHI2EWUJOayqGBVOos9 ZnwnNMz8dY0+p1naVtG8mDb6ZkfjhThmxoTDPCMohA/rJAU27KUrNQQNhZv/Lq9NqraXFG z4wvSob6TjBBXSNl6dNY1wACJk6m+Rm7bXwauX3V+EMx2y7wMiNx6Mh9oxJjYFuA2a40Vk AYM3jptoo2rENhYHnuXxlXb6BJHx+ZCRgpBOPLmj42N3B6SU+QFJZ8MuP4tUChOdWrzpNm yE9EXHPulDV5VZAPrkMSPjL0Q6zyIpGYf99hRxf51pGDwMaqueAsZMXekVDmxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682614078; a=rsa-sha256; cv=none; b=sENXNz9y8TZ+s6x6Hz2PzyECcv4Zlpx1WRmNSROsQmCKMOCiJn0ZX/RfzD0fOMIIFjkNrd 81R9UwkorOfQ4c85yRAKGLEsk1a3XnUVVR7ctYBKQk4lN+54vHCYoLykqfccMhCe1ybxVl sbNPMMIhXXjts55AeVBxUKSW4/GuodYqqIzjDVjRu/Vquju3tOJ89k3vsf7AMYoXgxrVx9 MiiThYH+jfazFcCMyXGU0X0ieTsAPNHgQjqy8p3VOdrYnyjnQcvSoGEcMM5vOrg2Sc33X9 QA2MYvdF7KGLIih39uZTSu+AqvREUKMaQA7c5OkEaaiWf/qKcYefLwmPcwURLg== 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 4Q6hW16DvMzQT6; Thu, 27 Apr 2023 16:47:57 +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 33RGlvfH014415; Thu, 27 Apr 2023 16:47:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33RGlv63014414; Thu, 27 Apr 2023 16:47:57 GMT (envelope-from git) Date: Thu, 27 Apr 2023 16:47:57 GMT Message-Id: <202304271647.33RGlv63014414@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Eugene Grosbein Subject: git: 83fd35b3f3fa - main - logger(1): fix timestamps in case of long run 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: eugen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 83fd35b3f3fa580d2b99874abd1f67ee61dcb659 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by eugen: URL: https://cgit.FreeBSD.org/src/commit/?id=83fd35b3f3fa580d2b99874abd1f67ee61dcb659 commit 83fd35b3f3fa580d2b99874abd1f67ee61dcb659 Author: Eugene Grosbein AuthorDate: 2023-04-27 16:43:16 +0000 Commit: Eugene Grosbein CommitDate: 2023-04-27 16:43:16 +0000 logger(1): 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 MFC after: 1 week --- 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); }