]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Mar 2018 14:34:54 +0000 (16:34 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 29 Mar 2018 13:33:12 +0000 (15:33 +0200)
Let's optimize things, and let the kernel chase the paths if none of the
features chase_symlinks() offers are actually used.

src/basic/fs-util.c

index ef9ce5e9322a8c5b7f9a5cc9ed4957ada67731a6..112aedd027fa411e348dd83933bce47804cefa0b 100644 (file)
@@ -634,6 +634,16 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
         if (noop_root(original_root))
                 original_root = NULL;
 
+        if (!original_root && !ret && (flags & (CHASE_NONEXISTENT|CHASE_NO_AUTOFS|CHASE_SAFE|CHASE_OPEN)) == CHASE_OPEN) {
+                /* Shortcut the CHASE_OPEN case if the caller isn't interested in the actual path and has no root set
+                 * and doesn't care about any of the other special features we provide either. */
+                r = open(path, O_PATH|O_CLOEXEC);
+                if (r < 0)
+                        return -errno;
+
+                return r;
+        }
+
         if (original_root) {
                 r = path_make_absolute_cwd(original_root, &root);
                 if (r < 0)