chiark / gitweb /
manager: we are not interested in SIGSTOP notifications
[elogind.git] / automount.c
index 84691e6e6eb875899c037a157bc5dc3964a5b2e4..c6ce25d8b254eba93bcc815437bb3e798c906fc0 100644 (file)
 /*-*- Mode: C; c-basic-offset: 8 -*-*/
 
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
 #include <errno.h>
 
-#include "name.h"
+#include "unit.h"
 #include "automount.h"
 #include "load-fragment.h"
-#include "load-fstab.h"
 #include "load-dropin.h"
 
-static int automount_load(Name *n) {
-        int r;
-        Automount *a = AUTOMOUNT(n);
+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_defaults(&a->exec_context);
+static void automount_init(Unit *u) {
+        Automount *a = AUTOMOUNT(u);
 
-        /* Load a .automount file */
-        if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT)
-                return r;
+        a->state = 0;
+        a->mount = NULL;
+}
 
-        /* Load entry from /etc/fstab */
-        if ((r = name_load_fstab(n)) < 0)
-                return r;
+static int automount_load(Unit *u) {
+        int r;
+        Automount *a = AUTOMOUNT(u);
 
-        /* Load drop-in directory data */
-        if ((r = name_load_dropin(n)) < 0)
+        assert(u);
+        assert(u->meta.load_state == UNIT_STUB);
+
+        /* Load a .automount file */
+        if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
                 return r;
 
-        return 0;
-}
+        if (u->meta.load_state == UNIT_LOADED) {
 
-static void automount_dump(Name *n, 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(n);
+                if ((r = unit_load_related_unit(u, ".mount", (Unit**) &a->mount)) < 0)
+                        return r;
 
-        assert(s);
+                if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
+                        return r;
+        }
 
-        fprintf(f,
-                "%sAutomount State: %s\n"
-                "%sPath: %s\n",
-                prefix, state_table[s->state],
-                prefix, s->path);
+        return 0;
+}
 
-        exec_context_dump(&s->exec_context, f, prefix);
+static void automount_done(Unit *u) {
+        Automount *a = AUTOMOUNT(u);
 
-        for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) {
-                ExecCommand *i;
+        assert(a);
 
-                LIST_FOREACH(i, s->exec_command[c])
-                        fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
-        }
+        a->mount = NULL;
 }
 
-static NameActiveState automount_active_state(Name *n) {
+static void automount_dump(Unit *u, FILE *f, const char *prefix) {
+        Automount *s = AUTOMOUNT(u);
 
-        static const NameActiveState table[_AUTOMOUNT_STATE_MAX] = {
-                [AUTOMOUNT_DEAD] = NAME_INACTIVE,
-                [AUTOMOUNT_START_PRE] = NAME_ACTIVATING,
-                [AUTOMOUNT_START_POST] = NAME_ACTIVATING,
-                [AUTOMOUNT_WAITING] = NAME_ACTIVE,
-                [AUTOMOUNT_RUNNING] = NAME_ACTIVE,
-                [AUTOMOUNT_STOP_PRE] = NAME_DEACTIVATING,
-                [AUTOMOUNT_STOP_POST] = NAME_DEACTIVATING,
-                [AUTOMOUNT_MAINTAINANCE] = NAME_INACTIVE,
-        };
+        assert(s);
 
-        return table[AUTOMOUNT(n)->state];
+        fprintf(f,
+                "%sAutomount State: %s\n",
+                prefix, state_string_table[s->state]);
 }
 
-static void automount_free_hook(Name *n) {
-        Automount *d = AUTOMOUNT(n);
+static UnitActiveState automount_active_state(Unit *u) {
 
-        assert(d);
-        free(d->path);
+        return state_translation_table[AUTOMOUNT(u)->state];
 }
 
-const NameVTable automount_vtable = {
+const UnitVTable automount_vtable = {
         .suffix = ".mount",
 
-        .load = automount_load,
-        .dump = automount_dump,
+        .no_alias = true,
 
-        .start = NULL,
-        .stop = NULL,
-        .reload = NULL,
+        .init = automount_init,
+        .load = automount_load,
+        .done = automount_done,
 
-        .active_state = automount_active_state,
+        .dump = automount_dump,
 
-        .free_hook = automount_free_hook
+        .active_state = automount_active_state
 };