chiark / gitweb /
mount-setup: introduce mount_point_is_api() call
[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 int automount_init(Unit *u, UnitLoadState *new_state) {
30         int r;
31         Automount *a = AUTOMOUNT(u);
32
33         assert(a);
34
35         exec_context_init(&a->exec_context);
36
37         /* Load a .automount file */
38         if ((r = unit_load_fragment(u, new_state)) < 0)
39                 return r;
40
41         if (*new_state == UNIT_STUB)
42                 *new_state = UNIT_LOADED;
43
44         /* Load drop-in directory data */
45         if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
46                 return r;
47
48         if (*new_state == UNIT_LOADED) {
49
50                 if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount))) < 0)
51                         return r;
52
53                 if ((r = unit_add_exec_dependencies(u, &a->exec_context)) < 0)
54                         return r;
55
56                 if ((r = unit_add_default_cgroup(u)) < 0)
57                         return r;
58         }
59
60         return 0;
61 }
62
63 static void automount_done(Unit *u) {
64         Automount *d = AUTOMOUNT(u);
65
66         assert(d);
67         free(d->path);
68 }
69
70 static void automount_dump(Unit *u, FILE *f, const char *prefix) {
71
72         static const char* const state_table[_AUTOMOUNT_STATE_MAX] = {
73                 [AUTOMOUNT_DEAD] = "dead",
74                 [AUTOMOUNT_START_PRE] = "start-pre",
75                 [AUTOMOUNT_START_POST] = "start-post",
76                 [AUTOMOUNT_WAITING] = "waiting",
77                 [AUTOMOUNT_RUNNING] = "running",
78                 [AUTOMOUNT_STOP_PRE] = "stop-pre",
79                 [AUTOMOUNT_STOP_POST] = "stop-post",
80                 [AUTOMOUNT_MAINTAINANCE] = "maintainance"
81         };
82
83         static const char* const command_table[_AUTOMOUNT_EXEC_MAX] = {
84                 [AUTOMOUNT_EXEC_START_PRE] = "StartPre",
85                 [AUTOMOUNT_EXEC_START_POST] = "StartPost",
86                 [AUTOMOUNT_EXEC_STOP_PRE] = "StopPre",
87                 [AUTOMOUNT_EXEC_STOP_POST] = "StopPost"
88         };
89
90         AutomountExecCommand c;
91         Automount *s = AUTOMOUNT(u);
92
93         assert(s);
94
95         fprintf(f,
96                 "%sAutomount State: %s\n"
97                 "%sPath: %s\n",
98                 prefix, state_table[s->state],
99                 prefix, s->path);
100
101         exec_context_dump(&s->exec_context, f, prefix);
102
103         for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) {
104                 ExecCommand *i;
105
106                 LIST_FOREACH(command, i, s->exec_command[c])
107                         fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
108         }
109 }
110
111 static UnitActiveState automount_active_state(Unit *u) {
112
113         static const UnitActiveState table[_AUTOMOUNT_STATE_MAX] = {
114                 [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
115                 [AUTOMOUNT_START_PRE] = UNIT_ACTIVATING,
116                 [AUTOMOUNT_START_POST] = UNIT_ACTIVATING,
117                 [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
118                 [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
119                 [AUTOMOUNT_STOP_PRE] = UNIT_DEACTIVATING,
120                 [AUTOMOUNT_STOP_POST] = UNIT_DEACTIVATING,
121                 [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
122         };
123
124         return table[AUTOMOUNT(u)->state];
125 }
126
127 const UnitVTable automount_vtable = {
128         .suffix = ".mount",
129
130         .init = automount_init,
131         .done = automount_done,
132
133         .dump = automount_dump,
134
135         .active_state = automount_active_state
136 };