From 30cdcd628bbb046729d3d4c301167b12efdeca19 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 1 Feb 2021 17:04:47 +0100 Subject: [PATCH] fs-util: port open_parent() to path_extract_directory() --- src/basic/fs-util.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 3a3daa9a05d..c8885e5aa1a 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -1503,16 +1503,11 @@ int syncfs_path(int atfd, const char *path) { int open_parent(const char *path, int flags, mode_t mode) { _cleanup_free_ char *parent = NULL; - int fd; - - if (isempty(path)) - return -EINVAL; - if (path_equal(path, "/")) /* requesting the parent of the root dir is fishy, let's prohibit that */ - return -EINVAL; + int fd, r; - parent = dirname_malloc(path); - if (!parent) - return -ENOMEM; + r = path_extract_directory(path, &parent); + if (r < 0) + return r; /* Let's insist on O_DIRECTORY since the parent of a file or directory is a directory. Except if we open an * O_TMPFILE file, because in that case we are actually create a regular file below the parent directory. */ -- 2.47.3