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

Lennart Poettering lennart at poettering.net
Thu Sep 12 05:23:12 PDT 2013


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...

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.

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.


More information about the systemd-devel mailing list