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