ad58010
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2e4660d
From: Peter Jones <pjones@redhat.com>
2e4660d
Date: Thu, 30 Nov 2017 15:11:39 -0500
902c8e8
Subject: [PATCH] Add grub_debug_enabled()
2e4660d
2e4660d
---
2e4660d
 grub-core/kern/misc.c | 21 ++++++++++++++++-----
2e4660d
 include/grub/misc.h   |  1 +
2e4660d
 2 files changed, 17 insertions(+), 5 deletions(-)
2e4660d
2e4660d
diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c
2e4660d
index 636f97e1ba1..e758ab3416d 100644
2e4660d
--- a/grub-core/kern/misc.c
2e4660d
+++ b/grub-core/kern/misc.c
2e4660d
@@ -159,17 +159,28 @@ int grub_err_printf (const char *fmt, ...)
2e4660d
 __attribute__ ((alias("grub_printf")));
2e4660d
 #endif
2e4660d
 
2e4660d
+int
2e4660d
+grub_debug_enabled (const char * condition)
2e4660d
+{
2e4660d
+  const char *debug;
2e4660d
+
2e4660d
+  debug = grub_env_get ("debug");
2e4660d
+  if (!debug)
2e4660d
+    return 0;
2e4660d
+
2e4660d
+  if (grub_strword (debug, "all") || grub_strword (debug, condition))
2e4660d
+    return 1;
2e4660d
+
2e4660d
+  return 0;
2e4660d
+}
2e4660d
+
2e4660d
 void
2e4660d
 grub_real_dprintf (const char *file, const int line, const char *condition,
2e4660d
 		   const char *fmt, ...)
2e4660d
 {
2e4660d
   va_list args;
2e4660d
-  const char *debug = grub_env_get ("debug");
2e4660d
 
2e4660d
-  if (! debug)
2e4660d
-    return;
2e4660d
-
2e4660d
-  if (grub_strword (debug, "all") || grub_strword (debug, condition))
2e4660d
+  if (grub_debug_enabled (condition))
2e4660d
     {
2e4660d
       grub_printf ("%s:%d: ", file, line);
2e4660d
       va_start (args, fmt);
2e4660d
diff --git a/include/grub/misc.h b/include/grub/misc.h
5a73eab
index cbfae75a1b4..f7473c154f0 100644
2e4660d
--- a/include/grub/misc.h
2e4660d
+++ b/include/grub/misc.h
2e4660d
@@ -367,6 +367,7 @@ grub_puts (const char *s)
2e4660d
 }
2e4660d
 
2e4660d
 int EXPORT_FUNC(grub_puts_) (const char *s);
2e4660d
+int EXPORT_FUNC(grub_debug_enabled) (const char *condition);
2e4660d
 void EXPORT_FUNC(grub_real_dprintf) (const char *file,
2e4660d
                                      const int line,
2e4660d
                                      const char *condition,