[systemd-devel] [PATCH] journal: pass secfrac to syslog

Lars Gullik Bjønnes larsbj at gullik.org
Thu Sep 12 06:47:43 PDT 2013


On 12 September 2013 14:23, Lennart Poettering <lennart at poettering.net>wrote:

> On Thu, 12.09.13 11:44, Lars Gullik Bjønnes (larsbj at gullik.org) wrote:
>
> >
> > Also pass fractional seconds to syslog. This allows the syslog
> > daemon to show the fractional seconds at its own choosing.
> > ---
> >
> > This has so far only been compile tested, and I am not sure if
> > other syslog deamons than syslog-ng will work with this.
>
> When passing native data on to a syslog daemon we currently generate the
> exact format glibc generates on the /dev/syslog socket.
>
> Also note that for the case where we receieved a message via the syslog
> protocol we actually pass the bytewise identical message on
> (forward_syslog_raw() does that). Since most traffic still comes in via
> the syslog protocol your change won't affect most of the traffic
> hence. This means: to make this fully useful you'd have to patch glibc
> too, to generate the precise format. However, systemd is currently not
> capable of parsing that precise format, so you'd have to add that too...
>

I do not see the need for patching glibc, that will work like it has always
done.
I agree that systemd must learn how to read the fractional seconds.
(after all part of both new and old syslog RFC's)

Current status in our environment is that we don't use syslog(3) for this,
especially to get fractions.
We want to use sd_journal_* instead, but we do not want to loose the
fractional seconds that
we have to day.

Then, we can only merge this if the three big syslog implementations,
> rsyslog, syslog-ng, sysklogd are known to understand this formatting in
> their default configuration
>

syslog-ng certainly both reads and writes this format.
I will have to check the tow others (but if they implement the old (and
new) RFC
they should undertand it already.)


> Lennart
>
>
> >
> > [Sorry if you see this twice on list.]
> >
> >  src/journal/journald-syslog.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/journal/journald-syslog.c
> b/src/journal/journald-syslog.c
> > index c2770a5..2233416 100644
> > --- a/src/journal/journald-syslog.c
> > +++ b/src/journal/journald-syslog.c
> > @@ -125,6 +125,8 @@ void server_forward_syslog(Server *s, int priority,
> const char *identifier, cons
> >          char header_priority[6], header_time[64], header_pid[16];
> >          int n = 0;
> >          time_t t;
> > +        usec_t realtime;
> > +        suseconds_t us;
> >          struct tm *tm;
> >          char *ident_buf = NULL;
> >
> > @@ -142,12 +144,17 @@ void server_forward_syslog(Server *s, int
> priority, const char *identifier, cons
> >          IOVEC_SET_STRING(iovec[n++], header_priority);
> >
> >          /* Second: timestamp */
> > -        t = tv ? tv->tv_sec : ((time_t) (now(CLOCK_REALTIME) /
> USEC_PER_SEC));
> > +        realtime = now(CLOCK_REALTIME);
> > +        t = tv ? tv->tv_sec : ((time_t) (realtime / USEC_PER_SEC));
> > +        us = tv ? tv->tv_usec : ((suseconds_t)(realtime %
> USEC_PER_SEC));
> >          tm = localtime(&t);
> >          if (!tm)
> >                  return;
> > -        if (strftime(header_time, sizeof(header_time), "%h %e %T ", tm)
> <= 0)
> > +        if (strftime(header_time, sizeof(header_time), "%h %e %T", tm)
> <= 0)
> >                  return;
> > +        snprintf(header_time + strlen(header_time), sizeof(header_time)
> - strlen(header_time),
> > +                 ".%06lu ", us);
> > +
> >          IOVEC_SET_STRING(iovec[n++], header_time);
> >
> >          /* Third: identifier and PID */
>
>
> Lennart
>
> --
> Lennart Poettering - Red Hat, Inc.
>



-- 
        Lgb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20130912/cf3a4dee/attachment-0001.html>


More information about the systemd-devel mailing list