chiark / gitweb /
s/name/unit
[elogind.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-fstab.h"
9 #include "load-dropin.h"
10
11 static int automount_init(Unit *u) {
12         int r;
13         Automount *a = AUTOMOUNT(u);
14
15         assert(a);
16
17         exec_context_init(&a->exec_context);
18
19         /* Load a .automount file */
20         if ((r = unit_load_fragment(u)) < 0 && errno != -ENOENT)
21                 return r;
22
23         /* Load entry from /etc/fstab */
24         if ((r = unit_load_fstab(u)) < 0)
25                 return r;
26
27         /* Load drop-in directory data */
28         if ((r = unit_load_dropin(u)) < 0)
29                 return r;
30
31         return 0;
32 }
33
34 static void automount_done(Unit *u) {
35         Automount *d = AUTOMOUNT(u);
36
37         assert(d);
38         free(d->path);
39 }
40
41 static void automount_dump(Unit *u, FILE *f, const char *prefix) {
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;
62         Automount *s = AUTOMOUNT(u);
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
77                 LIST_FOREACH(command, i, s->exec_command[c])
78                         fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
79         }
80 }
81
82 static 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,
93         };
94
95         return table[AUTOMOUNT(u)->state];
96 }
97
98 const UnitVTable automount_vtable = {
99         .suffix = ".mount",
100
101         .init = automount_init,
102         .done = automount_done,
103
104         .dump = automount_dump,
105
106         .active_state = automount_active_state
107 };