X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=automount.c;h=c28472da769106f1ff61f6d633094f257d3552b5;hp=84691e6e6eb875899c037a157bc5dc3964a5b2e4;hb=a90ebccc072efa17313fe68c737b3507247c37dd;hpb=5cb5a6ffc33667c93e9bc3572534dcaa684046e3 diff --git a/automount.c b/automount.c index 84691e6e6..c28472da7 100644 --- a/automount.c +++ b/automount.c @@ -1,37 +1,73 @@ /*-*- 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) { +static int automount_init(Unit *u, UnitLoadState *new_state) { int r; - Automount *a = AUTOMOUNT(n); + Automount *a = AUTOMOUNT(u); assert(a); - exec_context_defaults(&a->exec_context); + exec_context_init(&a->exec_context); /* Load a .automount file */ - if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT) + if ((r = unit_load_fragment(u, new_state)) < 0) return r; - /* Load entry from /etc/fstab */ - if ((r = name_load_fstab(n)) < 0) - return r; + if (*new_state == UNIT_STUB) + *new_state = UNIT_LOADED; /* Load drop-in directory data */ - if ((r = name_load_dropin(n)) < 0) + if ((r = unit_load_dropin(unit_follow_merge(u))) < 0) return r; + if (*new_state == UNIT_LOADED) { + + if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0) + return r; + + if ((r = unit_add_exec_dependencies(u, &a->exec_context)) < 0) + return r; + + if ((r = unit_add_default_cgroup(u)) < 0) + return r; + } + return 0; } -static void automount_dump(Name *n, FILE *f, const char *prefix) { +static void automount_done(Unit *u) { + Automount *d = AUTOMOUNT(u); + + assert(d); + free(d->path); +} + +static void automount_dump(Unit *u, FILE *f, const char *prefix) { static const char* const state_table[_AUTOMOUNT_STATE_MAX] = { [AUTOMOUNT_DEAD] = "dead", @@ -52,7 +88,7 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) { }; AutomountExecCommand c; - Automount *s = AUTOMOUNT(n); + Automount *s = AUTOMOUNT(u); assert(s); @@ -67,45 +103,34 @@ static void automount_dump(Name *n, FILE *f, const char *prefix) { for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) { ExecCommand *i; - LIST_FOREACH(i, s->exec_command[c]) + LIST_FOREACH(command, i, s->exec_command[c]) fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path); } } -static NameActiveState automount_active_state(Name *n) { - - 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, +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(n)->state]; -} - -static void automount_free_hook(Name *n) { - Automount *d = AUTOMOUNT(n); - - assert(d); - free(d->path); + return table[AUTOMOUNT(u)->state]; } -const NameVTable automount_vtable = { +const UnitVTable automount_vtable = { .suffix = ".mount", - .load = automount_load, - .dump = automount_dump, - - .start = NULL, - .stop = NULL, - .reload = NULL, + .init = automount_init, + .done = automount_done, - .active_state = automount_active_state, + .dump = automount_dump, - .free_hook = automount_free_hook + .active_state = automount_active_state };