chiark / gitweb /
implement coldpluggin
[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)
21                 return r;
22
23         /* Load drop-in directory data */
24         if ((r = unit_load_dropin(u)) < 0)
25                 return r;
26
27         return 0;
28 }
29
30 static void automount_done(Unit *u) {
31         Automount *d = AUTOMOUNT(u);
32
33         assert(d);
34         free(d->path);
35 }
36
37 static void automount_dump(Unit *u, FILE *f, const char *prefix) {
38
39         static const char* const state_table[_AUTOMOUNT_STATE_MAX] = {
40                 [AUTOMOUNT_DEAD] = "dead",
41                 [AUTOMOUNT_START_PRE] = "start-pre",
42                 [AUTOMOUNT_START_POST] = "start-post",
43                 [AUTOMOUNT_WAITING] = "waiting",
44                 [AUTOMOUNT_RUNNING] = "running",
45                 [AUTOMOUNT_STOP_PRE] = "stop-pre",
46                 [AUTOMOUNT_STOP_POST] = "stop-post",
47                 [AUTOMOUNT_MAINTAINANCE] = "maintainance"
48         };
49
50         static const char* const command_table[_AUTOMOUNT_EXEC_MAX] = {
51                 [AUTOMOUNT_EXEC_START_PRE] = "StartPre",
52                 [AUTOMOUNT_EXEC_START_POST] = "StartPost",
53                 [AUTOMOUNT_EXEC_STOP_PRE] = "StopPre",
54                 [AUTOMOUNT_EXEC_STOP_POST] = "StopPost"
55         };
56
57         AutomountExecCommand c;
58         Automount *s = AUTOMOUNT(u);
59
60         assert(s);
61
62         fprintf(f,
63                 "%sAutomount State: %s\n"
64                 "%sPath: %s\n",
65                 prefix, state_table[s->state],
66                 prefix, s->path);
67
68         exec_context_dump(&s->exec_context, f, prefix);
69
70         for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) {
71                 ExecCommand *i;
72
73                 LIST_FOREACH(command, i, s->exec_command[c])
74                         fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
75         }
76 }
77
78 static UnitActiveState automount_active_state(Unit *u) {
79
80         static const UnitActiveState table[_AUTOMOUNT_STATE_MAX] = {
81                 [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
82                 [AUTOMOUNT_START_PRE] = UNIT_ACTIVATING,
83                 [AUTOMOUNT_START_POST] = UNIT_ACTIVATING,
84                 [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
85                 [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
86                 [AUTOMOUNT_STOP_PRE] = UNIT_DEACTIVATING,
87                 [AUTOMOUNT_STOP_POST] = UNIT_DEACTIVATING,
88                 [AUTOMOUNT_MAINTAINANCE] = UNIT_INACTIVE,
89         };
90
91         return table[AUTOMOUNT(u)->state];
92 }
93
94 const UnitVTable automount_vtable = {
95         .suffix = ".mount",
96
97         .init = automount_init,
98         .done = automount_done,
99
100         .dump = automount_dump,
101
102         .active_state = automount_active_state
103 };