chiark / gitweb /
mount: only add those mount points to localfs.target as Wants that are marked for us
[elogind.git] / mount.c
diff --git a/mount.c b/mount.c
index d52c11d3cabd9d7f15bef62589c85ff18474eb22..2e3abcc6bc4a080db8f50b6ebe6a8eaa6594d15f 100644 (file)
--- a/mount.c
+++ b/mount.c
@@ -65,6 +65,16 @@ static const char* const state_string_table[_MOUNT_STATE_MAX] = {
         [MOUNT_MAINTAINANCE] = "maintainance"
 };
 
+static void service_unwatch_control_pid(Mount *m) {
+        assert(m);
+
+        if (m->control_pid <= 0)
+                return;
+
+        unit_unwatch_pid(UNIT(m), m->control_pid);
+        m->control_pid = 0;
+}
+
 static void mount_parameters_done(MountParameters *p) {
         assert(p);
 
@@ -91,10 +101,7 @@ static void mount_done(Unit *u) {
         exec_command_done_array(m->exec_command, _MOUNT_EXEC_COMMAND_MAX);
         m->control_command = NULL;
 
-        if (m->control_pid > 0) {
-                unit_unwatch_pid(u, m->control_pid);
-                m->control_pid = 0;
-        }
+        service_unwatch_control_pid(m);
 
         unit_unwatch_timer(u, &m->timer_watch);
 }
@@ -237,6 +244,8 @@ static int mount_add_target_links(Mount *m) {
         MountParameters *p;
         Unit *u;
         int r;
+        bool noauto;
+        bool handle;
 
         assert(m);
 
@@ -247,10 +256,10 @@ static int mount_add_target_links(Mount *m) {
         else
                 return 0;
 
-        if (!p->fstype)
-                return 0;
+        noauto = mount_test_option(p->options, MNTOPT_NOAUTO);
+        handle = mount_test_option(p->options, "comment=systemd.mount");
 
-        if (mount_test_option(p->options, MNTOPT_NOAUTO))
+        if (noauto && !handle)
                 return 0;
 
         if (mount_test_option(p->options, "_netdev") ||
@@ -262,8 +271,9 @@ static int mount_add_target_links(Mount *m) {
         if ((r = manager_load_unit(UNIT(m)->meta.manager, target, &u)) < 0)
                 return r;
 
-        if ((r = unit_add_dependency(u, UNIT_WANTS, UNIT(m))) < 0)
-                return r;
+        if (handle)
+                if ((r = unit_add_dependency(u, UNIT_WANTS, UNIT(m))) < 0)
+                        return r;
 
         return unit_add_dependency(UNIT(m), UNIT_BEFORE, u);
 }
@@ -322,12 +332,7 @@ static void mount_set_state(Mount *m, MountState state) {
             state != MOUNT_REMOUNTING_SIGTERM &&
             state != MOUNT_REMOUNTING_SIGKILL) {
                 unit_unwatch_timer(UNIT(m), &m->timer_watch);
-
-                if (m->control_pid > 0) {
-                        unit_unwatch_pid(UNIT(m), m->control_pid);
-                        m->control_pid = 0;
-                }
-
+                service_unwatch_control_pid(m);
                 m->control_command = NULL;
         }
 
@@ -365,6 +370,7 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) {
                             NULL, 0,
                             true,
                             true,
+                            UNIT(m)->meta.manager->confirm_spawn,
                             UNIT(m)->meta.cgroup_bondings,
                             &pid)) < 0)
                 goto fail;
@@ -434,21 +440,28 @@ static void mount_enter_dead(Mount *m, bool success) {
         mount_set_state(m, m->failure ? MOUNT_MAINTAINANCE : MOUNT_DEAD);
 }
 
+static void mount_enter_mounted(Mount *m, bool success) {
+        assert(m);
+
+        if (!success)
+                m->failure = true;
+
+        mount_set_state(m, MOUNT_MOUNTED);
+}
+
 static void mount_enter_signal(Mount *m, MountState state, bool success) {
         int r;
+        bool sent = false;
 
         assert(m);
 
         if (!success)
                 m->failure = true;
 
-        if (m->control_pid > 0) {
-                int sig;
-                bool sent = false;
-
-                sig = (state == MOUNT_MOUNTING_SIGTERM ||
-                       state == MOUNT_UNMOUNTING_SIGTERM ||
-                       state == MOUNT_REMOUNTING_SIGTERM) ? SIGTERM : SIGKILL;
+        if (m->kill_mode != KILL_NONE) {
+                int sig = (state == MOUNT_MOUNTING_SIGTERM ||
+                           state == MOUNT_UNMOUNTING_SIGTERM ||
+                           state == MOUNT_REMOUNTING_SIGTERM) ? SIGTERM : SIGKILL;
 
                 if (m->kill_mode == KILL_CONTROL_GROUP) {
 
@@ -459,32 +472,32 @@ static void mount_enter_signal(Mount *m, MountState state, bool success) {
                                 sent = true;
                 }
 
-                if (!sent)
+                if (!sent && m->control_pid > 0)
                         if (kill(m->kill_mode == KILL_PROCESS ? m->control_pid : -m->control_pid, sig) < 0 && errno != ESRCH) {
                                 r = -errno;
                                 goto fail;
                         }
         }
 
-        mount_set_state(m, state);
+        if (sent) {
+                if ((r = unit_watch_timer(UNIT(m), m->timeout_usec, &m->timer_watch)) < 0)
+                        goto fail;
 
-        if (m->control_pid <= 0)
+                mount_set_state(m, state);
+        } else if (state == MOUNT_REMOUNTING_SIGTERM || state == MOUNT_REMOUNTING_SIGKILL)
+                mount_enter_mounted(m, true);
+        else
                 mount_enter_dead(m, true);
 
         return;
 
 fail:
         log_warning("%s failed to kill processes: %s", unit_id(UNIT(m)), strerror(-r));
-        mount_enter_dead(m, false);
-}
-
-static void mount_enter_mounted(Mount *m, bool success) {
-        assert(m);
-
-        if (!success)
-                m->failure = true;
 
-        mount_set_state(m, MOUNT_MOUNTED);
+        if (state == MOUNT_REMOUNTING_SIGTERM || state == MOUNT_REMOUNTING_SIGKILL)
+                mount_enter_mounted(m, false);
+        else
+                mount_enter_dead(m, false);
 }
 
 static void mount_enter_unmounting(Mount *m, bool success) {
@@ -505,6 +518,8 @@ static void mount_enter_unmounting(Mount *m, bool success) {
                              NULL)) < 0)
                 goto fail;
 
+        service_unwatch_control_pid(m);
+
         if ((r = mount_spawn(m, c, &m->control_pid)) < 0)
                 goto fail;
 
@@ -549,6 +564,8 @@ static void mount_enter_mounting(Mount *m, bool success) {
         if (r < 0)
                 goto fail;
 
+        service_unwatch_control_pid(m);
+
         if ((r = mount_spawn(m, c, &m->control_pid)) < 0)
                 goto fail;
 
@@ -620,6 +637,8 @@ static void mount_enter_remounting(Mount *m, bool success) {
                 goto fail;
         }
 
+        service_unwatch_control_pid(m);
+
         if ((r = mount_spawn(m, c, &m->control_pid)) < 0)
                 goto fail;
 
@@ -704,6 +723,12 @@ static UnitActiveState mount_active_state(Unit *u) {
         return state_translation_table[MOUNT(u)->state];
 }
 
+static const char *mount_sub_state_to_string(Unit *u) {
+        assert(u);
+
+        return state_string_table[MOUNT(u)->state];
+}
+
 static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         Mount *m = MOUNT(u);
         bool success;
@@ -1270,6 +1295,7 @@ const UnitVTable mount_vtable = {
         .reload = mount_reload,
 
         .active_state = mount_active_state,
+        .sub_state_to_string = mount_sub_state_to_string,
 
         .sigchld_event = mount_sigchld_event,
         .timer_event = mount_timer_event,