mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
misc: Use 64 bit time_t interfaces on syslog
It also handles the highly unlikely case where localtime might return NULL, in this case only the PRI is set to hopefully instruct the relay to get eh TIMESTAMP (as defined by the RFC). Checked on x86_64-linux-gnu and i686-linux-gnu.
This commit is contained in:
parent
cac6b54ae2
commit
ac0d208b54
@ -153,10 +153,17 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap,
|
||||
|
||||
/* "%b %e %H:%M:%S " */
|
||||
char timestamp[sizeof "MMM DD hh:mm:ss "];
|
||||
time_t now = time_now ();
|
||||
__time64_t now = time64_now ();
|
||||
struct tm now_tm;
|
||||
__localtime_r (&now, &now_tm);
|
||||
__strftime_l (timestamp, sizeof timestamp, "%b %e %T ", &now_tm,
|
||||
struct tm *now_tmp = __localtime64_r (&now, &now_tm);
|
||||
bool has_ts = now_tmp != NULL;
|
||||
|
||||
/* In the unlikely case of localtime_r failure (tm_year out of int range)
|
||||
skip the hostname so the message is handled as valid PRI but without
|
||||
TIMESTAMP or invalid TIMESTAMP (which should force the relay to add the
|
||||
timestamp itself). */
|
||||
if (has_ts)
|
||||
__strftime_l (timestamp, sizeof timestamp, "%h %e %T ", now_tmp,
|
||||
_nl_C_locobj_ptr);
|
||||
|
||||
#define SYSLOG_HEADER(__pri, __timestamp, __msgoff, pid) \
|
||||
@ -165,8 +172,16 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap,
|
||||
LogTag == NULL ? __progname : LogTag, \
|
||||
"[" + (pid == 0), pid, "]" + (pid == 0)
|
||||
|
||||
int l = __snprintf (bufs, sizeof bufs,
|
||||
#define SYSLOG_HEADER_WITHOUT_TS(__pri, __msgoff) \
|
||||
"<%d>: %n", __pri, __msgoff
|
||||
|
||||
int l;
|
||||
if (has_ts)
|
||||
l = __snprintf (bufs, sizeof bufs,
|
||||
SYSLOG_HEADER (pri, timestamp, &msgoff, pid));
|
||||
else
|
||||
l = __snprintf (bufs, sizeof bufs,
|
||||
SYSLOG_HEADER_WITHOUT_TS (pri, &msgoff));
|
||||
if (0 <= l && l < sizeof bufs)
|
||||
{
|
||||
va_list apc;
|
||||
@ -194,8 +209,12 @@ __vsyslog_internal (int pri, const char *fmt, va_list ap,
|
||||
/* Tell the cancellation handler to free this buffer. */
|
||||
clarg.buf = buf;
|
||||
|
||||
__snprintf (buf, sizeof buf,
|
||||
if (has_ts)
|
||||
__snprintf (bufs, sizeof bufs,
|
||||
SYSLOG_HEADER (pri, timestamp, &msgoff, pid));
|
||||
else
|
||||
__snprintf (bufs, sizeof bufs,
|
||||
SYSLOG_HEADER_WITHOUT_TS (pri, &msgoff));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user