X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fmount.c;h=5577f16dfd7a18ff0cba8919d27bfc886d0d7129;hp=ec03a52f6a7c4442d3f29e4893040dd769624797;hb=2279955bb56859e76702bd9c40a0b875bd6c6bb8;hpb=e99e38bbdcca3fe5956823bdb3d38544ccf93221 diff --git a/src/mount.c b/src/mount.c index ec03a52f6..5577f16df 100644 --- a/src/mount.c +++ b/src/mount.c @@ -167,6 +167,19 @@ static int mount_add_swap_links(Mount *m) { return 0; } +static int mount_add_path_links(Mount *m) { + Meta *other; + int r; + + assert(m); + + LIST_FOREACH(units_per_type, other, m->meta.manager->units_per_type[UNIT_PATH]) + if ((r = path_add_one_mount_link((Path*) other, m)) < 0) + return r; + + return 0; +} + static int mount_add_automount_links(Mount *m) { Meta *other; int r; @@ -215,7 +228,7 @@ static int mount_add_target_links(Mount *m) { MountParameters *p; Unit *tu; int r; - bool noauto, handle, automount; + bool noauto, handle, automount, user; assert(m); @@ -227,6 +240,7 @@ static int mount_add_target_links(Mount *m) { return 0; noauto = !!mount_test_option(p->options, MNTOPT_NOAUTO); + user = mount_test_option(p->options, "user") || mount_test_option(p->options, "users"); handle = !!mount_test_option(p->options, "comment=systemd.mount"); automount = !!mount_test_option(p->options, "comment=systemd.automount"); @@ -239,7 +253,7 @@ static int mount_add_target_links(Mount *m) { if ((r = manager_load_unit(UNIT(m)->meta.manager, target, NULL, &tu)) < 0) return r; - if (automount) { + if (automount && m->meta.manager->running_as != MANAGER_SESSION) { Unit *am; if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0) @@ -253,8 +267,9 @@ static int mount_add_target_links(Mount *m) { } else { if (!noauto && handle) - if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0) - return r; + if (user || m->meta.manager->running_as != MANAGER_SESSION) + if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0) + return r; return unit_add_dependency(UNIT(m), UNIT_BEFORE, tu, true); } @@ -265,9 +280,12 @@ static int mount_verify(Mount *m) { char *e; assert(m); - if (UNIT(m)->meta.load_state != UNIT_LOADED) + if (m->meta.load_state != UNIT_LOADED) return 0; + if (!m->from_etc_fstab && !m->from_fragment && !m->from_proc_self_mountinfo) + return -ENOENT; + if (!(e = unit_name_from_path(m->where, ".mount"))) return -ENOMEM; @@ -336,6 +354,9 @@ static int mount_load(Unit *u) { if ((r = mount_add_swap_links(m)) < 0) return r; + if ((r = mount_add_path_links(m)) < 0) + return r; + if ((r = mount_add_automount_links(m)) < 0) return r; @@ -931,7 +952,7 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) { case MOUNT_REMOUNTING_SIGKILL: case MOUNT_REMOUNTING_SIGTERM: - if (success && m->from_proc_self_mountinfo) + if (success) mount_enter_mounted(m, true); else if (m->from_proc_self_mountinfo) mount_enter_mounted(m, false); @@ -1241,7 +1262,7 @@ finish: static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) { int r; - char *device, *path, *options, *fstype, *d, *p; + char *device, *path, *options, *options2, *fstype, *d, *p, *o; assert(m); @@ -1250,7 +1271,7 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) { for (;;) { int k; - device = path = options = fstype = d = p = NULL; + device = path = options = options2 = fstype = d = p = o = NULL; if ((k = fscanf(m->proc_self_mountinfo, "%*s " /* (1) mount id */ @@ -1263,11 +1284,13 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) { "- " /* (8) seperator */ "%ms " /* (9) file system type */ "%ms" /* (10) mount source */ + "%ms" /* (11) mount options 2 */ "%*[^\n]", /* some rubbish at the end */ &path, &options, &fstype, - &device)) != 4) { + &device, + &options2)) != 5) { if (k == EOF) break; @@ -1276,21 +1299,28 @@ static int mount_load_proc_self_mountinfo(Manager *m, bool set_flags) { goto finish; } + if (asprintf(&o, "%s,%s", options, options2) < 0) { + r = -ENOMEM; + goto finish; + } + if (!(d = cunescape(device)) || !(p = cunescape(path))) { r = -ENOMEM; goto finish; } - if ((r = mount_add_one(m, d, p, options, fstype, true, set_flags)) < 0) + if ((r = mount_add_one(m, d, p, o, fstype, true, set_flags)) < 0) goto finish; free(device); free(path); free(options); + free(options2); free(fstype); free(d); free(p); + free(o); } r = 0; @@ -1299,9 +1329,11 @@ finish: free(device); free(path); free(options); + free(options2); free(fstype); free(d); free(p); + free(o); return r; }