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

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