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