summaryrefslogtreecommitdiffstats
path: root/include/debug.h
diff options
context:
space:
mode:
authorOndrej Oprala2014-07-31 13:23:07 +0200
committerKarel Zak2014-08-13 12:33:47 +0200
commit14ad2353ccabc330412baff5fe86592f2618cdee (patch)
tree43e0d6eb8674c60ba1a6be0d879f3d62d28c9a51 /include/debug.h
parentlibfdisk: rename fdisk_column to fdisk_field (diff)
downloadkernel-qcow2-util-linux-14ad2353ccabc330412baff5fe86592f2618cdee.tar.gz
kernel-qcow2-util-linux-14ad2353ccabc330412baff5fe86592f2618cdee.tar.xz
kernel-qcow2-util-linux-14ad2353ccabc330412baff5fe86592f2618cdee.zip
libs/debug: accept human readable names for _DEBUG=
For example $ LIBMOUNT_DEBUG=tab,cache findmnt to debug only TAB and CACHE subsystem. Signed-off-by: Ondrej Oprala <ooprala@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/debug.h')
-rw-r--r--include/debug.h42
1 files changed, 41 insertions, 1 deletions
diff --git a/include/debug.h b/include/debug.h
index 2eb9d4421..1497490b5 100644
--- a/include/debug.h
+++ b/include/debug.h
@@ -8,6 +8,7 @@
#define UTIL_LINUX_DEBUG_H
#include <stdarg.h>
+#include <string.h>
#define UL_DEBUG_DEFINE_MASK(m) int m ## _debug_mask
#define UL_DEBUG_DECLARE_MASK(m) extern UL_DEBUG_DEFINE_MASK(m)
@@ -47,7 +48,7 @@
else if (!mask) { \
char *str = getenv(# env); \
if (str) \
- lib ## _debug_mask = strtoul(str, 0, 0); \
+ lib ## _debug_mask = parse_envmask(lib ## _masknames, str); \
} else \
lib ## _debug_mask = mask; \
lib ## _debug_mask |= pref ## INIT; \
@@ -57,6 +58,8 @@
} \
} while (0)
+struct dbg_mask { char *mname; int val; };
+
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
ul_debug(const char *mesg, ...)
{
@@ -80,4 +83,41 @@ ul_debugobj(void *handler, const char *mesg, ...)
fputc('\n', stderr);
}
+static inline int parse_envmask(const struct dbg_mask const flagnames[],
+ const char *mask)
+{
+ int res;
+ char *ptr;
+
+ /* let's check for a numeric mask first */
+ res = strtoul(mask, &ptr, 0);
+
+ /* perhaps it's a comma-separated string? */
+ if (*ptr != '\0') {
+ char *msbuf, *ms, *name;
+ res = 0;
+
+ ms = msbuf = strdup(mask);
+ if (!ms)
+ return res;
+
+ while ((name = strtok_r(ms, ",", &ptr))) {
+ size_t i = 0;
+ ms = ptr;
+
+ while (flagnames[i].mname) {
+ if (!strcmp(name, flagnames[i].mname)) {
+ res |= flagnames[i].val;
+ break;
+ }
+ ++i;
+ }
+ /* nothing else we can do by OR-ing the mask */
+ if (res == 0xffff)
+ break;
+ }
+ free(msbuf);
+ }
+ return res;
+}
#endif /* UTIL_LINUX_DEBUG_H */