summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-04-03 09:13:37 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-04-03 09:13:37 +0200
commit6bfb1daff14344b74c034238980390190d4faa69 (patch)
tree0425f4b5d170aa97875789ef1669fda9bba97f65
parentcore: use a temporary variable for calculation of seccomp flags (diff)
downloadsystemd-6bfb1daff14344b74c034238980390190d4faa69.tar.xz
systemd-6bfb1daff14344b74c034238980390190d4faa69.zip
basic/log: log any available location information in log_syntax()
We would log "(null):0: Failed to parse system call, ignoring: rseq" from log_syntax_internal() from log_syntax() from seccomp_parse_syscall_filter_full() from seccomp_parse_syscall_filter() from config_parse_syscall_filter(), when generating the built-in @default whitelist. Since it was not based on the unit file, we would not pass a file name. So let's make sure that log_syntax() does not print "(null)" pointer (which is iffy and ugly), and use the unit name as fallback or nothing if both are missing. In principle, one of the two should be always available, since why use log_syntax() otherwise, but let's make things more resilient by guarding against this case too. log_syntax() is called from a thousand places, and often in error path, so it's hard to verify all callers.
-rw-r--r--src/basic/log.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/basic/log.c b/src/basic/log.c
index 37a5ffa74f..ea252c4130 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -1231,16 +1231,34 @@ int log_syntax_internal(
if (unit)
unit_fmt = getpid_cached() == 1 ? "UNIT=%s" : "USER_UNIT=%s";
- return log_struct_internal(
- LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, level),
- error,
- file, line, func,
- "MESSAGE_ID=" SD_MESSAGE_INVALID_CONFIGURATION_STR,
- "CONFIG_FILE=%s", config_file,
- "CONFIG_LINE=%u", config_line,
- LOG_MESSAGE("%s:%u: %s", config_file, config_line, buffer),
- unit_fmt, unit,
- NULL);
+ if (config_file)
+ return log_struct_internal(
+ LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, level),
+ error,
+ file, line, func,
+ "MESSAGE_ID=" SD_MESSAGE_INVALID_CONFIGURATION_STR,
+ "CONFIG_FILE=%s", config_file,
+ "CONFIG_LINE=%u", config_line,
+ LOG_MESSAGE("%s:%u: %s", config_file, config_line, buffer),
+ unit_fmt, unit,
+ NULL);
+ else if (unit)
+ return log_struct_internal(
+ LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, level),
+ error,
+ file, line, func,
+ "MESSAGE_ID=" SD_MESSAGE_INVALID_CONFIGURATION_STR,
+ LOG_MESSAGE("%s: %s", unit, buffer),
+ unit_fmt, unit,
+ NULL);
+ else
+ return log_struct_internal(
+ LOG_REALM_PLUS_LEVEL(LOG_REALM_SYSTEMD, level),
+ error,
+ file, line, func,
+ "MESSAGE_ID=" SD_MESSAGE_INVALID_CONFIGURATION_STR,
+ LOG_MESSAGE("%s", buffer),
+ NULL);
}
int log_syntax_invalid_utf8_internal(