chiark / gitweb /
log: don't open log targets too early
[elogind.git] / src / log.c
index bf2382dfafe0bb4407488f6d24d8b00ffdb8f724..265a7f10e28e2ee1d624b899c69320a2c768a897 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -162,6 +162,12 @@ int log_open(void) {
          * the fs. If we don't use /dev/kmsg we still keep it open,
          * because there is no reason to close it. */
 
+        if (log_target == LOG_TARGET_NULL) {
+                log_close_syslog();
+                log_close_console();
+                return 0;
+        }
+
         if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
             log_target == LOG_TARGET_SYSLOG)
                 if ((r = log_open_syslog()) >= 0) {
@@ -316,6 +322,9 @@ static int log_dispatch(
 
         int r = 0;
 
+        if (log_target == LOG_TARGET_NULL)
+                return 0;
+
         do {
                 char *e;
                 int k;
@@ -475,6 +484,7 @@ static const char *const log_target_table[] = {
         [LOG_TARGET_SYSLOG] = "syslog",
         [LOG_TARGET_KMSG] = "kmsg",
         [LOG_TARGET_SYSLOG_OR_KMSG] = "syslog-or-kmsg",
+        [LOG_TARGET_NULL] = "null"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(log_target, LogTarget);