chiark / gitweb /
b64bacbf4a398339eea1946c5c9a2623e97f74bc
[elogind.git] / automount.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #include <errno.h>
4
5 #include "name.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(Name *n) {
12         int r;
13         Automount *a = AUTOMOUNT(n);
14
15         assert(a);
16
17         exec_context_init(&a->exec_context);
18
19         /* Load a .automount file */
20         if ((r = name_load_fragment(n)) < 0 && errno != -ENOENT)
21                 return r;
22
23         /* Load entry from /etc/fstab */
24         if ((r = name_load_fstab(n)) < 0)
25                 return r;
26
27         /* Load drop-in directory data */
28         if ((r = name_load_dropin(n)) < 0)
29                 return r;
30
31         return 0;
32 }
33
34 static void automount_done(Name *n) {
35         Automount *d = AUTOMOUNT(n);
36
37         assert(d);
38         free(d->path);
39 }
40
41 static void automount_dump(Name *n, 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(n);
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 NameActiveState automount_active_state(Name *n) {
83
84         static const NameActiveState table[_AUTOMOUNT_STATE_MAX] = {
85                 [AUTOMOUNT_DEAD] = NAME_INACTIVE,
86                 [AUTOMOUNT_START_PRE] = NAME_ACTIVATING,
87                 [AUTOMOUNT_START_POST] = NAME_ACTIVATING,
88                 [AUTOMOUNT_WAITING] = NAME_ACTIVE,
89                 [AUTOMOUNT_RUNNING] = NAME_ACTIVE,
90                 [AUTOMOUNT_STOP_PRE] = NAME_DEACTIVATING,
91                 [AUTOMOUNT_STOP_POST] = NAME_DEACTIVATING,
92                 [AUTOMOUNT_MAINTAINANCE] = NAME_INACTIVE,
93         };
94
95         return table[AUTOMOUNT(n)->state];
96 }
97
98 const NameVTable 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 };