From: Lennart Poettering Date: Mon, 1 Feb 2021 16:04:47 +0000 (+0100) Subject: fs-util: port open_parent() to path_extract_directory() X-Git-Tag: v248-rc3~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=30cdcd628bbb046729d3d4c301167b12efdeca19;p=thirdparty%2Fsystemd.git fs-util: port open_parent() to path_extract_directory() --- 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. */