]>
Commit | Line | Data |
---|---|---|
5cb5a6ff LP |
1 | /*-*- Mode: C; c-basic-offset: 8 -*-*/ |
2 | ||
a7334b09 LP |
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 | ||
5cb5a6ff LP |
22 | #include <errno.h> |
23 | ||
87f0e418 | 24 | #include "unit.h" |
5cb5a6ff LP |
25 | #include "automount.h" |
26 | #include "load-fragment.h" | |
5cb5a6ff LP |
27 | #include "load-dropin.h" |
28 | ||
87f0e418 | 29 | static int automount_init(Unit *u) { |
5cb5a6ff | 30 | int r; |
87f0e418 | 31 | Automount *a = AUTOMOUNT(u); |
5cb5a6ff LP |
32 | |
33 | assert(a); | |
34 | ||
034c6ed7 | 35 | exec_context_init(&a->exec_context); |
5cb5a6ff LP |
36 | |
37 | /* Load a .automount file */ | |
d46de8a1 | 38 | if ((r = unit_load_fragment(u)) < 0) |
5cb5a6ff LP |
39 | return r; |
40 | ||
5cb5a6ff | 41 | /* Load drop-in directory data */ |
87f0e418 | 42 | if ((r = unit_load_dropin(u)) < 0) |
5cb5a6ff LP |
43 | return r; |
44 | ||
45 | return 0; | |
46 | } | |
47 | ||
87f0e418 LP |
48 | static void automount_done(Unit *u) { |
49 | Automount *d = AUTOMOUNT(u); | |
034c6ed7 LP |
50 | |
51 | assert(d); | |
52 | free(d->path); | |
53 | } | |
54 | ||
87f0e418 | 55 | static void automount_dump(Unit *u, FILE *f, const char *prefix) { |
5cb5a6ff LP |
56 | |
57 | static const char* const state_table[_AUTOMOUNT_STATE_MAX] = { | |
58 | [AUTOMOUNT_DEAD] = "dead", | |
59 | [AUTOMOUNT_START_PRE] = "start-pre", | |
60 | [AUTOMOUNT_START_POST] = "start-post", | |
61 | [AUTOMOUNT_WAITING] = "waiting", | |
62 | [AUTOMOUNT_RUNNING] = "running", | |
63 | [AUTOMOUNT_STOP_PRE] = "stop-pre", | |
64 | [AUTOMOUNT_STOP_POST] = "stop-post", | |
65 | [AUTOMOUNT_MAINTAINANCE] = "maintainance" | |
66 | }; | |
67 | ||
68 | static const char* const command_table[_AUTOMOUNT_EXEC_MAX] = { | |
69 | [AUTOMOUNT_EXEC_START_PRE] = "StartPre", | |
70 | [AUTOMOUNT_EXEC_START_POST] = "StartPost", | |
71 | [AUTOMOUNT_EXEC_STOP_PRE] = "StopPre", | |
72 | [AUTOMOUNT_EXEC_STOP_POST] = "StopPost" | |
73 | }; | |
74 | ||
75 | AutomountExecCommand c; | |
87f0e418 | 76 | Automount *s = AUTOMOUNT(u); |
5cb5a6ff LP |
77 | |
78 | assert(s); | |
79 | ||
80 | fprintf(f, | |
81 | "%sAutomount State: %s\n" | |
82 | "%sPath: %s\n", | |
83 | prefix, state_table[s->state], | |
84 | prefix, s->path); | |
85 | ||
86 | exec_context_dump(&s->exec_context, f, prefix); | |
87 | ||
88 | for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) { | |
89 | ExecCommand *i; | |
90 | ||
034c6ed7 | 91 | LIST_FOREACH(command, i, s->exec_command[c]) |
5cb5a6ff LP |
92 | fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path); |
93 | } | |
94 | } | |
95 | ||
87f0e418 LP |
96 | static UnitActiveState automount_active_state(Unit *u) { |
97 | ||
98 | static const UnitActiveState table[_AUTOMOUNT_STATE_MAX] = { | |
99 | [AUTOMOUNT_DEAD] = UNIT_INACTIVE, | |
100 | [AUTOMOUNT_START_PRE] = UNIT_ACTIVATING, | |
101 | [AUTOMOUNT_START_POST] = UNIT_ACTIVATING, | |
102 | [AUTOMOUNT_WAITING] = UNIT_ACTIVE, | |
103 | [AUTOMOUNT_RUNNING] = UNIT_ACTIVE, | |
104 | [AUTOMOUNT_STOP_PRE] = UNIT_DEACTIVATING, | |
105 | [AUTOMOUNT_STOP_POST] = UNIT_DEACTIVATING, | |
106 | [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE, | |
5cb5a6ff LP |
107 | }; |
108 | ||
87f0e418 | 109 | return table[AUTOMOUNT(u)->state]; |
5cb5a6ff LP |
110 | } |
111 | ||
87f0e418 | 112 | const UnitVTable automount_vtable = { |
5cb5a6ff LP |
113 | .suffix = ".mount", |
114 | ||
034c6ed7 LP |
115 | .init = automount_init, |
116 | .done = automount_done, | |
5cb5a6ff | 117 | |
034c6ed7 | 118 | .dump = automount_dump, |
5cb5a6ff | 119 | |
034c6ed7 | 120 | .active_state = automount_active_state |
5cb5a6ff | 121 | }; |