]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: port open_parent() to path_extract_directory()
authorLennart Poettering <lennart@poettering.net>
Mon, 1 Feb 2021 16:04:47 +0000 (17:04 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Mar 2021 21:00:24 +0000 (22:00 +0100)
src/basic/fs-util.c

index 3a3daa9a05d8288c829807b27c039b2d4643b65a..c8885e5aa1a19edabbfef08569e1adb44461bee7 100644 (file)
@@ -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. */