diff options
author | Ondrej Oprala | 2014-07-31 13:23:07 +0200 |
---|---|---|
committer | Karel Zak | 2014-08-13 12:33:47 +0200 |
commit | 14ad2353ccabc330412baff5fe86592f2618cdee (patch) | |
tree | 43e0d6eb8674c60ba1a6be0d879f3d62d28c9a51 | |
parent | libfdisk: rename fdisk_column to fdisk_field (diff) | |
download | kernel-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>
-rw-r--r-- | include/debug.h | 42 | ||||
-rw-r--r-- | libblkid/src/init.c | 19 | ||||
-rw-r--r-- | libfdisk/src/init.c | 12 | ||||
-rw-r--r-- | libmount/src/Makemodule.am | 8 | ||||
-rw-r--r-- | libmount/src/init.c | 44 | ||||
-rw-r--r-- | libsmartcols/src/init.c | 9 | ||||
-rw-r--r-- | tests/commands.sh | 1 |
7 files changed, 132 insertions, 3 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 */ diff --git a/libblkid/src/init.c b/libblkid/src/init.c index 5b21ce331..61fe5d45e 100644 --- a/libblkid/src/init.c +++ b/libblkid/src/init.c @@ -17,6 +17,25 @@ UL_DEBUG_DEFINE_MASK(libblkid); +static const struct dbg_mask libblkid_masknames [] = { + { "all", BLKID_DEBUG_ALL }, + { "cache", BLKID_DEBUG_CACHE }, + { "dump", BLKID_DEBUG_DUMP }, + { "dev", BLKID_DEBUG_DEV }, + { "devname", BLKID_DEBUG_DEVNAME }, + { "devno", BLKID_DEBUG_DEVNO }, + { "probe", BLKID_DEBUG_PROBE }, + { "read", BLKID_DEBUG_READ }, + { "resolve", BLKID_DEBUG_RESOLVE }, + { "save", BLKID_DEBUG_SAVE }, + { "tag", BLKID_DEBUG_TAG }, + { "lowprobe", BLKID_DEBUG_LOWPROBE }, + { "config", BLKID_DEBUG_CONFIG }, + { "evaluate", BLKID_DEBUG_EVALUATE }, + { "init", BLKID_DEBUG_INIT }, + { NULL, 0 } +}; + /** * blkid_init_debug: * @mask: debug mask (0xffff to enable full debuging) diff --git a/libfdisk/src/init.c b/libfdisk/src/init.c index e30c8b976..87217cbd7 100644 --- a/libfdisk/src/init.c +++ b/libfdisk/src/init.c @@ -3,6 +3,18 @@ UL_DEBUG_DEFINE_MASK(libfdisk); +static const struct dbg_mask libfdisk_masknames[] = { + { "all", FDISK_DEBUG_ALL }, + { "init", FDISK_DEBUG_INIT }, + { "cxt", FDISK_DEBUG_CXT }, + { "label", FDISK_DEBUG_LABEL }, + { "ask", FDISK_DEBUG_ASK}, + { "frontend", FDISK_DEBUG_FRONTEND }, + { "part", FDISK_DEBUG_PART }, + { "parttype", FDISK_DEBUG_PARTTYPE }, + { "tab", FDISK_DEBUG_TAB}, + { NULL, 0 } +}; /** * fdisk_init_debug: * @mask: debug mask (0xffff to enable full debuging) diff --git a/libmount/src/Makemodule.am b/libmount/src/Makemodule.am index 54ab51d3e..d21179a9c 100644 --- a/libmount/src/Makemodule.am +++ b/libmount/src/Makemodule.am @@ -63,7 +63,8 @@ check_PROGRAMS += \ test_mount_tab_diff \ test_mount_tab_update \ test_mount_utils \ - test_mount_version + test_mount_version \ + test_mount_debug libmount_tests_cflags = -DTEST_PROGRAM $(libmount_la_CFLAGS) libmount_tests_ldflags = libblkid.la -static @@ -118,6 +119,11 @@ test_mount_version_CFLAGS = $(libmount_tests_cflags) test_mount_version_LDFLAGS = $(libmount_tests_ldflags) test_mount_version_LDADD = $(libmount_tests_ldadd) +test_mount_debug_SOURCES = libmount/src/init.c +test_mount_debug_CFLAGS = $(libmount_tests_cflags) +test_mount_debug_LDFLAGS = $(libmount_tests_ldflags) +test_mount_debug_LDADD = $(libmount_tests_ldadd) + endif # BUILD_LIBMOUNT_TESTS diff --git a/libmount/src/init.c b/libmount/src/init.c index b3d10df44..e460788fb 100644 --- a/libmount/src/init.c +++ b/libmount/src/init.c @@ -16,7 +16,21 @@ #include "mountP.h" UL_DEBUG_DEFINE_MASK(libmount); - +static const struct dbg_mask libmount_masknames [] = { + { "all", MNT_DEBUG_ALL }, + { "init", MNT_DEBUG_INIT }, + { "cache", MNT_DEBUG_CACHE }, + { "options", MNT_DEBUG_OPTIONS }, + { "locks", MNT_DEBUG_LOCKS }, + { "tab", MNT_DEBUG_TAB }, + { "fs", MNT_DEBUG_FS }, + { "opts", MNT_DEBUG_OPTS }, + { "update", MNT_DEBUG_UPDATE }, + { "utils", MNT_DEBUG_UTILS }, + { "cxt", MNT_DEBUG_CXT }, + { "diff", MNT_DEBUG_DIFF }, + { NULL, 0 } +}; /** * mnt_init_debug: * @mask: debug mask (0xffff to enable full debugging) @@ -44,3 +58,31 @@ void mnt_init_debug(int mask) DBG(INIT, ul_debug(" feature: %s", *p++)); } } + +#ifdef TEST_PROGRAM + +#include <errno.h> +#include <stdlib.h> +int main(int argc, char *argv[]) +{ + if (argc == 2) { + int mask; + + errno = 0; + mask = strtoul(argv[1], 0, 0); + + if (errno) + return 1; + + __UL_INIT_DEBUG(libmount, MNT_DEBUG_, mask, LIBMOUNT_DEBUG); + } + else if (argc == 1) { + __UL_INIT_DEBUG(libmount, MNT_DEBUG_, 0, LIBMOUNT_DEBUG); + } + else + return 1; + + return 0; +} +#endif /* TEST_PROGRAM */ + diff --git a/libsmartcols/src/init.c b/libsmartcols/src/init.c index 95b4610b7..9fec0356d 100644 --- a/libsmartcols/src/init.c +++ b/libsmartcols/src/init.c @@ -19,6 +19,15 @@ UL_DEBUG_DEFINE_MASK(libsmartcols); +static const struct dbg_mask libsmartcols_masknames [] = { + { "all", SCOLS_DEBUG_ALL }, + { "cell", SCOLS_DEBUG_CELL }, + { "line", SCOLS_DEBUG_LINE }, + { "tab", SCOLS_DEBUG_TAB }, + { "col", SCOLS_DEBUG_COL }, + { "buff", SCOLS_DEBUG_BUFF }, + { NULL, 0 } +}; /** * scols_init_debug: * @mask: debug mask (0xffff to enable full debugging) diff --git a/tests/commands.sh b/tests/commands.sh index f699ef1ab..0a3062872 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -13,6 +13,7 @@ TS_HELPER_LIBMOUNT_TABDIFF="$top_builddir/test_mount_tab_diff" TS_HELPER_LIBMOUNT_TAB="$top_builddir/test_mount_tab" TS_HELPER_LIBMOUNT_UPDATE="$top_builddir/test_mount_tab_update" TS_HELPER_LIBMOUNT_UTILS="$top_builddir/test_mount_utils" +TS_HELPER_LIBMOUNT_DEBUG="$top_builddir/test_mount_debug" TS_HELPER_PYLIBMOUNT_CONTEXT="$top_srcdir/libmount/python/test_mount_context.py" TS_HELPER_PYLIBMOUNT_TAB="$top_srcdir/libmount/python/test_mount_tab.py" TS_HELPER_PYLIBMOUNT_UPDATE="$top_srcdir/libmount/python/test_mount_tab_update.py" |