chiark / gitweb /
manager: we are not interested in SIGSTOP notifications
[elogind.git] / automount.c
index c28472da769106f1ff61f6d633094f257d3552b5..c6ce25d8b254eba93bcc815437bb3e798c906fc0 100644 (file)
 #include "load-fragment.h"
 #include "load-dropin.h"
 
-static int automount_init(Unit *u, UnitLoadState *new_state) {
-        int r;
-        Automount *a = AUTOMOUNT(u);
+static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
+        [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
+        [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
+        [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
+        [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
+};
 
-        assert(a);
+static const char* const state_string_table[_AUTOMOUNT_STATE_MAX] = {
+        [AUTOMOUNT_DEAD] = "dead",
+        [AUTOMOUNT_WAITING] = "waiting",
+        [AUTOMOUNT_RUNNING] = "running",
+        [AUTOMOUNT_MAINTAINANCE] = "maintainance"
+};
 
-        exec_context_init(&a->exec_context);
+static void automount_init(Unit *u) {
+        Automount *a = AUTOMOUNT(u);
 
-        /* Load a .automount file */
-        if ((r = unit_load_fragment(u, new_state)) < 0)
-                return r;
+        a->state = 0;
+        a->mount = NULL;
+}
 
-        if (*new_state == UNIT_STUB)
-                *new_state = UNIT_LOADED;
+static int automount_load(Unit *u) {
+        int r;
+        Automount *a = AUTOMOUNT(u);
 
-        /* Load drop-in directory data */
-        if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
-                return r;
+        assert(u);
+        assert(u->meta.load_state == UNIT_STUB);
 
-        if (*new_state == UNIT_LOADED) {
+        /* Load a .automount file */
+        if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
+                return r;
 
-                if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
-                        return r;
+        if (u->meta.load_state == UNIT_LOADED) {
 
-                if ((r = unit_add_exec_dependencies(u, &a->exec_context)) < 0)
+                if ((r = unit_load_related_unit(u, ".mount", (Unit**) &a->mount)) < 0)
                         return r;
 
-                if ((r = unit_add_default_cgroup(u)) < 0)
+                if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
                         return r;
         }
 
@@ -61,73 +71,35 @@ static int automount_init(Unit *u, UnitLoadState *new_state) {
 }
 
 static void automount_done(Unit *u) {
-        Automount *d = AUTOMOUNT(u);
+        Automount *a = AUTOMOUNT(u);
+
+        assert(a);
 
-        assert(d);
-        free(d->path);
+        a->mount = NULL;
 }
 
 static void automount_dump(Unit *u, FILE *f, const char *prefix) {
-
-        static const char* const state_table[_AUTOMOUNT_STATE_MAX] = {
-                [AUTOMOUNT_DEAD] = "dead",
-                [AUTOMOUNT_START_PRE] = "start-pre",
-                [AUTOMOUNT_START_POST] = "start-post",
-                [AUTOMOUNT_WAITING] = "waiting",
-                [AUTOMOUNT_RUNNING] = "running",
-                [AUTOMOUNT_STOP_PRE] = "stop-pre",
-                [AUTOMOUNT_STOP_POST] = "stop-post",
-                [AUTOMOUNT_MAINTAINANCE] = "maintainance"
-        };
-
-        static const char* const command_table[_AUTOMOUNT_EXEC_MAX] = {
-                [AUTOMOUNT_EXEC_START_PRE] = "StartPre",
-                [AUTOMOUNT_EXEC_START_POST] = "StartPost",
-                [AUTOMOUNT_EXEC_STOP_PRE] = "StopPre",
-                [AUTOMOUNT_EXEC_STOP_POST] = "StopPost"
-        };
-
-        AutomountExecCommand c;
         Automount *s = AUTOMOUNT(u);
 
         assert(s);
 
         fprintf(f,
-                "%sAutomount State: %s\n"
-                "%sPath: %s\n",
-                prefix, state_table[s->state],
-                prefix, s->path);
-
-        exec_context_dump(&s->exec_context, f, prefix);
-
-        for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) {
-                ExecCommand *i;
-
-                LIST_FOREACH(command, i, s->exec_command[c])
-                        fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
-        }
+                "%sAutomount State: %s\n",
+                prefix, state_string_table[s->state]);
 }
 
 static UnitActiveState automount_active_state(Unit *u) {
 
-        static const UnitActiveState table[_AUTOMOUNT_STATE_MAX] = {
-                [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
-                [AUTOMOUNT_START_PRE] = UNIT_ACTIVATING,
-                [AUTOMOUNT_START_POST] = UNIT_ACTIVATING,
-                [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
-                [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
-                [AUTOMOUNT_STOP_PRE] = UNIT_DEACTIVATING,
-                [AUTOMOUNT_STOP_POST] = UNIT_DEACTIVATING,
-                [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
-        };
-
-        return table[AUTOMOUNT(u)->state];
+        return state_translation_table[AUTOMOUNT(u)->state];
 }
 
 const UnitVTable automount_vtable = {
         .suffix = ".mount",
 
+        .no_alias = true,
+
         .init = automount_init,
+        .load = automount_load,
         .done = automount_done,
 
         .dump = automount_dump,