aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/logger
diff options
context:
space:
mode:
authorEugene Grosbein <eugen@FreeBSD.org>2023-04-27 16:43:16 +0000
committerEugene Grosbein <eugen@FreeBSD.org>2023-04-27 16:43:16 +0000
commit83fd35b3f3fa580d2b99874abd1f67ee61dcb659 (patch)
treecc99ed27fbb9fd5a8c83e2c0c371260c5e8d5009 /usr.bin/logger
parent7ee4066db1295fe3660964c2561bef87da7431f8 (diff)
downloadsrc-83fd35b3f3fa580d2b99874abd1f67ee61dcb659.tar.gz
src-83fd35b3f3fa580d2b99874abd1f67ee61dcb659.zip
Diffstat (limited to 'usr.bin/logger')
-rw-r--r--usr.bin/logger/logger.c18
1 files 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);
}