summaryrefslogtreecommitdiff
path: root/src/basic/log.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-01-24 17:36:25 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:50:16 +0200
commit26d26c80c5d80515134e24e0e9829a39bf577dd0 (patch)
treee8f1c3546f7bb11e3ffc9cd1186e98c0326618f7 /src/basic/log.c
parent50cac1201976fbf64285378b7d2422c758cef254 (diff)
log: add new "prohibit_ipc" flag to logging system
If set, we'll avoid logging to any IPC log targets, i.e. syslog or the journal, but allow stderr, kmsg, console logging. This is useful as PID 1 wants to turn this off explicitly as long as the journal is not up. Previously we'd open/close the log stream to these services whenever needed but this is incompatible with the "open_when_needed" logic introduced in #6915, which might open the log streams whenever it likes, including possibly inside of the child process we fork off that'll become journald later on. Hence, let's make this all explicit, and instead of managing when we open/close log streams add a boolean that clearly prohibits the IPC targets when needed, so that opening can be done at any time, but will honour this. See: #7985
Diffstat (limited to 'src/basic/log.c')
-rw-r--r--src/basic/log.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/basic/log.c b/src/basic/log.c
index b01ebaacd..a704e4bed 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -79,6 +79,7 @@ static bool upgrade_syslog_to_journal = false;
#endif // 0
static bool always_reopen_console = false;
static bool open_when_needed = false;
+static bool prohibit_ipc = false;
/* Akin to glibc's __abort_msg; which is private and we hence cannot
* use here. */
@@ -261,7 +262,8 @@ int log_open(void) {
isatty(STDERR_FILENO) <= 0) {
#if 0 /// elogind does not support logging to systemd-journald
- if (IN_SET(log_target, LOG_TARGET_AUTO,
+ if (!prohibit_ipc &&
+ IN_SET(log_target, LOG_TARGET_AUTO,
LOG_TARGET_JOURNAL_OR_KMSG,
LOG_TARGET_JOURNAL)) {
r = log_open_journal();
@@ -273,7 +275,8 @@ int log_open(void) {
}
#endif // 0
- if (IN_SET(log_target, LOG_TARGET_SYSLOG_OR_KMSG,
+ if (!prohibit_ipc &&
+ IN_SET(log_target, LOG_TARGET_SYSLOG_OR_KMSG,
LOG_TARGET_SYSLOG)) {
r = log_open_syslog();
if (r >= 0) {
@@ -1356,6 +1359,10 @@ void log_set_open_when_needed(bool b) {
open_when_needed = b;
}
+void log_set_prohibit_ipc(bool b) {
+ prohibit_ipc = b;
+}
+
int log_emergency_level(void) {
/* Returns the log level to use for log_emergency() logging. We use LOG_EMERG only when we are PID 1, as only
* then the system of the whole system is obviously affected. */