Revert "Revert "oran-shell-release: release image for F""
[pti/rtp.git] / meta-starlingx / meta-stx-integ / recipes-core / systemd / files / 0900-inject-milisec-in-syslog-date.patch
1 From 5ef6dbb951246912ba021f9e2edacd0f9e7619e6 Mon Sep 17 00:00:00 2001
2 From: "Sar Ashki, Babak" <Babak.SarAshki@windriver.com>
3 Date: Sat, 29 Feb 2020 12:48:57 -0800
4 Subject: [PATCH] inject milisec in syslog date
5
6 From stx.3.0: 0231aba5cdcb96b15106591acfff280159050366
7 ---
8  src/journal/journald-syslog.c | 45 +++++++++++++++++++++++++++++++----
9  1 file changed, 40 insertions(+), 5 deletions(-)
10
11 diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
12 index a60a259bc4..0036750353 100644
13 --- a/src/journal/journald-syslog.c
14 +++ b/src/journal/journald-syslog.c
15 @@ -25,6 +25,44 @@
16  /* Warn once every 30s if we missed syslog message */
17  #define WARN_FORWARD_SYSLOG_MISSED_USEC (30 * USEC_PER_SEC)
18  
19 +/*  internal function that builds a formatted time str of the
20 + *  tv parameter into the passed buffer. (ie Nov  7 16:28:38.109)
21 + *  If tv is NULL, then the clock function is used to build the formatted time
22 + *  returns (same as snprintf) - number of characters written to buffer.
23 + */
24 +static int formatSyslogDate(char * buffer, int bufLen, const struct timeval *tv) {
25 +  struct timeval tv_tmp;
26 +  long int millisec;
27 +  char tmpbuf[64];
28 +  struct tm *tm;
29 +  time_t t;
30 +
31 +  if (!tv) {
32 +      // no timeval input so get time data from clock
33 +      usec_t now_usec  = now(CLOCK_REALTIME);
34 +      time_t now_sec = ((time_t) now_usec / USEC_PER_SEC);
35 +      long int now_fraction_secs = now_usec % USEC_PER_SEC;
36 +      tv_tmp.tv_sec = now_sec;
37 +      tv_tmp.tv_usec = now_fraction_secs;
38 +      tv = &tv_tmp;
39 +  }
40 +
41 +  t = tv->tv_sec;
42 +  tm = localtime(&t);
43 +  if (!tm)
44 +     return 0;
45 +
46 +  // format time to the second granularity - ie Nov  7 16:28:38
47 +  if (strftime(tmpbuf,sizeof(tmpbuf),"%h %e %T", tm) <= 0)
48 +     return 0;
49 +
50 +  millisec = tv->tv_usec / 1000;
51 +  // now append millisecond granularity (ie Nov  7 16:28:38.109) to
52 +  // the formatted string.
53 +  return snprintf(buffer, bufLen, "%s.%03lu", tmpbuf, millisec);
54 +}
55 +
56 +
57  static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned n_iovec, const struct ucred *ucred, const struct timeval *tv) {
58  
59          static const union sockaddr_union sa = {
60 @@ -133,11 +171,8 @@ void server_forward_syslog(Server *s, int priority, const char *identifier, cons
61          iovec[n++] = IOVEC_MAKE_STRING(header_priority);
62  
63          /* Second: timestamp */
64 -        t = tv ? tv->tv_sec : ((time_t) (now(CLOCK_REALTIME) / USEC_PER_SEC));
65 -        if (!localtime_r(&t, &tm))
66 -                return;
67 -        if (strftime(header_time, sizeof(header_time), "%h %e %T ", &tm) <= 0)
68 -                return;
69 +       if (formatSyslogDate(header_time, sizeof(header_time), tv) <=0 )
70 +               return;
71          iovec[n++] = IOVEC_MAKE_STRING(header_time);
72  
73          /* Third: identifier and PID */
74 -- 
75 2.23.0
76