chiark / gitweb /
service,mount,socket: explicitly unwatch control pids
[elogind.git] / automount.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2 of the License, or
11   (at your option) any later version.
12
13   systemd is distributed in the hope that it will be useful, but
14   WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <errno.h>
23
24 #include "unit.h"
25 #include "automount.h"
26 #include "load-fragment.h"
27 #include "load-dropin.h"
28
29 static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
30         [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
31         [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
32         [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
33         [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
34 };
35
36 static const char* const state_string_table[_AUTOMOUNT_STATE_MAX] = {
37         [AUTOMOUNT_DEAD] = "dead",
38         [AUTOMOUNT_WAITING] = "waiting",
39         [AUTOMOUNT_RUNNING] = "running",
40         [AUTOMOUNT_MAINTAINANCE] = "maintainance"
41 };
42
43 static void automount_init(Unit *u) {
44         Automount *a = AUTOMOUNT(u);
45
46         a->state = 0;
47         a->mount = NULL;
48 }
49
50 static int automount_load(Unit *u) {
51         int r;
52         Automount *a = AUTOMOUNT(u);
53
54         assert(u);
55         assert(u->meta.load_state == UNIT_STUB);
56
57         /* Load a .automount file */
58         if ((r = unit_load_fragment_and_dropin_optional(u)) < 0)
59                 return r;
60
61         if (u->meta.load_state == UNIT_LOADED) {
62
63                 if ((r = unit_load_related_unit(u, ".mount", (Unit**) &a->mount)) < 0)
64                         return r;
65
66                 if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
67                         return r;
68         }
69
70         return 0;
71 }
72
73 static void automount_done(Unit *u) {
74         Automount *a = AUTOMOUNT(u);
75
76         assert(a);
77
78         a->mount = NULL;
79 }
80
81 static void automount_dump(Unit *u, FILE *f, const char *prefix) {
82         Automount *s = AUTOMOUNT(u);
83
84         assert(s);
85
86         fprintf(f,
87                 "%sAutomount State: %s\n",
88                 prefix, state_string_table[s->state]);
89 }
90
91 static UnitActiveState automount_active_state(Unit *u) {
92
93         return state_translation_table[AUTOMOUNT(u)->state];
94 }
95
96 const UnitVTable automount_vtable = {
97         .suffix = ".mount",
98
99         .no_alias = true,
100
101         .init = automount_init,
102         .load = automount_load,
103         .done = automount_done,
104
105         .dump = automount_dump,
106
107         .active_state = automount_active_state
108 };