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