]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: teach open_tree_attr_fallback() our usual AT_EMPTY_PATH trick 38130/head
authorMike Yuan <me@yhndnzj.com>
Wed, 9 Jul 2025 08:07:07 +0000 (10:07 +0200)
committerMike Yuan <me@yhndnzj.com>
Wed, 9 Jul 2025 08:14:00 +0000 (10:14 +0200)
While at it, rename it to _with_fallback following
the naming scheme we use elsewhere.

src/nspawn/nspawn-mount.c
src/shared/mount-util.c
src/shared/mount-util.h

index be1c01caf9feb250b33353a4d13823861c0a9c5b..af794b00172a7f937cc122feccdadefc52a9539f 100644 (file)
@@ -824,7 +824,7 @@ static int mount_bind(const char *dest, CustomMount *m, uid_t uid_shift, uid_t u
          * caller's userns *without* any mount idmapping in place. To get that uid, we clone the
          * mount source tree and clear any existing idmapping and temporarily mount that tree over
          * the mount source before we stat the mount source to figure out the source uid. */
-        _cleanup_close_ int fd_clone = open_tree_attr_fallback(
+        _cleanup_close_ int fd_clone = open_tree_attr_with_fallback(
                         AT_FDCWD,
                         m->source,
                         OPEN_TREE_CLONE|OPEN_TREE_CLOEXEC,
index a0db226c259c0865a910d58f85fca8573b13c2e5..3d10a050919dc1c327586ac56b9a695fc582c213 100644 (file)
@@ -1441,10 +1441,18 @@ int make_userns(uid_t uid_shift,
         return TAKE_FD(userns_fd);
 }
 
-int open_tree_attr_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr) {
+int open_tree_attr_with_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr) {
+        _cleanup_close_ int fd = -EBADF;
+
+        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
         assert(attr);
 
-        _cleanup_close_ int fd = open_tree_attr(dir_fd, path, flags, attr, sizeof(struct mount_attr));
+        if (isempty(path)) {
+                path = "";
+                flags |= AT_EMPTY_PATH;
+        }
+
+        fd = open_tree_attr(dir_fd, path, flags, attr, sizeof(struct mount_attr));
         if (fd >= 0)
                 return TAKE_FD(fd);
         if (!ERRNO_IS_NOT_SUPPORTED(errno))
@@ -1492,8 +1500,8 @@ int remount_idmap_fd(
 
         for (size_t i = 0; i < n; i++) {
                 /* Clone the mount point and et the user namespace mapping attribute on the cloned mount point. */
-                mount_fds[n_mounts_fds] = open_tree_attr_fallback(
-                                /* dir_fd= */ -EBADF,
+                mount_fds[n_mounts_fds] = open_tree_attr_with_fallback(
+                                AT_FDCWD,
                                 paths[i],
                                 OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC,
                                 &(struct mount_attr) {
index 3c1fe9dc1ef3e7d87f26aa1213601136863f4fe2..3140762498f44cdfb3ae0ee91c958f3afbc11369 100644 (file)
@@ -150,7 +150,7 @@ typedef enum RemountIdmapping {
         _REMOUNT_IDMAPPING_INVALID = -EINVAL,
 } RemountIdmapping;
 
-int open_tree_attr_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr);
+int open_tree_attr_with_fallback(int dir_fd, const char *path, unsigned int flags, struct mount_attr *attr);
 
 int make_userns(uid_t uid_shift, uid_t uid_range, uid_t host_owner, uid_t dest_owner, RemountIdmapping idmapping);
 int remount_idmap_fd(char **p, int userns_fd, uint64_t extra_mount_attr_set);