]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: add new "prohibit_ipc" flag to logging system
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Jan 2018 16:36:25 +0000 (17:36 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 24 Jan 2018 17:22:56 +0000 (18:22 +0100)
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

src/basic/log.c
src/basic/log.h

index 8a65aa349e4725bcc724fdb0b8fdb08f0bd6759b..ae0ac72b579a66ecdff1f8af9d63da45e436da50 100644 (file)
@@ -77,6 +77,7 @@ static bool show_location = false;
 static bool upgrade_syslog_to_journal = false;
 static bool always_reopen_console = false;
 static bool open_when_needed = false;
 static bool upgrade_syslog_to_journal = false;
 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. */
 
 /* Akin to glibc's __abort_msg; which is private and we hence cannot
  * use here. */
@@ -254,7 +255,8 @@ int log_open(void) {
             getpid_cached() == 1 ||
             isatty(STDERR_FILENO) <= 0) {
 
             getpid_cached() == 1 ||
             isatty(STDERR_FILENO) <= 0) {
 
-                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();
                                        LOG_TARGET_JOURNAL_OR_KMSG,
                                        LOG_TARGET_JOURNAL)) {
                         r = log_open_journal();
@@ -265,7 +267,8 @@ int log_open(void) {
                         }
                 }
 
                         }
                 }
 
-                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) {
                                        LOG_TARGET_SYSLOG)) {
                         r = log_open_syslog();
                         if (r >= 0) {
@@ -1332,6 +1335,10 @@ void log_set_open_when_needed(bool b) {
         open_when_needed = 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. */
 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. */
index 910a89a25596be51ea60c8441714175c7834afab..0a8fa228662ac603b296e15c13c81934884d545b 100644 (file)
@@ -307,6 +307,10 @@ void log_set_upgrade_syslog_to_journal(bool b);
 void log_set_always_reopen_console(bool b);
 void log_set_open_when_needed(bool b);
 
 void log_set_always_reopen_console(bool b);
 void log_set_open_when_needed(bool b);
 
+/* If turned on, then we'll never use IPC-based logging, i.e. never log to syslog or the journal. We'll only log to
+ * stderr, the console or kmsg */
+void log_set_prohibit_ipc(bool b);
+
 int log_syntax_internal(
                 const char *unit,
                 int level,
 int log_syntax_internal(
                 const char *unit,
                 int level,