diff options
author | Karel Zak | 2018-10-17 13:18:25 +0200 |
---|---|---|
committer | Karel Zak | 2018-12-07 12:32:58 +0100 |
commit | c9ea91d41ef0fb1975e8340a010e777aee84b089 (patch) | |
tree | ead678f7c0fb78246774204cc807726a26571e70 /lib | |
parent | lsblk: rename set_device() (diff) | |
download | kernel-qcow2-util-linux-c9ea91d41ef0fb1975e8340a010e777aee84b089.tar.gz kernel-qcow2-util-linux-c9ea91d41ef0fb1975e8340a010e777aee84b089.tar.xz kernel-qcow2-util-linux-c9ea91d41ef0fb1975e8340a010e777aee84b089.zip |
lib/path: allow to close dirfd
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/path.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/path.c b/lib/path.c index 9cc2e3e2e..d36fe41e8 100644 --- a/lib/path.c +++ b/lib/path.c @@ -94,8 +94,7 @@ void ul_unref_path(struct path_cxt *pc) DBG(CXT, ul_debugobj(pc, "dealloc")); if (pc->dialect) pc->free_dialect(pc); - if (pc->dir_fd >= 0) - close(pc->dir_fd); + ul_path_close_dirfd(pc); free(pc->dir_path); free(pc->prefix); free(pc); @@ -212,6 +211,23 @@ int ul_path_get_dirfd(struct path_cxt *pc) return pc->dir_fd; } +/* Note that next ul_path_get_dirfd() will reopen the directory */ +void ul_path_close_dirfd(struct path_cxt *pc) +{ + assert(pc); + + if (pc->dir_fd >= 0) { + DBG(CXT, ul_debugobj(pc, "closing dir: '%s'", pc->dir_path)); + close(pc->dir_fd); + pc->dir_fd = -1; + } +} + +int ul_path_isopen_dirfd(struct path_cxt *pc) +{ + return pc && pc->dir_fd >= 0; +} + static const char *ul_path_mkpath(struct path_cxt *pc, const char *path, va_list ap) { int rc = vsnprintf(pc->path_buffer, sizeof(pc->path_buffer), path, ap); @@ -301,7 +317,7 @@ int ul_path_open(struct path_cxt *pc, int flags, const char *path) if (!pc) { fd = open(path, flags); - DBG(CXT, ul_debug("opening '%s'", path)); + DBG(CXT, ul_debug("opening '%s' [no context]", path)); } else { int fdx; int dir = ul_path_get_dirfd(pc); |