From e26d6ce517a49c246141ed20528614823c2f5799 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 29 May 2015 17:13:12 +0200 Subject: [PATCH] path-util: Change path_is_mount_point() symlink arg from bool to flags This makes path_is_mount_point() consistent with fd_is_mount_point() wrt. flags. --- src/core/automount.c | 2 +- src/core/machine-id-setup.c | 2 +- src/core/mount-setup.c | 2 +- src/efi-boot-generator/efi-boot-generator.c | 2 +- src/gpt-auto-generator/gpt-auto-generator.c | 2 +- src/login/logind-user.c | 2 +- src/nspawn/nspawn.c | 10 +++---- src/shared/cgroup-util.c | 2 +- src/shared/condition.c | 2 +- src/shared/machine-pool.c | 2 +- src/shared/path-util.c | 5 ++-- src/shared/path-util.h | 2 +- src/test/test-path-util.c | 32 ++++++++++----------- 13 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/core/automount.c b/src/core/automount.c index 13f80c2abd..d847dc1629 100644 --- a/src/core/automount.c +++ b/src/core/automount.c @@ -747,7 +747,7 @@ static int automount_start(Unit *u) { assert(a); assert(a->state == AUTOMOUNT_DEAD || a->state == AUTOMOUNT_FAILED); - if (path_is_mount_point(a->where, false) > 0) { + if (path_is_mount_point(a->where, 0) > 0) { log_unit_error(u, "Path %s is already a mount point, refusing start.", a->where); return -EEXIST; } diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c index e083c5b347..b3d22840cf 100644 --- a/src/core/machine-id-setup.c +++ b/src/core/machine-id-setup.c @@ -297,7 +297,7 @@ int machine_id_commit(const char *root) { etc_machine_id = path_kill_slashes(x); } - r = path_is_mount_point(etc_machine_id, false); + r = path_is_mount_point(etc_machine_id, 0); if (r < 0) return log_error_errno(r, "Failed to determine whether %s is a mount point: %m", etc_machine_id); if (r == 0) { diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index ba96741e95..c35248eeae 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -156,7 +156,7 @@ static int mount_one(const MountPoint *p, bool relabel) { if (relabel) label_fix(p->where, true, true); - r = path_is_mount_point(p->where, true); + r = path_is_mount_point(p->where, AT_SYMLINK_FOLLOW); if (r < 0 && r != -ENOENT) return r; if (r > 0) diff --git a/src/efi-boot-generator/efi-boot-generator.c b/src/efi-boot-generator/efi-boot-generator.c index 42b21f57de..e6b15c9bb0 100644 --- a/src/efi-boot-generator/efi-boot-generator.c +++ b/src/efi-boot-generator/efi-boot-generator.c @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; } - r = path_is_mount_point("/boot", true); + r = path_is_mount_point("/boot", AT_SYMLINK_FOLLOW); if (r > 0) { log_debug("/boot is already a mount point, exiting."); return EXIT_SUCCESS; diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index b192526186..b46e160888 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -297,7 +297,7 @@ static int probe_and_add_mount( assert(where); assert(description); - if (path_is_mount_point(where, true) <= 0 && + if (path_is_mount_point(where, AT_SYMLINK_FOLLOW) <= 0 && dir_is_empty(where) <= 0) { log_debug("%s already populated, ignoring.", where); return 0; diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 71bff96728..dc3db9abda 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -320,7 +320,7 @@ static int user_mkdir_runtime_path(User *u) { } else p = u->runtime_path; - if (path_is_mount_point(p, false) <= 0) { + if (path_is_mount_point(p, 0) <= 0) { _cleanup_free_ char *t = NULL; (void) mkdir(p, 0700); diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 23bb959171..de755ce538 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1099,7 +1099,7 @@ static int mount_all(const char *dest, bool userns) { if (!where) return log_oom(); - r = path_is_mount_point(where, true); + r = path_is_mount_point(where, AT_SYMLINK_FOLLOW); if (r < 0 && r != -ENOENT) return log_error_errno(r, "Failed to detect whether %s is a mount point: %m", where); @@ -1298,7 +1298,7 @@ static int mount_cgroup_hierarchy(const char *dest, const char *controller, cons to = strjoina(dest, "/sys/fs/cgroup/", hierarchy); - r = path_is_mount_point(to, false); + r = path_is_mount_point(to, 0); if (r < 0 && r != -ENOENT) return log_error_errno(r, "Failed to determine if %s is mounted already: %m", to); if (r > 0) @@ -2154,7 +2154,7 @@ static int setup_journal(const char *directory) { p = strjoina("/var/log/journal/", id); q = prefix_roota(directory, p); - if (path_is_mount_point(p, false) > 0) { + if (path_is_mount_point(p, 0) > 0) { if (arg_link_journal != LINK_AUTO) { log_error("%s: already a mount point, refusing to use for journal", p); return -EEXIST; @@ -2163,7 +2163,7 @@ static int setup_journal(const char *directory) { return 0; } - if (path_is_mount_point(q, false) > 0) { + if (path_is_mount_point(q, 0) > 0) { if (arg_link_journal != LINK_AUTO) { log_error("%s: already a mount point, refusing to use for journal", q); return -EEXIST; @@ -4507,7 +4507,7 @@ int main(int argc, char *argv[]) { * 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, false); + r = path_is_mount_point(arg_directory, 0); if (r < 0) { log_error_errno(r, "Failed to determine whether directory %s is mount point: %m", arg_directory); goto finish; diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index c0b0ca4cf2..9988e5c574 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -489,7 +489,7 @@ int cg_get_path(const char *controller, const char *path, const char *suffix, ch if (_unlikely_(!good)) { int r; - r = path_is_mount_point("/sys/fs/cgroup", false); + r = path_is_mount_point("/sys/fs/cgroup", 0); if (r < 0) return r; if (r == 0) diff --git a/src/shared/condition.c b/src/shared/condition.c index 9f2574c2f6..24871b0dae 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -349,7 +349,7 @@ static int condition_test_path_is_mount_point(Condition *c) { assert(c->parameter); assert(c->type == CONDITION_PATH_IS_MOUNT_POINT); - return path_is_mount_point(c->parameter, true) > 0; + return path_is_mount_point(c->parameter, AT_SYMLINK_FOLLOW) > 0; } static int condition_test_path_is_read_write(Condition *c) { diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index 9920d150ab..447983fb1b 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -198,7 +198,7 @@ int setup_machine_directory(uint64_t size, sd_bus_error *error) { return 0; } - if (path_is_mount_point("/var/lib/machines", true) > 0 || + if (path_is_mount_point("/var/lib/machines", AT_SYMLINK_FOLLOW) > 0 || dir_is_empty("/var/lib/machines") == 0) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "/var/lib/machines is not a btrfs file system. Operation is not supported on legacy file systems."); diff --git a/src/shared/path-util.c b/src/shared/path-util.c index 8be479cd7f..be50a1865d 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -637,7 +637,8 @@ fallback_fstat: return check_st_dev && (a.st_dev != b.st_dev); } -int path_is_mount_point(const char *t, bool allow_symlink) { +/* flags can be AT_SYMLINK_FOLLOW or 0 */ +int path_is_mount_point(const char *t, int flags) { _cleanup_close_ int fd = -1; _cleanup_free_ char *parent = NULL; int r; @@ -655,7 +656,7 @@ int path_is_mount_point(const char *t, bool allow_symlink) { if (fd < 0) return -errno; - return fd_is_mount_point(fd, basename(t), (allow_symlink ? AT_SYMLINK_FOLLOW : 0)); + return fd_is_mount_point(fd, basename(t), flags); } int path_is_read_only_fs(const char *path) { diff --git a/src/shared/path-util.h b/src/shared/path-util.h index 38ad799ba0..1eac89c51b 100644 --- a/src/shared/path-util.h +++ b/src/shared/path-util.h @@ -54,7 +54,7 @@ char** path_strv_resolve(char **l, const char *prefix); char** path_strv_resolve_uniq(char **l, const char *prefix); int fd_is_mount_point(int fd, const char *filename, int flags); -int path_is_mount_point(const char *path, bool allow_symlink); +int path_is_mount_point(const char *path, int flags); int path_is_read_only_fs(const char *path); int path_is_os_tree(const char *path); diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index 80782ff902..0045ae6824 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -316,17 +316,17 @@ static void test_path_is_mount_point(void) { char tmp_dir[] = "/tmp/test-path-is-mount-point-XXXXXX"; _cleanup_free_ char *file1 = NULL, *file2 = NULL, *link1 = NULL, *link2 = NULL; - assert_se(path_is_mount_point("/", true) > 0); - assert_se(path_is_mount_point("/", false) > 0); + assert_se(path_is_mount_point("/", AT_SYMLINK_FOLLOW) > 0); + assert_se(path_is_mount_point("/", 0) > 0); - assert_se(path_is_mount_point("/proc", true) > 0); - assert_se(path_is_mount_point("/proc", false) > 0); + assert_se(path_is_mount_point("/proc", AT_SYMLINK_FOLLOW) > 0); + assert_se(path_is_mount_point("/proc", 0) > 0); - assert_se(path_is_mount_point("/proc/1", true) == 0); - assert_se(path_is_mount_point("/proc/1", false) == 0); + assert_se(path_is_mount_point("/proc/1", AT_SYMLINK_FOLLOW) == 0); + assert_se(path_is_mount_point("/proc/1", 0) == 0); - assert_se(path_is_mount_point("/sys", true) > 0); - assert_se(path_is_mount_point("/sys", false) > 0); + assert_se(path_is_mount_point("/sys", AT_SYMLINK_FOLLOW) > 0); + assert_se(path_is_mount_point("/sys", 0) > 0); /* file mountpoints */ assert_se(mkdtemp(tmp_dir) != NULL); @@ -347,17 +347,17 @@ static void test_path_is_mount_point(void) { assert_se(link1); assert_se(symlink("file2", link2) == 0); - assert_se(path_is_mount_point(file1, true) == 0); - assert_se(path_is_mount_point(file1, false) == 0); - assert_se(path_is_mount_point(link1, true) == 0); - assert_se(path_is_mount_point(link1, false) == 0); + assert_se(path_is_mount_point(file1, AT_SYMLINK_FOLLOW) == 0); + assert_se(path_is_mount_point(file1, 0) == 0); + assert_se(path_is_mount_point(link1, AT_SYMLINK_FOLLOW) == 0); + assert_se(path_is_mount_point(link1, 0) == 0); /* this test will only work as root */ if (mount(file1, file2, NULL, MS_BIND, NULL) >= 0) { - rf = path_is_mount_point(file2, false); - rt = path_is_mount_point(file2, true); - rlf = path_is_mount_point(link2, false); - rlt = path_is_mount_point(link2, true); + rf = path_is_mount_point(file2, 0); + rt = path_is_mount_point(file2, AT_SYMLINK_FOLLOW); + rlf = path_is_mount_point(link2, 0); + rlt = path_is_mount_point(link2, AT_SYMLINK_FOLLOW); assert_se(umount(file2) == 0);