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

Lars Gullik Bjønnes larsbj at gullik.org
Thu Sep 12 02:44:35 PDT 2013


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.

[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 */
-- 
1.8.4


-- 
	Lgb


More information about the systemd-devel mailing list