Date: Thu, 19 Sep 2002 16:40:04 -0700 (PDT) From: "Chris S.J. Peron" <maneo@bsdpro.com> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/42974: [patch] ISO 8601 date format option Message-ID: <200209192340.g8JNe3X8010438@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/42974; it has been noted by GNATS. From: "Chris S.J. Peron" <maneo@bsdpro.com> To: freebsd-gnats-submit@FreeBSD.org Cc: Subject: Re: bin/42974: [patch] ISO 8601 date format option Date: Thu, 19 Sep 2002 18:57:29 -0500 Sorry.. I posted the wrong patch. The above patch will put some un-necessary characters after the date/time. This is the 'right' patch :) --- syslogd.o.c Thu Sep 19 15:44:36 2002 +++ syslogd.c Thu Sep 19 18:21:21 2002 @@ -129,6 +129,8 @@ #define MAXFUNIX 20 +#define MAXSTAMPLEN 20 + int nfunix = 1; const char *funixn[MAXFUNIX] = { _PATH_LOG }; int funix[MAXFUNIX]; @@ -174,7 +176,7 @@ } f_pipe; } f_un; char f_prevline[MAXSVLINE]; /* last message logged */ - char f_lasttime[16]; /* time of last occurrence */ + char f_lasttime[MAXSTAMPLEN]; /* time of last occurrence */ char f_prevhost[MAXHOSTNAMELEN]; /* host from which recd. */ int f_prevpri; /* pri of f_prevline */ int f_prevlen; /* length of f_prevline */ @@ -258,6 +260,7 @@ int Debug; /* debug flag */ int resolve = 1; /* resolve hostname */ +int iso8601stamp = 0; /* date/time printed in YYYY-MM-DD HH:MM:SS format ISO 9601 */ char LocalHostName[MAXHOSTNAMELEN]; /* our hostname */ const char *LocalDomain; /* our local domain name */ int *finet = NULL; /* Internet datagram socket */ @@ -333,7 +336,7 @@ socklen_t len; bindhostname = NULL; - while ((ch = getopt(argc, argv, "46Aa:b:cdf:kl:m:np:P:suv")) != -1) + while ((ch = getopt(argc, argv, "46Aa:b:cDdf:kl:m:np:P:suv")) != -1) switch (ch) { case '4': family = PF_INET; @@ -359,6 +362,9 @@ case 'd': /* debug */ Debug++; break; + case 'D': + iso8601stamp = 1; + break; case 'f': /* configuration file */ ConfFile = optarg; break; @@ -761,6 +767,7 @@ int flags; { struct filed *f; + struct tm *t; int i, fac, msglen, omask, prilev; const char *timestamp; char prog[NAME_MAX+1]; @@ -780,12 +787,19 @@ flags |= ADDDATE; (void)time(&now); - if (flags & ADDDATE) - timestamp = ctime(&now) + 4; - else { - timestamp = msg; - msg += 16; - msglen -= 16; + if (iso8601stamp) { + timestamp = alloca(MAXSTAMPLEN); + memset((char *)timestamp, 0, MAXSTAMPLEN); + t = localtime(&now); + strftime((char *)timestamp, MAXSTAMPLEN, "%Y-%m-%d %H:%M:%S", t); + } else { + if (flags & ADDDATE) + timestamp = ctime(&now) + 4; + else { + timestamp = msg; + msg += 16; + msglen -= 16; + } } /* skip leading blanks */ @@ -868,7 +882,7 @@ (flags & MARK) == 0 && msglen == f->f_prevlen && !strcmp(msg, f->f_prevline) && !strcasecmp(from, f->f_prevhost)) { - (void)strlcpy(f->f_lasttime, timestamp, 16); + (void)strlcpy(f->f_lasttime, timestamp, iso8601stamp ? MAXSTAMPLEN : 16); f->f_prevcount++; dprintf("msg repeated %d times, %ld sec of %d\n", f->f_prevcount, (long)(now - f->f_time), @@ -889,7 +903,7 @@ fprintlog(f, 0, (char *)NULL); f->f_repeatcount = 0; f->f_prevpri = pri; - (void)strlcpy(f->f_lasttime, timestamp, 16); + (void)strlcpy(f->f_lasttime, timestamp, iso8601stamp ? MAXSTAMPLEN : 16); (void)strlcpy(f->f_prevhost, from, sizeof(f->f_prevhost)); if (msglen < MAXSVLINE) { @@ -932,7 +946,7 @@ v++; } else { v->iov_base = f->f_lasttime; - v->iov_len = 15; + v->iov_len = iso8601stamp ? MAXSTAMPLEN - 1 : 15; v++; v->iov_base = " "; v->iov_len = 1; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209192340.g8JNe3X8010438>