chiark / gitweb /
manager: get rid of destinction between running_as=system and running_as=init, as...
[elogind.git] / src / mount.c
index 01fc2dffbbee3bbbe057b27511f5f98b675e9fd8..c95581fd1ed541b2428f681fb0bd281858c317f1 100644 (file)
@@ -35,6 +35,7 @@
 #include "unit-name.h"
 #include "mount.h"
 #include "dbus-mount.h"
+#include "special.h"
 
 static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
         [MOUNT_DEAD] = UNIT_INACTIVE,
@@ -49,7 +50,7 @@ static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = {
         [MOUNT_REMOUNTING_SIGKILL] = UNIT_ACTIVE_RELOADING,
         [MOUNT_UNMOUNTING_SIGTERM] = UNIT_DEACTIVATING,
         [MOUNT_UNMOUNTING_SIGKILL] = UNIT_DEACTIVATING,
-        [MOUNT_MAINTAINANCE] = UNIT_INACTIVE,
+        [MOUNT_MAINTENANCE] = UNIT_INACTIVE,
 };
 
 static void mount_init(Unit *u) {
@@ -167,6 +168,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;
@@ -240,7 +254,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 && m->meta.manager->running_as != MANAGER_SESSION) {
+        if (automount && m->meta.manager->running_as == MANAGER_SYSTEM) {
                 Unit *am;
 
                 if ((r = unit_load_related_unit(UNIT(m), ".automount", &am)) < 0)
@@ -254,7 +268,7 @@ static int mount_add_target_links(Mount *m) {
         } else {
 
                 if (!noauto && handle)
-                        if (user || m->meta.manager->running_as != MANAGER_SESSION)
+                        if (user || m->meta.manager->running_as == MANAGER_SYSTEM)
                                 if ((r = unit_add_dependency(tu, UNIT_WANTS, UNIT(m), true)) < 0)
                                         return r;
 
@@ -327,9 +341,7 @@ static int mount_load(Unit *u) {
                         what = m->parameters_proc_self_mountinfo.what;
 
                 if (what)
-                        if ((r = unit_add_node_link(u, what,
-                                                    (u->meta.manager->running_as == MANAGER_INIT ||
-                                                     u->meta.manager->running_as == MANAGER_SYSTEM))) < 0)
+                        if ((r = unit_add_node_link(u, what, u->meta.manager->running_as == MANAGER_SYSTEM)) < 0)
                                 return r;
 
                 if ((r = mount_add_mount_links(m)) < 0)
@@ -341,6 +353,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;
 
@@ -400,7 +415,7 @@ static void mount_set_state(Mount *m, MountState state) {
                  state == MOUNT_REMOUNTING_SIGKILL ||
                  state == MOUNT_UNMOUNTING_SIGTERM ||
                  state == MOUNT_UNMOUNTING_SIGKILL ||
-                 state == MOUNT_MAINTAINANCE)
+                 state == MOUNT_MAINTENANCE)
                 mount_notify_automount(m, -ENODEV);
 
         if (state != old_state)
@@ -539,7 +554,7 @@ static void mount_enter_dead(Mount *m, bool success) {
         if (!success)
                 m->failure = true;
 
-        mount_set_state(m, m->failure ? MOUNT_MAINTAINANCE : MOUNT_DEAD);
+        mount_set_state(m, m->failure ? MOUNT_MAINTENANCE : MOUNT_DEAD);
 }
 
 static void mount_enter_mounted(Mount *m, bool success) {
@@ -764,7 +779,7 @@ static int mount_start(Unit *u) {
             m->state == MOUNT_MOUNTING_SIGKILL)
                 return 0;
 
-        assert(m->state == MOUNT_DEAD || m->state == MOUNT_MAINTAINANCE);
+        assert(m->state == MOUNT_DEAD || m->state == MOUNT_MAINTENANCE);
 
         m->failure = false;
         mount_enter_mounting(m);
@@ -823,7 +838,7 @@ static int mount_serialize(Unit *u, FILE *f, FDSet *fds) {
         unit_serialize_item(u, f, "failure", yes_no(m->failure));
 
         if (m->control_pid > 0)
-                unit_serialize_item_format(u, f, "control-pid", "%u", (unsigned) m->control_pid);
+                unit_serialize_item_format(u, f, "control-pid", "%lu", (unsigned long) m->control_pid);
 
         if (m->control_command_id >= 0)
                 unit_serialize_item(u, f, "control-command", mount_exec_command_to_string(m->control_command_id));
@@ -856,12 +871,12 @@ static int mount_deserialize_item(Unit *u, const char *key, const char *value, F
                         m->failure = b || m->failure;
 
         } else if (streq(key, "control-pid")) {
-                unsigned pid;
+                pid_t pid;
 
-                if ((r = safe_atou(value, &pid)) < 0 || pid <= 0)
+                if ((r = parse_pid(value, &pid)) < 0)
                         log_debug("Failed to parse control-pid value %s", value);
                 else
-                        m->control_pid = (pid_t) pid;
+                        m->control_pid = pid;
         } else if (streq(key, "control-command")) {
                 MountExecCommand id;
 
@@ -905,12 +920,14 @@ static void mount_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         assert(m);
         assert(pid >= 0);
 
-        success = is_clean_exit(code, status);
-        m->failure = m->failure || !success;
+        if (pid != m->control_pid)
+                return;
 
-        assert(m->control_pid == pid);
         m->control_pid = 0;
 
+        success = is_clean_exit(code, status);
+        m->failure = m->failure || !success;
+
         if (m->control_command) {
                 exec_status_fill(&m->control_command->exec_status, pid, code, status);
                 m->control_command = NULL;
@@ -1246,7 +1263,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);
 
@@ -1255,7 +1272,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 */
@@ -1268,11 +1285,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;
@@ -1281,21 +1300,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;
@@ -1304,9 +1330,11 @@ finish:
         free(device);
         free(path);
         free(options);
+        free(options2);
         free(fstype);
         free(d);
         free(p);
+        free(o);
 
         return r;
 }
@@ -1406,7 +1434,7 @@ void mount_fd_event(Manager *m, int events) {
                         switch (mount->state) {
 
                         case MOUNT_DEAD:
-                        case MOUNT_MAINTAINANCE:
+                        case MOUNT_MAINTENANCE:
                                 mount_enter_mounted(mount, true);
                                 break;
 
@@ -1494,7 +1522,7 @@ static const char* const mount_state_table[_MOUNT_STATE_MAX] = {
         [MOUNT_REMOUNTING_SIGKILL] = "remounting-sigkill",
         [MOUNT_UNMOUNTING_SIGTERM] = "unmounting-sigterm",
         [MOUNT_UNMOUNTING_SIGKILL] = "unmounting-sigkill",
-        [MOUNT_MAINTAINANCE] = "maintainance"
+        [MOUNT_MAINTENANCE] = "maintenance"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(mount_state, MountState);