lbalhar / rpms / pulseaudio

Forked from rpms/pulseaudio 4 years ago
Clone
Blob Blame History Raw
From 21b484e056be445fdaf00f91ce50bc40b1ac9623 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 13 Jan 2010 17:35:04 +0100
Subject: [PATCH 11/62] log: add an easy way to disable log rate limiting

Should help with debuggin bugs like:

https://bugzilla.redhat.com/show_bug.cgi?id=554405
---
 src/pulsecore/log.c |   88 +++++++++++++++++++++++++++++----------------------
 1 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/src/pulsecore/log.c b/src/pulsecore/log.c
index 8c21ee6..0c5a317 100644
--- a/src/pulsecore/log.c
+++ b/src/pulsecore/log.c
@@ -61,6 +61,7 @@
 #define ENV_LOG_PRINT_LEVEL "PULSE_LOG_LEVEL"
 #define ENV_LOG_BACKTRACE "PULSE_LOG_BACKTRACE"
 #define ENV_LOG_BACKTRACE_SKIP "PULSE_LOG_BACKTRACE_SKIP"
+#define ENV_LOG_NO_RATELIMIT "PULSE_LOG_NO_RATE_LIMIT"
 
 static char *ident = NULL; /* in local charset format */
 static pa_log_target_t target = PA_LOG_STDERR, target_override;
@@ -68,6 +69,7 @@ static pa_bool_t target_override_set = FALSE;
 static pa_log_level_t maximum_level = PA_LOG_ERROR, maximum_level_override = PA_LOG_ERROR;
 static unsigned show_backtrace = 0, show_backtrace_override = 0, skip_backtrace = 0;
 static pa_log_flags_t flags = 0, flags_override = 0;
+static pa_bool_t no_rate_limit = FALSE;
 
 #ifdef HAVE_SYSLOG_H
 static const int level_to_syslog[] = {
@@ -195,54 +197,61 @@ static char* get_backtrace(unsigned show_nframes) {
 #endif
 
 static void init_defaults(void) {
-    const char *e;
+    PA_ONCE_BEGIN {
 
-    if (!ident) {
-        char binary[256];
-        if (pa_get_binary_name(binary, sizeof(binary)))
-            pa_log_set_ident(binary);
-    }
+        const char *e;
 
-    if (getenv(ENV_LOG_SYSLOG)) {
-        target_override = PA_LOG_SYSLOG;
-        target_override_set = TRUE;
-    }
+        if (!ident) {
+            char binary[256];
+            if (pa_get_binary_name(binary, sizeof(binary)))
+                pa_log_set_ident(binary);
+        }
 
-    if ((e = getenv(ENV_LOG_LEVEL))) {
-        maximum_level_override = (pa_log_level_t) atoi(e);
+        if (getenv(ENV_LOG_SYSLOG)) {
+            target_override = PA_LOG_SYSLOG;
+            target_override_set = TRUE;
+        }
 
-        if (maximum_level_override >= PA_LOG_LEVEL_MAX)
-            maximum_level_override = PA_LOG_LEVEL_MAX-1;
-    }
+        if ((e = getenv(ENV_LOG_LEVEL))) {
+            maximum_level_override = (pa_log_level_t) atoi(e);
 
-    if (getenv(ENV_LOG_COLORS))
-        flags_override |= PA_LOG_COLORS;
+            if (maximum_level_override >= PA_LOG_LEVEL_MAX)
+                maximum_level_override = PA_LOG_LEVEL_MAX-1;
+        }
 
-    if (getenv(ENV_LOG_PRINT_TIME))
-        flags_override |= PA_LOG_PRINT_TIME;
+        if (getenv(ENV_LOG_COLORS))
+            flags_override |= PA_LOG_COLORS;
 
-    if (getenv(ENV_LOG_PRINT_FILE))
-        flags_override |= PA_LOG_PRINT_FILE;
+        if (getenv(ENV_LOG_PRINT_TIME))
+            flags_override |= PA_LOG_PRINT_TIME;
 
-    if (getenv(ENV_LOG_PRINT_META))
-        flags_override |= PA_LOG_PRINT_META;
+        if (getenv(ENV_LOG_PRINT_FILE))
+            flags_override |= PA_LOG_PRINT_FILE;
 
-    if (getenv(ENV_LOG_PRINT_LEVEL))
-        flags_override |= PA_LOG_PRINT_LEVEL;
+        if (getenv(ENV_LOG_PRINT_META))
+            flags_override |= PA_LOG_PRINT_META;
 
-    if ((e = getenv(ENV_LOG_BACKTRACE))) {
-        show_backtrace_override = (unsigned) atoi(e);
+        if (getenv(ENV_LOG_PRINT_LEVEL))
+            flags_override |= PA_LOG_PRINT_LEVEL;
 
-        if (show_backtrace_override <= 0)
-            show_backtrace_override = 0;
-    }
+        if ((e = getenv(ENV_LOG_BACKTRACE))) {
+            show_backtrace_override = (unsigned) atoi(e);
 
-    if ((e = getenv(ENV_LOG_BACKTRACE_SKIP))) {
-        skip_backtrace = (unsigned) atoi(e);
+            if (show_backtrace_override <= 0)
+                show_backtrace_override = 0;
+        }
 
-        if (skip_backtrace <= 0)
-            skip_backtrace = 0;
-    }
+        if ((e = getenv(ENV_LOG_BACKTRACE_SKIP))) {
+            skip_backtrace = (unsigned) atoi(e);
+
+            if (skip_backtrace <= 0)
+                skip_backtrace = 0;
+        }
+
+        if (getenv(ENV_LOG_NO_RATELIMIT))
+            no_rate_limit = TRUE;
+
+    } PA_ONCE_END;
 }
 
 void pa_log_levelv_meta(
@@ -268,9 +277,7 @@ void pa_log_levelv_meta(
     pa_assert(level < PA_LOG_LEVEL_MAX);
     pa_assert(format);
 
-    PA_ONCE_BEGIN {
-        init_defaults();
-    } PA_ONCE_END;
+    init_defaults();
 
     _target = target_override_set ? target_override : target;
     _maximum_level = PA_MAX(maximum_level, maximum_level_override);
@@ -428,5 +435,10 @@ pa_bool_t pa_log_ratelimit(void) {
     /* Not more than 10 messages every 5s */
     static PA_DEFINE_RATELIMIT(ratelimit, 5 * PA_USEC_PER_SEC, 10);
 
+    init_defaults();
+
+    if (no_rate_limit)
+        return TRUE;
+
     return pa_ratelimit_test(&ratelimit);
 }
-- 
1.7.0