summaryrefslogtreecommitdiffstats
path: root/include/debug.h
diff options
context:
space:
mode:
authorKarel Zak2018-01-17 13:58:29 +0100
committerKarel Zak2018-01-17 13:58:29 +0100
commita15dca2f6d0693546138a6a727f019dd8019dee8 (patch)
tree4ca90e704fea0743180867f7ab7f0592672f8562 /include/debug.h
parenthwclock: rename --debug option to --verbose (diff)
downloadkernel-qcow2-util-linux-a15dca2f6d0693546138a6a727f019dd8019dee8.tar.gz
kernel-qcow2-util-linux-a15dca2f6d0693546138a6a727f019dd8019dee8.tar.xz
kernel-qcow2-util-linux-a15dca2f6d0693546138a6a727f019dd8019dee8.zip
include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables. Suggested-by: J William Piggott <elseifthen@gmx.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/debug.h')
-rw-r--r--include/debug.h19
1 files changed, 12 insertions, 7 deletions
diff --git a/include/debug.h b/include/debug.h
index ff51e04d9..39c21d563 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -83,15 +83,12 @@ struct ul_debug_maskname {
} \
} while (0)
-
-#define __UL_INIT_DEBUG(lib, pref, mask, env) \
+#define __UL_INIT_DEBUG_FROM_STRING(lib, pref, mask, str) \
do { \
if (lib ## _debug_mask & pref ## INIT) \
; \
- else if (!mask) { \
- char *str = getenv(# env); \
- if (str) \
- lib ## _debug_mask = ul_debug_parse_envmask(lib ## _masknames, str); \
+ else if (!mask && str) { \
+ lib ## _debug_mask = ul_debug_parse_mask(lib ## _masknames, str); \
} else \
lib ## _debug_mask = mask; \
if (lib ## _debug_mask) { \
@@ -104,6 +101,14 @@ struct ul_debug_maskname {
} while (0)
+#define __UL_INIT_DEBUG_FROM_ENV(lib, pref, mask, env) \
+ do { \
+ const char *envstr = mask ? NULL : getenv(# env); \
+ __UL_INIT_DEBUG_FROM_STRING(lib, pref, mask, envstr); \
+ } while (0)
+
+
+
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
ul_debug(const char *mesg, ...)
{
@@ -114,7 +119,7 @@ ul_debug(const char *mesg, ...)
fputc('\n', stderr);
}
-static inline int ul_debug_parse_envmask(
+static inline int ul_debug_parse_mask(
const struct ul_debug_maskname flagnames[],
const char *mask)
{