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