#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)
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; \
} \
} while (0)
+struct dbg_mask { char *mname; int val; };
+
static inline void __attribute__ ((__format__ (__printf__, 1, 2)))
ul_debug(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 */
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)
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)
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
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
#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)
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 */
+
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)
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"