From e86b3761c42babc190a1e1b6d4288dfa7a4208b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 1 Jan 2015 14:25:18 -0500 Subject: [PATCH] mount: do not use -n when running in --user mode -n is only allowed for root. /etc/mtab is nowadays almost always a link to /proc/, so in practice this does not really matter too much, but should allow .mount units to work in --user mode. https://bugs.freedesktop.org/show_bug.cgi?id=87602 --- src/core/mount.c | 49 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index 110eafdc4..13c634807 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -879,11 +879,9 @@ static void mount_enter_unmounting(Mount *m) { m->control_command_id = MOUNT_EXEC_UNMOUNT; m->control_command = m->exec_command + MOUNT_EXEC_UNMOUNT; - r = exec_command_set(m->control_command, - "/bin/umount", - "-n", - m->where, - NULL); + r = exec_command_set(m->control_command, "/bin/umount", m->where, NULL); + if (r >= 0 && UNIT(m)->manager->running_as == SYSTEMD_SYSTEM) + r = exec_command_append(m->control_command, "-n", NULL); if (r < 0) goto fail; @@ -926,17 +924,18 @@ static void mount_enter_mounting(Mount *m) { if (r < 0) goto fail; - if (m->from_fragment) - r = exec_command_set( - m->control_command, - "/bin/mount", - m->sloppy_options ? "-ns" : "-n", - m->parameters_fragment.what, - m->where, - "-t", m->parameters_fragment.fstype ? m->parameters_fragment.fstype : "auto", - m->parameters_fragment.options ? "-o" : NULL, m->parameters_fragment.options, - NULL); - else + if (m->from_fragment) { + r = exec_command_set(m->control_command, "/bin/mount", + m->parameters_fragment.what, m->where, NULL); + if (r >= 0 && UNIT(m)->manager->running_as == SYSTEMD_SYSTEM) + r = exec_command_append(m->control_command, "-n", NULL); + if (r >= 0 && m->sloppy_options) + r = exec_command_append(m->control_command, "-s", NULL); + if (r >= 0 && m->parameters_fragment.fstype) + r = exec_command_append(m->control_command, "-t", m->parameters_fragment.fstype, NULL); + if (r >= 0 && m->parameters_fragment.options) + r = exec_command_append(m->control_command, "-o", m->parameters_fragment.options, NULL); + } else r = -ENOENT; if (r < 0) @@ -975,15 +974,15 @@ static void mount_enter_remounting(Mount *m) { else o = "remount"; - r = exec_command_set( - m->control_command, - "/bin/mount", - m->sloppy_options ? "-ns" : "-n", - m->parameters_fragment.what, - m->where, - "-t", m->parameters_fragment.fstype ? m->parameters_fragment.fstype : "auto", - "-o", o, - NULL); + r = exec_command_set(m->control_command, "/bin/mount", + m->parameters_fragment.what, m->where, + "-o", o, NULL); + if (r >= 0 && UNIT(m)->manager->running_as == SYSTEMD_SYSTEM) + r = exec_command_append(m->control_command, "-n", NULL); + if (r >= 0 && m->sloppy_options) + r = exec_command_append(m->control_command, "-s", NULL); + if (r >= 0 && m->parameters_fragment.fstype) + r = exec_command_append(m->control_command, "-t", m->parameters_fragment.fstype, NULL); } else r = -ENOENT; -- 2.30.2