Blame SOURCES/Always-choose-highest-requested-debug-level.patch

e8d79a
From d284ec7dc9fe0a824b177873078aeb36a25b7878 Mon Sep 17 00:00:00 2001
e8d79a
From: Robbie Harwood <rharwood@redhat.com>
e8d79a
Date: Wed, 11 Apr 2018 16:15:00 -0400
e8d79a
Subject: [PATCH] Always choose highest requested debug level
e8d79a
e8d79a
Allowing the CLI to lower the debug level specified in a config file
e8d79a
is dubious, and previously broken since we don't distinguish "default
e8d79a
value" from "explicitly requested value of 0" in popt.  This resulted
e8d79a
in "Debug Enabled (level: 0)" even when the log level was not actually
e8d79a
0, which is confusing for users.
e8d79a
e8d79a
Remove the gp_debug_args() function since it is no longer used.
e8d79a
e8d79a
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
e8d79a
Reviewed-by: Simo Sorce <simo@redhat.com>
e8d79a
Merges: #229
e8d79a
(cherry picked from commit 5a714768aec776dc875237dd729c85389932a688)
e8d79a
---
e8d79a
 src/gp_debug.c | 34 ++++++++--------------------------
e8d79a
 src/gp_debug.h |  3 +--
e8d79a
 src/gssproxy.c |  2 +-
e8d79a
 3 files changed, 10 insertions(+), 29 deletions(-)
e8d79a
e8d79a
diff --git a/src/gp_debug.c b/src/gp_debug.c
e8d79a
index 4a141fc..a0f51f0 100644
e8d79a
--- a/src/gp_debug.c
e8d79a
+++ b/src/gp_debug.c
e8d79a
@@ -1,4 +1,4 @@
e8d79a
-/* Copyright (C) 2011 the GSS-PROXY contributors, see COPYING for license */
e8d79a
+/* Copyright (C) 2011,2018 the GSS-PROXY contributors, see COPYING for license */
e8d79a
 
e8d79a
 #include "config.h"
e8d79a
 #include <stdbool.h>
e8d79a
@@ -7,35 +7,17 @@
e8d79a
 #include "gp_log.h"
e8d79a
 
e8d79a
 /* global debug switch */
e8d79a
-int gp_debug;
e8d79a
-
e8d79a
-int gp_debug_args(int level) {
e8d79a
-    static int args_level = 0;
e8d79a
-
e8d79a
-    if (level != 0) {
e8d79a
-        args_level = level;
e8d79a
-    }
e8d79a
-    return args_level;
e8d79a
-}
e8d79a
+int gp_debug = 0;
e8d79a
 
e8d79a
 void gp_debug_toggle(int level)
e8d79a
 {
e8d79a
-    static bool krb5_trace_set = false;
e8d79a
+    if (level <= gp_debug)
e8d79a
+        return;
e8d79a
 
e8d79a
-    /* Command line and environment options override config file */
e8d79a
-    gp_debug = gp_debug_args(0);
e8d79a
-    if (gp_debug == 0) {
e8d79a
-        gp_debug = level;
e8d79a
-    }
e8d79a
-    if (level >= 3) {
e8d79a
-        if (!getenv("KRB5_TRACE")) {
e8d79a
-            setenv("KRB5_TRACE", "/dev/stderr", 1);
e8d79a
-            krb5_trace_set = true;
e8d79a
-        }
e8d79a
-    } else if (krb5_trace_set) {
e8d79a
-        unsetenv("KRB5_TRACE");
e8d79a
-        krb5_trace_set = false;
e8d79a
-    }
e8d79a
+    if (level >= 3 && !getenv("KRB5_TRACE"))
e8d79a
+        setenv("KRB5_TRACE", "/dev/stderr", 1);
e8d79a
+
e8d79a
+    gp_debug = level;
e8d79a
     GPDEBUG("Debug Enabled (level: %d)\n", level);
e8d79a
 }
e8d79a
 
e8d79a
diff --git a/src/gp_debug.h b/src/gp_debug.h
e8d79a
index 1c2f8a3..4932bfd 100644
e8d79a
--- a/src/gp_debug.h
e8d79a
+++ b/src/gp_debug.h
e8d79a
@@ -1,4 +1,4 @@
e8d79a
-/* Copyright (C) 2011 the GSS-PROXY contributors, see COPYING for license */
e8d79a
+/* Copyright (C) 2011,2018 the GSS-PROXY contributors, see COPYING for license */
e8d79a
 
e8d79a
 #ifndef _GP_DEBUG_H_
e8d79a
 #define _GP_DEBUG_H_
e8d79a
@@ -10,7 +10,6 @@
e8d79a
 
e8d79a
 extern int gp_debug;
e8d79a
 
e8d79a
-int gp_debug_args(int level);
e8d79a
 void gp_debug_toggle(int);
e8d79a
 void gp_debug_printf(const char *format, ...);
e8d79a
 void gp_debug_time_printf(const char *format, ...);
e8d79a
diff --git a/src/gssproxy.c b/src/gssproxy.c
e8d79a
index 6d36a5d..db6e89b 100644
e8d79a
--- a/src/gssproxy.c
e8d79a
+++ b/src/gssproxy.c
e8d79a
@@ -208,7 +208,7 @@ int main(int argc, const char *argv[])
e8d79a
 
e8d79a
     if (opt_debug || opt_debug_level > 0) {
e8d79a
         if (opt_debug_level == 0) opt_debug_level = 1;
e8d79a
-        gp_debug_args(opt_debug_level);
e8d79a
+        gp_debug_toggle(opt_debug_level);
e8d79a
     }
e8d79a
 
e8d79a
     if (opt_daemon && opt_interactive) {