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