chiark / gitweb /
log: add null log target
authorLennart Poettering <lennart@poettering.net>
Wed, 9 Jun 2010 13:37:37 +0000 (15:37 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 9 Jun 2010 13:37:40 +0000 (15:37 +0200)
src/log.c
src/log.h

index bf2382d..94fb823 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) {
@@ -186,6 +192,7 @@ void log_set_target(LogTarget target) {
         assert(target < _LOG_TARGET_MAX);
 
         log_target = target;
+        log_open();
 }
 
 void log_set_max_level(int level) {
@@ -316,6 +323,9 @@ static int log_dispatch(
 
         int r = 0;
 
+        if (log_target == LOG_TARGET_NULL)
+                return 0;
+
         do {
                 char *e;
                 int k;
@@ -475,6 +485,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);
index 9d141dc..1d9a100 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -33,6 +33,7 @@ typedef enum LogTarget{
         LOG_TARGET_KMSG,
         LOG_TARGET_SYSLOG,
         LOG_TARGET_SYSLOG_OR_KMSG,
+        LOG_TARGET_NULL,
         _LOG_TARGET_MAX,
         _LOG_TARGET_INVALID = -1
 }  LogTarget;