diff options
author | Karel Zak | 2018-05-15 13:43:29 +0200 |
---|---|---|
committer | Karel Zak | 2018-06-21 13:07:46 +0200 |
commit | bcf445fd688692fd4cbfde03cda60be4281ac28b (patch) | |
tree | 0a805ce19b8b7bb2cf204320eb9cf24b455c9e63 /lib/path.c | |
parent | lib/loopdev: remove obsolete macro (diff) | |
download | kernel-qcow2-util-linux-bcf445fd688692fd4cbfde03cda60be4281ac28b.tar.gz kernel-qcow2-util-linux-bcf445fd688692fd4cbfde03cda60be4281ac28b.tar.xz kernel-qcow2-util-linux-bcf445fd688692fd4cbfde03cda60be4281ac28b.zip |
lib/path lib/sysfs: add debug
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/path.c')
-rw-r--r-- | lib/path.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/lib/path.c b/lib/path.c index d6cfe1453..998dce5bb 100644 --- a/lib/path.c +++ b/lib/path.c @@ -18,6 +18,29 @@ #include "fileutils.h" #include "all-io.h" #include "path.h" +#include "debug.h" + +/* + * Debug stuff (based on include/debug.h) + */ +static UL_DEBUG_DEFINE_MASK(ulpath); +UL_DEBUG_DEFINE_MASKNAMES(ulpath) = UL_DEBUG_EMPTY_MASKNAMES; + +#define ULPATH_DEBUG_INIT (1 << 1) +#define ULPATH_DEBUG_CXT (1 << 2) + +#define DBG(m, x) __UL_DBG(ulpath, ULPATH_DEBUG_, m, x) +#define ON_DBG(m, x) __UL_DBG_CALL(ulpath, ULPATH_DEBUG_, m, x) + +#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(ulpath) +#include "debugobj.h" + +void ul_path_init_debug(void) +{ + if (ulpath_debug_mask) + return; + __UL_INIT_DEBUG_FROM_ENV(ulpath, ULPATH_DEBUG_, 0, ULPATH_DEBUG); +} struct path_cxt *ul_new_path(const char *dir) { @@ -26,6 +49,8 @@ struct path_cxt *ul_new_path(const char *dir) if (!pc) return NULL; + DBG(CXT, ul_debugobj(pc, "alloc")); + pc->refcount = 1; pc->dir_fd = -1; @@ -54,6 +79,7 @@ void ul_unref_path(struct path_cxt *pc) pc->refcount--; if (pc->refcount <= 0) { + DBG(CXT, ul_debugobj(pc, "dealloc")); if (pc->dialect) pc->free_dialect(pc); if (pc->dir_fd >= 0) @@ -78,6 +104,7 @@ int ul_path_set_prefix(struct path_cxt *pc, const char *prefix) free(pc->prefix); pc->prefix = p; + DBG(CXT, ul_debugobj(pc, "new prefix: '%s'", p)); return 0; } @@ -103,6 +130,7 @@ int ul_path_set_dir(struct path_cxt *pc, const char *dir) free(pc->dir_path); pc->dir_path = p; + DBG(CXT, ul_debugobj(pc, "new dir: '%s'", p)); return 0; } @@ -115,6 +143,7 @@ int ul_path_set_dialect(struct path_cxt *pc, void *data, void free_data(struct p { pc->dialect = data; pc->free_dialect = free_data; + DBG(CXT, ul_debugobj(pc, "new dialect")); return 0; } @@ -157,6 +186,8 @@ int ul_path_get_dirfd(struct path_cxt *pc) const char *path = get_absdir(pc); if (!path) return -errno; + + DBG(CXT, ul_debugobj(pc, "opening dir: '%s'", path)); pc->dir_fd = open(path, O_RDONLY|O_CLOEXEC); } @@ -223,6 +254,7 @@ int ul_path_open(struct path_cxt *pc, int flags, const char *path) && pc->redirect_on_enoent(pc, path, &dir) == 0) fd = openat(dir, path, flags); + DBG(CXT, ul_debugobj(pc, "opening '%s'", path)); return fd; } @@ -327,8 +359,10 @@ DIR *ul_path_opendir(struct path_cxt *pc, const char *path) if (path) fd = ul_path_open(pc, O_RDONLY|O_CLOEXEC, path); - else if (pc->dir_path) + else if (pc->dir_path) { + DBG(CXT, ul_debugobj(pc, "duplicate dir path")); fd = dup_fd_cloexec(ul_path_get_dirfd(pc), STDERR_FILENO + 1); + } if (fd < 0) return NULL; @@ -895,6 +929,8 @@ int main(int argc, char *argv[]) errx(EXIT_FAILURE, "<dir> not defined"); dir = argv[optind++]; + ul_path_init_debug(); + pc = ul_new_path(dir); if (!pc) err(EXIT_FAILURE, "failed to initialize path context"); |