X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=automount.c;h=1192949d837f0996af79e134bb8db2875cfbf3f1;hb=05e343b70453716cc6292b17e7ef175a8c106aad;hp=84691e6e6eb875899c037a157bc5dc3964a5b2e4;hpb=5cb5a6ffc33667c93e9bc3572534dcaa684046e3;p=elogind.git
diff --git a/automount.c b/automount.c
index 84691e6e6..1192949d8 100644
--- a/automount.c
+++ b/automount.c
@@ -1,111 +1,115 @@
/*-*- 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 .
+***/
+
#include
-#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"
+};
+
+static void automount_init(Unit *u) {
+ Automount *a = AUTOMOUNT(u);
- exec_context_defaults(&a->exec_context);
+ a->state = 0;
+ a->mount = NULL;
+}
+
+static int automount_load(Unit *u) {
+ int r;
+ Automount *a = AUTOMOUNT(u);
+
+ assert(u);
+ assert(u->meta.load_state == UNIT_STUB);
/* Load a .automount file */
- if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT)
+ if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
return r;
- /* Load entry from /etc/fstab */
- if ((r = name_load_fstab(n)) < 0)
- return r;
+ if (u->meta.load_state == UNIT_LOADED) {
- /* Load drop-in directory data */
- if ((r = name_load_dropin(n)) < 0)
- return r;
+ if ((r = unit_load_related_unit(u, ".mount", (Unit**) &a->mount)) < 0)
+ return r;
+
+ if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
+ return r;
+ }
return 0;
}
-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);
+static void automount_done(Unit *u) {
+ Automount *a = AUTOMOUNT(u);
- assert(s);
+ assert(a);
- fprintf(f,
- "%sAutomount State: %s\n"
- "%sPath: %s\n",
- prefix, state_table[s->state],
- prefix, s->path);
+ a->mount = NULL;
+}
- exec_context_dump(&s->exec_context, f, prefix);
+static void automount_dump(Unit *u, FILE *f, const char *prefix) {
+ Automount *s = AUTOMOUNT(u);
- for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) {
- ExecCommand *i;
+ assert(s);
- LIST_FOREACH(i, s->exec_command[c])
- fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
- }
+ fprintf(f,
+ "%sAutomount State: %s\n",
+ prefix, state_string_table[s->state]);
}
-static NameActiveState automount_active_state(Name *n) {
+static UnitActiveState automount_active_state(Unit *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,
- };
-
- return table[AUTOMOUNT(n)->state];
+ return state_translation_table[AUTOMOUNT(u)->state];
}
-static void automount_free_hook(Name *n) {
- Automount *d = AUTOMOUNT(n);
+static const char *automount_sub_state_to_string(Unit *u) {
+ assert(u);
- assert(d);
- free(d->path);
+ return state_string_table[AUTOMOUNT(u)->state];
}
-const NameVTable automount_vtable = {
+const UnitVTable automount_vtable = {
.suffix = ".mount",
+ .no_alias = true,
+
+ .init = automount_init,
.load = automount_load,
- .dump = automount_dump,
+ .done = automount_done,
- .start = NULL,
- .stop = NULL,
- .reload = NULL,
+ .dump = automount_dump,
.active_state = automount_active_state,
-
- .free_hook = automount_free_hook
+ .sub_state_to_string = automount_sub_state_to_string
};