diff options
author | Thomas Haller <thaller@redhat.com> | 2019-05-14 12:28:22 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-05-17 21:12:38 +0200 |
commit | cc2553e871ca7cff7e4e3f5d92321a6789731b4d (patch) | |
tree | ab1462d7e2010a7ccd535a019b2b0e464efe72e4 | |
parent | 467ac96dd1e71d3c3868671001cca4fb5954dc17 (diff) | |
download | NetworkManager-cc2553e871ca7cff7e4e3f5d92321a6789731b4d.tar.gz |
logging: don't misuse SYSLOG_FACILITY field in journal
Syslog's "facility" is a well defined thing and must be
one of a few well-known numbers. Don't re-use it for our
own purposes.
Fixes: 1b808d3b255c ('logging: add native systemd-journald support to nm-logging')
https://bugzilla.redhat.com/show_bug.cgi?id=1709741
-rw-r--r-- | src/nm-logging.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/nm-logging.c b/src/nm-logging.c index 7b6b2f7a12..4fea7595f7 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -627,6 +627,8 @@ _iovec_set_string (struct iovec *iov, const char *str) _iovec_set (iov, str, strlen (str)); } +#define _iovec_set_string_literal(iov, str) _iovec_set ((iov), ""str"", NM_STRLEN (str)) + _nm_printf (3, 4) static void _iovec_set_format (struct iovec *iov, char **iov_free, const char *format, ...) @@ -746,8 +748,7 @@ _nm_log_impl (const char *file, case LOG_BACKEND_JOURNAL: { gint64 now, boottime; -#define _NUM_MAX_FIELDS_SYSLOG_FACILITY 10 - struct iovec iov_data[14 + _NUM_MAX_FIELDS_SYSLOG_FACILITY]; + struct iovec iov_data[15]; struct iovec *iov = iov_data; char *iov_free_data[5]; char **iov_free = iov_free_data; @@ -762,12 +763,10 @@ _nm_log_impl (const char *file, _iovec_set_format_a (iov++, 30, "SYSLOG_PID=%ld", (long) getpid ()); { const LogDesc *diter; - int i_domain = _NUM_MAX_FIELDS_SYSLOG_FACILITY; const char *s_domain_1 = NULL; NMLogDomain dom_all = domain; - NMLogDomain dom = dom_all & cur_log_state[level]; - for (diter = &domain_desc[0]; diter->name; diter++) { + for (diter = &domain_desc[0]; dom_all != 0 && diter->name; diter++) { if (!NM_FLAGS_ANY (dom_all, diter->num)) continue; @@ -785,23 +784,14 @@ _nm_log_impl (const char *file, g_string_append_c (s_domain_all, ','); g_string_append (s_domain_all, diter->name); } - - if (NM_FLAGS_ANY (dom, diter->num)) { - if (i_domain > 0) { - /* SYSLOG_FACILITY is specified multiple times for each domain that is actually enabled. */ - _iovec_set_format_str_a (iov++, 30, "SYSLOG_FACILITY=%s", diter->name); - i_domain--; - } - dom &= ~diter->num; - } - if (!dom && !dom_all) - break; } if (s_domain_all) _iovec_set (iov++, s_domain_all->str, s_domain_all->len); else _iovec_set_format_str_a (iov++, 30, "NM_LOG_DOMAINS=%s", s_domain_1); } + G_STATIC_ASSERT_EXPR (LOG_FAC (LOG_DAEMON) == 3); + _iovec_set_string_literal (iov++, "SYSLOG_FACILITY=3"); _iovec_set_format_str_a (iov++, 15, "NM_LOG_LEVEL=%s", level_desc[level].name); if (func) _iovec_set_format (iov++, iov_free++, "CODE_FUNC=%s", func); @@ -916,7 +906,7 @@ nm_log_handler (const char *log_domain, "MESSAGE=%s%s", gl.imm.prefix, message ?: "", syslog_identifier_full (gl.imm.syslog_identifier), "SYSLOG_PID=%ld", (long) getpid (), - "SYSLOG_FACILITY=GLIB", + "SYSLOG_FACILITY=3", "GLIB_DOMAIN=%s", log_domain ?: "", "GLIB_LEVEL=%d", (int) (level & G_LOG_LEVEL_MASK), "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000), |