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>
This commit is contained in:
parent
bd85d11fba
commit
14ad2353cc
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue