Blame SOURCES/0073-logging-test-log-level-at-first-step.patch

28bab8
From c362b6a9c4abb2f4185f5c88b90aecfebd6c67cb Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Thu, 24 Jul 2014 13:34:50 +0200
28bab8
Subject: [LIBREPORT PATCH 73/93] logging: test log level at first step
28bab8
28bab8
Return from the logger immediately if message's log level is not
28bab8
sufficient to write it to the log.
28bab8
28bab8
This patch is a workaround for rhbz#1122690 where we try to log a
28bab8
'post'ed string which has 18MB of size. It is not worth to try to fix it
28bab8
properly. We do not log such a big amount of data in non-debug mode, we
28bab8
need to have the logging extremely fast and we can live with crashes in
28bab8
debug mode.
28bab8
28bab8
Resolves: #1142380
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
---
28bab8
 src/lib/logging.c | 26 +++++++++++---------------
28bab8
 1 file changed, 11 insertions(+), 15 deletions(-)
28bab8
28bab8
diff --git a/src/lib/logging.c b/src/lib/logging.c
28bab8
index 259a634..4b9dd87 100644
28bab8
--- a/src/lib/logging.c
28bab8
+++ b/src/lib/logging.c
28bab8
@@ -66,7 +66,7 @@ static void log_handler(int level,
28bab8
                         int line,
28bab8
                         const char *func)
28bab8
 {
28bab8
-    if (!logmode)
28bab8
+    if (!logmode || !should_log(level))
28bab8
         return;
28bab8
 
28bab8
     /* This is ugly and costs +60 bytes compared to multiple
28bab8
@@ -122,29 +122,25 @@ static void log_handler(int level,
28bab8
     strcpy(&msg[used], msg_eol);
28bab8
 
28bab8
     if (flags & LOGMODE_STDIO) {
28bab8
-        if(should_log(level))
28bab8
-            full_write(STDERR_FILENO, msg, used + msgeol_len);
28bab8
+        full_write(STDERR_FILENO, msg, used + msgeol_len);
28bab8
     }
28bab8
     msg[used] = '\0'; /* remove msg_eol (usually "\n") */
28bab8
     if (flags & LOGMODE_SYSLOG) {
28bab8
-        if(should_log(level))
28bab8
-            syslog(level, "%s", msg + prefix_len);
28bab8
+        syslog(level, "%s", msg + prefix_len);
28bab8
     }
28bab8
 
28bab8
     if ((flags & LOGMODE_CUSTOM) && g_custom_logger) {
28bab8
-        if(should_log(level))
28bab8
-            g_custom_logger(msg + prefix_len);
28bab8
+        g_custom_logger(msg + prefix_len);
28bab8
     }
28bab8
 
28bab8
     if (flags & LOGMODE_JOURNAL) {
28bab8
-        if(should_log(level))
28bab8
-            sd_journal_send("MESSAGE=%s", msg + prefix_len,
28bab8
-                            "PRIORITY=%d", level,
28bab8
-                            "CODE_FILE=%s", file,
28bab8
-                            "CODE_LINE=%d", line,
28bab8
-                            "CODE_FUNC=%s", func,
28bab8
-                            "SYSLOG_FACILITY=1",
28bab8
-                            NULL);
28bab8
+        sd_journal_send("MESSAGE=%s", msg + prefix_len,
28bab8
+                        "PRIORITY=%d", level,
28bab8
+                        "CODE_FILE=%s", file,
28bab8
+                        "CODE_LINE=%d", line,
28bab8
+                        "CODE_FUNC=%s", func,
28bab8
+                        "SYSLOG_FACILITY=1",
28bab8
+                        NULL);
28bab8
     }
28bab8
 }
28bab8
 
28bab8
-- 
28bab8
1.8.3.1
28bab8