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.
This commit is contained in:
Martin Pitt 2015-05-29 17:13:12 +02:00
parent 5d40903401
commit e26d6ce517
13 changed files with 34 additions and 33 deletions

View File

@ -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;
}

View File

@ -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) {

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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) {

View File

@ -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.");

View File

@ -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) {

View File

@ -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);

View File

@ -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);