]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: introduce path_is_mount_point_full 31205/head
authorMike Yuan <me@yhndnzj.com>
Sun, 4 Feb 2024 20:17:32 +0000 (04:17 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 6 Feb 2024 07:09:28 +0000 (15:09 +0800)
29 files changed:
src/basic/mountpoint-util.c
src/basic/mountpoint-util.h
src/core/automount.c
src/core/exec-credential.c
src/core/import-creds.c
src/core/namespace.c
src/gpt-auto-generator/gpt-auto-generator.c
src/home/user-record-util.c
src/libsystemd/sd-device/test-device-util.c
src/libsystemd/sd-device/test-sd-device-monitor.c
src/libsystemd/sd-device/test-sd-device.c
src/login/user-runtime-dir.c
src/nspawn/nspawn-cgroup.c
src/nspawn/nspawn-mount.c
src/nspawn/nspawn.c
src/partition/growfs.c
src/partition/repart.c
src/shared/condition.c
src/shared/machine-id-setup.c
src/shared/mount-setup.c
src/shared/mount-util.c
src/shared/switch-root.c
src/sysext/sysext.c
src/test/test-mount-util.c
src/test/test-mountpoint-util.c
src/test/test-stat-util.c
src/udev/test-udev-format.c
src/udev/test-udev-spawn.c
src/volatile-root/volatile-root.c

index 0ff1ed601878682d93a63d14af54823cf8291158..8014e91dc561bd7a724bce302445ec262740596c 100644 (file)
@@ -329,34 +329,33 @@ fallback_fstat:
 }
 
 /* flags can be AT_SYMLINK_FOLLOW or 0 */
-int path_is_mount_point(const char *t, const char *root, int flags) {
+int path_is_mount_point_full(const char *path, const char *root, int flags) {
         _cleanup_free_ char *canonical = NULL;
         _cleanup_close_ int fd = -EBADF;
         int r;
 
-        assert(t);
+        assert(path);
         assert((flags & ~AT_SYMLINK_FOLLOW) == 0);
 
-        if (path_equal(t, "/"))
+        if (path_equal(path, "/"))
                 return 1;
 
-        /* we need to resolve symlinks manually, we can't just rely on
-         * fd_is_mount_point() to do that for us; if we have a structure like
-         * /bin -> /usr/bin/ and /usr is a mount point, then the parent that we
+        /* we need to resolve symlinks manually, we can't just rely on fd_is_mount_point() to do that for us;
+         * if we have a structure like /bin -> /usr/bin/ and /usr is a mount point, then the parent that we
          * look at needs to be /usr, not /. */
-        if (flags & AT_SYMLINK_FOLLOW) {
-                r = chase(t, root, CHASE_TRAIL_SLASH, &canonical, NULL);
+        if (FLAGS_SET(flags, AT_SYMLINK_FOLLOW)) {
+                r = chase(path, root, CHASE_TRAIL_SLASH, &canonical, NULL);
                 if (r < 0)
                         return r;
 
-                t = canonical;
+                path = canonical;
         }
 
-        fd = open_parent(t, O_PATH|O_CLOEXEC, 0);
+        fd = open_parent(path, O_PATH|O_CLOEXEC, 0);
         if (fd < 0)
                 return fd;
 
-        return fd_is_mount_point(fd, last_path_component(t), flags);
+        return fd_is_mount_point(fd, last_path_component(path), flags);
 }
 
 int path_get_mnt_id_at_fallback(int dir_fd, const char *path, int *ret) {
index 499403a4d89494530b4ef591d110d1553adb3c65..04f79bf76a85805d8a3f2bab83779945274773bc 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <fcntl.h>
 #include <stdbool.h>
+#include <stddef.h>
 #include <sys/types.h>
 
 /* The limit used for /dev itself. 4MB should be enough since device nodes and symlinks don't
@@ -44,7 +45,10 @@ static inline int path_get_mnt_id(const char *path, int *ret) {
 }
 
 int fd_is_mount_point(int fd, const char *filename, int flags);
-int path_is_mount_point(const char *path, const char *root, int flags);
+int path_is_mount_point_full(const char *path, const char *root, int flags);
+static inline int path_is_mount_point(const char *path) {
+        return path_is_mount_point_full(path, NULL, 0);
+}
 
 bool fstype_is_network(const char *fstype);
 bool fstype_needs_quota(const char *fstype);
index 4cbb3727e585c2b4b74437e1e74dc2d5badc8627..88a9f49b5fb2a4cc1700b93f4db0e10b1f491b9b 100644 (file)
@@ -821,7 +821,7 @@ static int automount_start(Unit *u) {
         assert(a);
         assert(IN_SET(a->state, AUTOMOUNT_DEAD, AUTOMOUNT_FAILED));
 
-        if (path_is_mount_point(a->where, NULL, 0) > 0)
+        if (path_is_mount_point(a->where) > 0)
                 return log_unit_error_errno(u, SYNTHETIC_ERRNO(EEXIST), "Path %s is already a mount point, refusing start.", a->where);
 
         r = unit_test_trigger_loaded(u);
index ef3033f67ab0c0cf44290e4e04c0103cf8ae4b45..048cccf56ecfe6df57efe93e69401bbe02273c5e 100644 (file)
@@ -777,7 +777,7 @@ static int setup_credentials_internal(
         assert(workspace);
 
         if (reuse_workspace) {
-                r = path_is_mount_point(workspace, NULL, 0);
+                r = path_is_mount_point(workspace);
                 if (r < 0)
                         return r;
                 if (r > 0)
@@ -788,7 +788,7 @@ static int setup_credentials_internal(
         } else
                 workspace_mounted = -1; /* ditto */
 
-        r = path_is_mount_point(final, NULL, 0);
+        r = path_is_mount_point(final);
         if (r < 0)
                 return r;
         if (r > 0) {
index be56c4676f308f71f3800817f568c2229c4c68a5..18e4bce67f8a0f7af960bf633811ef8e1a7a22f4 100644 (file)
@@ -80,7 +80,7 @@ static int acquire_credential_directory(ImportCredentialContext *c, const char *
         if (c->target_dir_fd >= 0)
                 return c->target_dir_fd;
 
-        r = path_is_mount_point(path, NULL, 0);
+        r = path_is_mount_point(path);
         if (r < 0) {
                 if (r != -ENOENT)
                         return log_error_errno(r, "Failed to determine if %s is a mount point: %m", path);
index aef0d527990fa7e4b47fe8bbebd59bf752a8d294..d87079ccbc6ae468b05b5da9075ebe2129dadb22 100644 (file)
@@ -1117,7 +1117,7 @@ static int mount_bind_dev(const MountEntry *m) {
 
         (void) mkdir_p_label(mount_entry_path(m), 0755);
 
-        r = path_is_mount_point(mount_entry_path(m), NULL, 0);
+        r = path_is_mount_point(mount_entry_path(m));
         if (r < 0)
                 return log_debug_errno(r, "Unable to determine whether /dev is already mounted: %m");
         if (r > 0) /* make this a NOP if /dev is already a mount point */
@@ -1137,7 +1137,7 @@ static int mount_bind_sysfs(const MountEntry *m) {
 
         (void) mkdir_p_label(mount_entry_path(m), 0755);
 
-        r = path_is_mount_point(mount_entry_path(m), NULL, 0);
+        r = path_is_mount_point(mount_entry_path(m));
         if (r < 0)
                 return log_debug_errno(r, "Unable to determine whether /sys is already mounted: %m");
         if (r > 0) /* make this a NOP if /sys is already a mount point */
@@ -1184,7 +1184,7 @@ static int mount_private_apivfs(
                 /* When we do not have enough privileges to mount a new instance, fall back to use an
                  * existing mount. */
 
-                r = path_is_mount_point(entry_path, /* root = */ NULL, /* flags = */ 0);
+                r = path_is_mount_point(entry_path);
                 if (r < 0)
                         return log_debug_errno(r, "Unable to determine whether '%s' is already mounted: %m", entry_path);
                 if (r > 0)
@@ -1299,7 +1299,7 @@ static int mount_run(const MountEntry *m) {
 
         assert(m);
 
-        r = path_is_mount_point(mount_entry_path(m), NULL, 0);
+        r = path_is_mount_point(mount_entry_path(m));
         if (r < 0 && r != -ENOENT)
                 return log_debug_errno(r, "Unable to determine whether /run is already mounted: %m");
         if (r > 0) /* make this a NOP if /run is already a mount point */
@@ -1533,7 +1533,7 @@ static int apply_one_mount(
         case MOUNT_READ_WRITE_IMPLICIT:
         case MOUNT_EXEC:
         case MOUNT_NOEXEC:
-                r = path_is_mount_point(mount_entry_path(m), root_directory, 0);
+                r = path_is_mount_point_full(mount_entry_path(m), root_directory, /* flags = */ 0);
                 if (r == -ENOENT && m->ignore)
                         return 0;
                 if (r < 0)
@@ -2537,7 +2537,7 @@ int setup_namespace(const NamespaceParameters *p, char **error_path) {
         } else if (p->root_directory) {
 
                 /* A root directory is specified. Turn its directory into bind mount, if it isn't one yet. */
-                r = path_is_mount_point(root, NULL, AT_SYMLINK_FOLLOW);
+                r = path_is_mount_point_full(root, /* root = */ NULL, AT_SYMLINK_FOLLOW);
                 if (r < 0)
                         return log_debug_errno(r, "Failed to detect that %s is a mount point or not: %m", root);
                 if (r == 0) {
index 80ca647e513803e7907c572101b9865e97b048e9..d23999ed93b436ecca71ad9fe4eebfa4af1adae2 100644 (file)
@@ -280,7 +280,7 @@ static int path_is_busy(const char *where) {
         assert(where);
 
         /* already a mountpoint; generators run during reload */
-        r = path_is_mount_point(where, NULL, AT_SYMLINK_FOLLOW);
+        r = path_is_mount_point_full(where, /* root = */ NULL, AT_SYMLINK_FOLLOW);
         if (r > 0)
                 return false;
         /* The directory will be created by the mount or automount unit when it is started. */
index 089cbb1a1d0ee47645f8fac6f563c47863d48e61..6c427138669abbdf1b23578cee94212b0e9cdb08 100644 (file)
@@ -428,7 +428,7 @@ int user_record_test_home_directory(UserRecord *h) {
         if (r == 0)
                 return -ENOTDIR;
 
-        r = path_is_mount_point(hd, NULL, 0);
+        r = path_is_mount_point(hd);
         if (r < 0)
                 return r;
         if (r > 0)
index 4d38982e348da15dd69c44f2431be38656daac1f..d98c687bc2ebfb0036b47dd92b7b2104fb75e90d 100644 (file)
@@ -82,7 +82,7 @@ TEST(device_is_devtype) {
 }
 
 static int intro(void) {
-        if (path_is_mount_point("/sys", NULL, 0) <= 0)
+        if (path_is_mount_point("/sys") <= 0)
                 return log_tests_skipped("/sys is not mounted");
 
         return EXIT_SUCCESS;
index 4f80c4e57941caaf74b0f4c24791d6c73dea6df4..3dbf9871dc3f7d3acca3ae2bf3f0270b7c49bc5c 100644 (file)
@@ -299,7 +299,7 @@ int main(int argc, char *argv[]) {
         if (getuid() != 0)
                 return log_tests_skipped("not root");
 
-        if (path_is_mount_point("/sys", NULL, 0) <= 0)
+        if (path_is_mount_point("/sys") <= 0)
                 return log_tests_skipped("/sys is not mounted");
 
         if (path_is_read_only_fs("/sys") > 0)
index f64f6013cf723b2f2790f69e6d3c8f0e6938db3b..9fde1a08143f7f5042d2512c2191e316e05bb931 100644 (file)
@@ -677,7 +677,7 @@ TEST(devname_from_devnum) {
 }
 
 static int intro(void) {
-        if (path_is_mount_point("/sys", NULL, 0) <= 0)
+        if (path_is_mount_point("/sys") <= 0)
                 return log_tests_skipped("/sys is not mounted");
 
         return EXIT_SUCCESS;
index ad04b04df9c6604bb6f226ba3bf80f7bf083c37a..5f527d8c4352f36a733ae0eb922483d824840cd9 100644 (file)
@@ -67,7 +67,7 @@ static int user_mkdir_runtime_path(
         if (r < 0)
                 return log_error_errno(r, "Failed to create /run/user: %m");
 
-        if (path_is_mount_point(runtime_path, NULL, 0) > 0)
+        if (path_is_mount_point(runtime_path) > 0)
                 log_debug("%s is already a mount point", runtime_path);
         else {
                 char options[sizeof("mode=0700,uid=,gid=,size=,nr_inodes=,smackfsroot=*")
index a5002437c6f7914d5b892e70afa0d2c5b06bc9d1..c4a784fd643d0a723e02f3a44c974cd96870f984 100644 (file)
@@ -265,7 +265,7 @@ static int mount_legacy_cgroup_hierarchy(
 
         to = strjoina(strempty(dest), "/sys/fs/cgroup/", hierarchy);
 
-        r = path_is_mount_point(to, dest, 0);
+        r = path_is_mount_point_full(to, dest, /* flags = */ 0);
         if (r < 0 && r != -ENOENT)
                 return log_error_errno(r, "Failed to determine if %s is mounted already: %m", to);
         if (r > 0)
@@ -317,7 +317,7 @@ static int mount_legacy_cgns_supported(
         (void) mkdir_p(cgroup_root, 0755);
 
         /* Mount a tmpfs to /sys/fs/cgroup if it's not mounted there yet. */
-        r = path_is_mount_point(cgroup_root, dest, AT_SYMLINK_FOLLOW);
+        r = path_is_mount_point_full(cgroup_root, dest, AT_SYMLINK_FOLLOW);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine if /sys/fs/cgroup is already mounted: %m");
         if (r == 0) {
@@ -427,7 +427,7 @@ static int mount_legacy_cgns_unsupported(
         (void) mkdir_p(cgroup_root, 0755);
 
         /* Mount a tmpfs to /sys/fs/cgroup if it's not mounted there yet. */
-        r = path_is_mount_point(cgroup_root, dest, AT_SYMLINK_FOLLOW);
+        r = path_is_mount_point_full(cgroup_root, dest, AT_SYMLINK_FOLLOW);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine if /sys/fs/cgroup is already mounted: %m");
         if (r == 0) {
@@ -529,7 +529,7 @@ static int mount_unified_cgroups(const char *dest) {
 
         (void) mkdir_p(p, 0755);
 
-        r = path_is_mount_point(p, dest, AT_SYMLINK_FOLLOW);
+        r = path_is_mount_point_full(p, dest, AT_SYMLINK_FOLLOW);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine if %s is mounted already: %m", p);
         if (r > 0) {
index 24771076b44108d99c2e397500b4021c4f9b9757..5f41c1c91fe441b8703d3d680a1a87eaa3bc0678 100644 (file)
@@ -642,7 +642,7 @@ int mount_all(const char *dest,
 
                 /* Skip this entry if it is not a remount. */
                 if (mount_table[k].what) {
-                        r = path_is_mount_point(where, NULL, 0);
+                        r = path_is_mount_point(where);
                         if (r < 0 && r != -ENOENT)
                                 return log_error_errno(r, "Failed to detect whether %s is a mount point: %m", where);
                         if (r > 0)
index c0ec076b2463c1f425af431fe7d0213324062991..ead1e4af8d1ed79825d097aace034a7165c99008 100644 (file)
@@ -2560,7 +2560,7 @@ static int setup_journal(const char *directory) {
         p = strjoina("/var/log/journal/", SD_ID128_TO_STRING(arg_uuid));
         q = prefix_roota(directory, p);
 
-        if (path_is_mount_point(p, NULL, 0) > 0) {
+        if (path_is_mount_point(p) > 0) {
                 if (try)
                         return 0;
 
@@ -2568,7 +2568,7 @@ static int setup_journal(const char *directory) {
                                        "%s: already a mount point, refusing to use for journal", p);
         }
 
-        if (path_is_mount_point(q, NULL, 0) > 0) {
+        if (path_is_mount_point(q) > 0) {
                 if (try)
                         return 0;
 
@@ -3633,7 +3633,7 @@ static int setup_unix_export_dir_outside(char **ret) {
         if (!p)
                 return log_oom();
 
-        r = path_is_mount_point(p, /* root= */ NULL, 0);
+        r = path_is_mount_point(p);
         if (r > 0)
                 return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Mount point '%s' exists already, refusing.", p);
         if (r < 0 && r != -ENOENT)
@@ -5680,7 +5680,7 @@ static int run(int argc, char *argv[]) {
                         /* If the specified path is a mount point we generate the new snapshot immediately
                          * inside it under a random name. However if the specified is not a mount point we
                          * create the new snapshot in the parent directory, just next to it. */
-                        r = path_is_mount_point(arg_directory, NULL, 0);
+                        r = path_is_mount_point(arg_directory);
                         if (r < 0) {
                                 log_error_errno(r, "Failed to determine whether directory %s is mount point: %m", arg_directory);
                                 goto finish;
index 491040ffb086889a403c98e129cc70691fac9780..f9600ace842c2a657eaa1aa7211302a95a18f346 100644 (file)
@@ -224,7 +224,7 @@ static int run(int argc, char *argv[]) {
         if (r <= 0)
                 return r;
 
-        r = path_is_mount_point(arg_target, NULL, 0);
+        r = path_is_mount_point(arg_target);
         if (r < 0)
                 return log_error_errno(r, "Failed to check if \"%s\" is a mount point: %m", arg_target);
         if (r == 0)
index 2deada07186c348c033c2cdddd3454e48e577b83..05332f9680f5ced5c52791a1f93814198814a5f9 100644 (file)
@@ -5828,7 +5828,7 @@ static int find_backing_devno(
         if (r < 0)
                 return r;
 
-        r = path_is_mount_point(resolved, NULL, 0);
+        r = path_is_mount_point(resolved);
         if (r < 0)
                 return r;
         if (r == 0) /* Not a mount point, then it's not a partition of its own, let's not automatically use it. */
@@ -7037,7 +7037,7 @@ static int parse_argv(int argc, char *argv[]) {
                 /* By default operate on /sysusr/ or /sysroot/ when invoked in the initrd. We prefer the
                  * former, if it is mounted, so that we have deterministic behaviour on systems where /usr/
                  * is vendor-supplied but the root fs formatted on first boot. */
-                r = path_is_mount_point("/sysusr/usr", NULL, 0);
+                r = path_is_mount_point("/sysusr/usr");
                 if (r <= 0) {
                         if (r < 0 && r != -ENOENT)
                                 log_debug_errno(r, "Unable to determine whether /sysusr/usr is a mount point, assuming it is not: %m");
index b08cd959a0bb1bc3b9c838a4bf3232aa6f22599f..385ceee332b44e92300c7268bc9b2a45938dae8d 100644 (file)
@@ -931,7 +931,7 @@ static int condition_test_path_is_mount_point(Condition *c, char **env) {
         assert(c->parameter);
         assert(c->type == CONDITION_PATH_IS_MOUNT_POINT);
 
-        return path_is_mount_point(c->parameter, NULL, AT_SYMLINK_FOLLOW) > 0;
+        return path_is_mount_point_full(c->parameter, /* root = */ NULL, AT_SYMLINK_FOLLOW) > 0;
 }
 
 static int condition_test_path_is_read_write(Condition *c, char **env) {
index 94425d6a73143926a79ad9653dd624454d515718..f821ea7c9d693585777d6c0d46b9f47ad4af7054 100644 (file)
@@ -237,7 +237,7 @@ int machine_id_commit(const char *root) {
 
         etc_machine_id = prefix_roota(root, "/etc/machine-id");
 
-        r = path_is_mount_point(etc_machine_id, NULL, 0);
+        r = path_is_mount_point(etc_machine_id);
         if (r < 0)
                 return log_error_errno(r, "Failed to determine whether %s is a mount point: %m", etc_machine_id);
         if (r == 0) {
index a602f6f1e2515950a31dd16e80088f09746b3ad8..a492e7127ff19b0b18532ee0313c12665ada3ca1 100644 (file)
@@ -177,7 +177,7 @@ static int mount_one(const MountPoint *p, bool relabel) {
         if (relabel)
                 (void) label_fix(p->where, LABEL_IGNORE_ENOENT|LABEL_IGNORE_EROFS);
 
-        r = path_is_mount_point(p->where, NULL, AT_SYMLINK_FOLLOW);
+        r = path_is_mount_point_full(p->where, /* root = */ NULL, AT_SYMLINK_FOLLOW);
         if (r < 0 && r != -ENOENT) {
                 log_full_errno(priority, r, "Failed to determine whether %s is a mount point: %m", p->where);
                 return (p->mode & MNT_FATAL) ? r : 0;
index bf351820a74afc8b25e20de8cb2fc4791d51e9a6..9bae21f88e512113dac387dad4771c2fcbff37f0 100644 (file)
@@ -347,7 +347,7 @@ int bind_remount_recursive_with_mountinfo(
                                  * think autofs, NFS, FUSE, …), but let's generate useful debug messages at
                                  * the very least. */
 
-                                q = path_is_mount_point(x, NULL, 0);
+                                q = path_is_mount_point(x);
                                 if (IN_SET(q, 0, -ENOENT)) {
                                         /* Hmm, whaaaa? The mount point is not actually a mount point? Then
                                          * it is either obstructed by a later mount or somebody has been
@@ -1283,7 +1283,7 @@ int make_mount_point(const char *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);
+        r = path_is_mount_point(path);
         if (r < 0)
                 return log_debug_errno(r, "Failed to determine whether '%s' is a mount point: %m", path);
         if (r > 0)
@@ -1590,7 +1590,7 @@ int bind_mount_submounts(
                 if (!t)
                         return -ENOMEM;
 
-                r = path_is_mount_point(t, NULL, 0);
+                r = path_is_mount_point(t);
                 if (r < 0) {
                         log_debug_errno(r, "Failed to detect if '%s' already is a mount point, ignoring: %m", t);
                         continue;
index 787fb79afb4c9797172cc4644953056a149203de..aba9d52e9677a950a8ffe02690e61a82ee569c28 100644 (file)
@@ -144,7 +144,7 @@ int switch_root(const char *new_root,
                         return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, transfer->path);
 
                 /* Let's see if it is a mount point already. */
-                r = path_is_mount_point(chased, NULL, 0);
+                r = path_is_mount_point(chased);
                 if (r < 0)
                         return log_error_errno(r, "Failed to determine whether %s is a mount point: %m", chased);
                 if (r > 0) /* If it is already mounted, then do nothing */
index fc793707814102e8d7583ec9072ec239be9641d2..49cedcc24bfe52896dee83a2d47c1bbfbc07357f 100644 (file)
@@ -113,7 +113,7 @@ static int is_our_mount_point(
 
         assert(p);
 
-        r = path_is_mount_point(p, NULL, 0);
+        r = path_is_mount_point(p);
         if (r == -ENOENT) {
                 log_debug_errno(r, "Hierarchy '%s' doesn't exist.", p);
                 return false;
index 069a63290cecf529ba2ca96dd1d89781df68f9cd..3e22ac67fc85b4cd97c4d62fc65f3719b5564159 100644 (file)
@@ -508,11 +508,11 @@ TEST(bind_mount_submounts) {
         free(x);
 
         assert_se(x = path_join(b, "x"));
-        assert_se(path_is_mount_point(x, NULL, 0) > 0);
+        assert_se(path_is_mount_point(x) > 0);
         free(x);
 
         assert_se(x = path_join(b, "y"));
-        assert_se(path_is_mount_point(x, NULL, 0) > 0);
+        assert_se(path_is_mount_point(x) > 0);
 
         assert_se(umount_recursive(a, 0) >= 0);
         assert_se(umount_recursive(b, 0) >= 0);
index 1f71a258598c02472620e859ec84026f644642b2..6d784a9ae83cc422d810a28ca5017e1376853346 100644 (file)
@@ -101,7 +101,7 @@ TEST(mnt_id) {
                  * See #11505. */
                 assert_se(q = hashmap_get(h, INT_TO_PTR(mnt_id2)));
 
-                assert_se((r = path_is_mount_point(p, NULL, 0)) >= 0);
+                assert_se((r = path_is_mount_point_full(p, NULL, 0)) >= 0);
                 if (r == 0) {
                         /* If the path is not a mount point anymore, then it must be a sub directory of
                          * the path corresponds to mnt_id2. */
@@ -123,20 +123,20 @@ TEST(path_is_mount_point) {
         _cleanup_free_ char *dir1 = NULL, *dir1file = NULL, *dirlink1 = NULL, *dirlink1file = NULL;
         _cleanup_free_ char *dir2 = NULL, *dir2file = NULL;
 
-        assert_se(path_is_mount_point("/", NULL, AT_SYMLINK_FOLLOW) > 0);
-        assert_se(path_is_mount_point("/", NULL, 0) > 0);
-        assert_se(path_is_mount_point("//", NULL, AT_SYMLINK_FOLLOW) > 0);
-        assert_se(path_is_mount_point("//", NULL, 0) > 0);
+        assert_se(path_is_mount_point_full("/", NULL, AT_SYMLINK_FOLLOW) > 0);
+        assert_se(path_is_mount_point_full("/", NULL, 0) > 0);
+        assert_se(path_is_mount_point_full("//", NULL, AT_SYMLINK_FOLLOW) > 0);
+        assert_se(path_is_mount_point_full("//", NULL, 0) > 0);
 
-        assert_se(path_is_mount_point("/proc", NULL, AT_SYMLINK_FOLLOW) > 0);
-        assert_se(path_is_mount_point("/proc", NULL, 0) > 0);
-        assert_se(path_is_mount_point("/proc/", NULL, AT_SYMLINK_FOLLOW) > 0);
-        assert_se(path_is_mount_point("/proc/", NULL, 0) > 0);
+        assert_se(path_is_mount_point_full("/proc", NULL, AT_SYMLINK_FOLLOW) > 0);
+        assert_se(path_is_mount_point_full("/proc", NULL, 0) > 0);
+        assert_se(path_is_mount_point_full("/proc/", NULL, AT_SYMLINK_FOLLOW) > 0);
+        assert_se(path_is_mount_point_full("/proc/", NULL, 0) > 0);
 
-        assert_se(path_is_mount_point("/proc/1", NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point("/proc/1", NULL, 0) == 0);
-        assert_se(path_is_mount_point("/proc/1/", NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point("/proc/1/", NULL, 0) == 0);
+        assert_se(path_is_mount_point_full("/proc/1", NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full("/proc/1", NULL, 0) == 0);
+        assert_se(path_is_mount_point_full("/proc/1/", NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full("/proc/1/", NULL, 0) == 0);
 
         /* we'll create a hierarchy of different kinds of dir/file/link
          * layouts:
@@ -170,10 +170,10 @@ TEST(path_is_mount_point) {
         assert_se(link1);
         assert_se(symlink("file2", link2) == 0);
 
-        assert_se(path_is_mount_point(file1, NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point(file1, NULL, 0) == 0);
-        assert_se(path_is_mount_point(link1, NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point(link1, NULL, 0) == 0);
+        assert_se(path_is_mount_point_full(file1, NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full(file1, NULL, 0) == 0);
+        assert_se(path_is_mount_point_full(link1, NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full(link1, NULL, 0) == 0);
 
         /* directory mountpoints */
         dir1 = path_join(tmp_dir, "dir1");
@@ -189,10 +189,10 @@ TEST(path_is_mount_point) {
         assert_se(dir2);
         assert_se(mkdir(dir2, 0755) == 0);
 
-        assert_se(path_is_mount_point(dir1, NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point(dir1, NULL, 0) == 0);
-        assert_se(path_is_mount_point(dirlink1, NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point(dirlink1, NULL, 0) == 0);
+        assert_se(path_is_mount_point_full(dir1, NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full(dir1, NULL, 0) == 0);
+        assert_se(path_is_mount_point_full(dirlink1, NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full(dirlink1, NULL, 0) == 0);
 
         /* file in subdirectory mountpoints */
         dir1file = path_join(dir1, "file");
@@ -201,10 +201,10 @@ TEST(path_is_mount_point) {
         assert_se(fd > 0);
         close(fd);
 
-        assert_se(path_is_mount_point(dir1file, NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point(dir1file, NULL, 0) == 0);
-        assert_se(path_is_mount_point(dirlink1file, NULL, AT_SYMLINK_FOLLOW) == 0);
-        assert_se(path_is_mount_point(dirlink1file, NULL, 0) == 0);
+        assert_se(path_is_mount_point_full(dir1file, NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full(dir1file, NULL, 0) == 0);
+        assert_se(path_is_mount_point_full(dirlink1file, NULL, AT_SYMLINK_FOLLOW) == 0);
+        assert_se(path_is_mount_point_full(dirlink1file, NULL, 0) == 0);
 
         /* these tests will only work as root */
         if (mount(file1, file2, NULL, MS_BIND, NULL) >= 0) {
@@ -214,17 +214,17 @@ TEST(path_is_mount_point) {
                 /* files */
                 /* capture results in vars, to avoid dangling mounts on failure */
                 log_info("%s: %s", __func__, file2);
-                rf = path_is_mount_point(file2, NULL, 0);
-                rt = path_is_mount_point(file2, NULL, AT_SYMLINK_FOLLOW);
+                rf = path_is_mount_point_full(file2, NULL, 0);
+                rt = path_is_mount_point_full(file2, NULL, AT_SYMLINK_FOLLOW);
 
                 file2d = strjoina(file2, "/");
                 log_info("%s: %s", __func__, file2d);
-                rdf = path_is_mount_point(file2d, NULL, 0);
-                rdt = path_is_mount_point(file2d, NULL, AT_SYMLINK_FOLLOW);
+                rdf = path_is_mount_point_full(file2d, NULL, 0);
+                rdt = path_is_mount_point_full(file2d, NULL, AT_SYMLINK_FOLLOW);
 
                 log_info("%s: %s", __func__, link2);
-                rlf = path_is_mount_point(link2, NULL, 0);
-                rlt = path_is_mount_point(link2, NULL, AT_SYMLINK_FOLLOW);
+                rlf = path_is_mount_point_full(link2, NULL, 0);
+                rlt = path_is_mount_point_full(link2, NULL, AT_SYMLINK_FOLLOW);
 
                 assert_se(umount(file2) == 0);
 
@@ -245,15 +245,15 @@ TEST(path_is_mount_point) {
                 assert_se(mount(dir2, dir1, NULL, MS_BIND, NULL) >= 0);
 
                 log_info("%s: %s", __func__, dir1);
-                rf = path_is_mount_point(dir1, NULL, 0);
-                rt = path_is_mount_point(dir1, NULL, AT_SYMLINK_FOLLOW);
+                rf = path_is_mount_point_full(dir1, NULL, 0);
+                rt = path_is_mount_point_full(dir1, NULL, AT_SYMLINK_FOLLOW);
                 log_info("%s: %s", __func__, dirlink1);
-                rlf = path_is_mount_point(dirlink1, NULL, 0);
-                rlt = path_is_mount_point(dirlink1, NULL, AT_SYMLINK_FOLLOW);
+                rlf = path_is_mount_point_full(dirlink1, NULL, 0);
+                rlt = path_is_mount_point_full(dirlink1, NULL, AT_SYMLINK_FOLLOW);
                 log_info("%s: %s", __func__, dirlink1file);
                 /* its parent is a mount point, but not /file itself */
-                rl1f = path_is_mount_point(dirlink1file, NULL, 0);
-                rl1t = path_is_mount_point(dirlink1file, NULL, AT_SYMLINK_FOLLOW);
+                rl1f = path_is_mount_point_full(dirlink1file, NULL, 0);
+                rl1t = path_is_mount_point_full(dirlink1file, NULL, AT_SYMLINK_FOLLOW);
 
                 assert_se(umount(dir1) == 0);
 
index 95137ffcf12e198a7b1cb8d321d8a16a43877794..3fc83fc043f21ad7cad0ac985caf50d2899eba04 100644 (file)
@@ -73,11 +73,11 @@ TEST(is_symlink) {
 
 TEST(path_is_fs_type) {
         /* run might not be a mount point in build chroots */
-        if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
+        if (path_is_mount_point_full("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
                 assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0);
                 assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0);
         }
-        if (path_is_mount_point("/proc", NULL, AT_SYMLINK_FOLLOW) > 0) {
+        if (path_is_mount_point_full("/proc", NULL, AT_SYMLINK_FOLLOW) > 0) {
                 assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0);
                 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
         }
@@ -95,7 +95,7 @@ TEST(path_is_temporary_fs) {
         }
 
         /* run might not be a mount point in build chroots */
-        if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
+        if (path_is_mount_point_full("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
                 assert_se(path_is_temporary_fs("/run") > 0);
         assert_se(path_is_temporary_fs("/proc") == 0);
         assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT);
@@ -111,7 +111,7 @@ TEST(path_is_read_only_fs) {
                                s, r, r < 0 ? errno_to_name(r) : yes_no(r));
         }
 
-        if (path_is_mount_point("/sys", NULL, AT_SYMLINK_FOLLOW) > 0)
+        if (path_is_mount_point_full("/sys", NULL, AT_SYMLINK_FOLLOW) > 0)
                 assert_se(IN_SET(path_is_read_only_fs("/sys"), 0, 1));
 
         assert_se(path_is_read_only_fs("/proc") == 0);
index 18a60b351e57586bd0c332bb3e426c4301889ec9..7eacb6b81ae9f73b6f10b185d2dde2d606ae7556 100644 (file)
@@ -36,7 +36,7 @@ TEST(udev_resolve_subsys_kernel) {
 }
 
 static int intro(void) {
-        if (path_is_mount_point("/sys", NULL, 0) <= 0)
+        if (path_is_mount_point("/sys") <= 0)
                 return log_tests_skipped("/sys is not mounted");
 
         return EXIT_SUCCESS;
index 3a11dd9b2017f3982be1aa7cc7a41d7c5e5b5551..848667682174d75f1620c589c725040faea9f842 100644 (file)
@@ -81,7 +81,7 @@ static void test2(void) {
 int main(int argc, char *argv[]) {
         _cleanup_free_ char *self = NULL;
 
-        if (path_is_mount_point("/sys", NULL, 0) <= 0)
+        if (path_is_mount_point("/sys") <= 0)
                 return log_tests_skipped("/sys is not mounted");
 
         if (argc > 1) {
index 27be7bdf56fdbaed4c12f21da4661a5a39ed93d4..9ab96504800308382f4d0ece0828304bd0eefbe1 100644 (file)
@@ -154,7 +154,7 @@ static int run(int argc, char *argv[]) {
         if (!IN_SET(m, VOLATILE_YES, VOLATILE_OVERLAY))
                 return 0;
 
-        r = path_is_mount_point(path, NULL, AT_SYMLINK_FOLLOW);
+        r = path_is_mount_point_full(path, /* root = */ NULL, AT_SYMLINK_FOLLOW);
         if (r < 0)
                 return log_error_errno(r, "Couldn't determine whether %s is a mount point: %m", path);
         if (r == 0)