summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/path.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/path.c b/lib/path.c
index 968ce9114..9b05f4b98 100644
--- a/lib/path.c
+++ b/lib/path.c
@@ -436,8 +436,12 @@ 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) {
+ int dirfd;
+
DBG(CXT, ul_debugobj(pc, "duplicate dir path"));
- fd = dup_fd_cloexec(ul_path_get_dirfd(pc), STDERR_FILENO + 1);
+ dirfd = ul_path_get_dirfd(pc);
+ if (dirfd >= 0)
+ fd = dup_fd_cloexec(dirfd, STDERR_FILENO + 1);
}
if (fd < 0)