]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: add helper that ensures something is a mount point
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Apr 2021 14:13:51 +0000 (16:13 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 May 2021 20:43:29 +0000 (22:43 +0200)
src/nspawn/nspawn.c
src/shared/mount-util.c
src/shared/mount-util.h

index ee84495ca2664fc66db8df471f408f7eb18d4d03..38d6eeacc7e0563aedb118154af6009cddc29c62 100644 (file)
@@ -3688,11 +3688,9 @@ static int outer_child(
                 return r;
 
         /* Make sure we always have a mount that we can move to root later on. */
-        if (!path_is_mount_point(directory, NULL, 0)) {
-                r = mount_nofollow_verbose(LOG_ERR, directory, directory, NULL, MS_BIND|MS_REC, NULL);
-                if (r < 0)
-                        return r;
-        }
+        r = make_mount_point(directory);
+        if (r < 0)
+                return r;
 
         if (dissected_image) {
                 /* Now we know the uid shift, let's now mount everything else that might be in the image. */
index 13f202d7e7dfb241fb2eda925b9d2ecc7d289c1c..2c38f93917c8bc64e86d704bc055c3cbaa3e34f2 100644 (file)
@@ -986,3 +986,23 @@ int mount_image_in_namespace(
 
         return mount_in_namespace(target, propagate_path, incoming_path, src, dest, read_only, make_file_or_directory, options, true);
 }
+
+int make_mount_point(const char *path) {
+        int r;
+
+        assert(path);
+
+        /* If 'path' is already a mount point, does nothing and returns 0. If it is not it makes it one, and returns 1. */
+
+        r = path_is_mount_point(path, NULL, 0);
+        if (r < 0)
+                return log_debug_errno(r, "Failed to determine whether '%s' is a mount point: %m", path);
+        if (r > 0)
+                return 0;
+
+        r = mount_nofollow_verbose(LOG_DEBUG, path, path, NULL, MS_BIND|MS_REC, NULL);
+        if (r < 0)
+                return r;
+
+        return 1;
+}
index 6469181d1cf46a37ca1124f48ba6a6175e55f039..59cf75606df20abc7f126dc95f93f8ebe9b1d0c6 100644 (file)
@@ -103,3 +103,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_rmdir_and_free);
 
 int bind_mount_in_namespace(pid_t target, const char *propagate_path, const char *incoming_path, const char *src, const char *dest, bool read_only, bool make_file_or_directory);
 int mount_image_in_namespace(pid_t target, const char *propagate_path, const char *incoming_path, const char *src, const char *dest, bool read_only, bool make_file_or_directory, const MountOptions *options);
+
+int make_mount_point(const char *path);