]> git.ipfire.org Git - thirdparty/systemd.git/blame - automount.c
first attempt in implementinging execution logic
[thirdparty/systemd.git] / automount.c
CommitLineData
5cb5a6ff
LP
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
11static int automount_load(Name *n) {
12 int r;
13 Automount *a = AUTOMOUNT(n);
14
15 assert(a);
16
17 exec_context_defaults(&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
34static void automount_dump(Name *n, FILE *f, const char *prefix) {
35
36 static const char* const state_table[_AUTOMOUNT_STATE_MAX] = {
37 [AUTOMOUNT_DEAD] = "dead",
38 [AUTOMOUNT_START_PRE] = "start-pre",
39 [AUTOMOUNT_START_POST] = "start-post",
40 [AUTOMOUNT_WAITING] = "waiting",
41 [AUTOMOUNT_RUNNING] = "running",
42 [AUTOMOUNT_STOP_PRE] = "stop-pre",
43 [AUTOMOUNT_STOP_POST] = "stop-post",
44 [AUTOMOUNT_MAINTAINANCE] = "maintainance"
45 };
46
47 static const char* const command_table[_AUTOMOUNT_EXEC_MAX] = {
48 [AUTOMOUNT_EXEC_START_PRE] = "StartPre",
49 [AUTOMOUNT_EXEC_START_POST] = "StartPost",
50 [AUTOMOUNT_EXEC_STOP_PRE] = "StopPre",
51 [AUTOMOUNT_EXEC_STOP_POST] = "StopPost"
52 };
53
54 AutomountExecCommand c;
55 Automount *s = AUTOMOUNT(n);
56
57 assert(s);
58
59 fprintf(f,
60 "%sAutomount State: %s\n"
61 "%sPath: %s\n",
62 prefix, state_table[s->state],
63 prefix, s->path);
64
65 exec_context_dump(&s->exec_context, f, prefix);
66
67 for (c = 0; c < _AUTOMOUNT_EXEC_MAX; c++) {
68 ExecCommand *i;
69
70 LIST_FOREACH(i, s->exec_command[c])
71 fprintf(f, "%s%s: %s\n", prefix, command_table[c], i->path);
72 }
73}
74
75static NameActiveState automount_active_state(Name *n) {
76
77 static const NameActiveState table[_AUTOMOUNT_STATE_MAX] = {
78 [AUTOMOUNT_DEAD] = NAME_INACTIVE,
79 [AUTOMOUNT_START_PRE] = NAME_ACTIVATING,
80 [AUTOMOUNT_START_POST] = NAME_ACTIVATING,
81 [AUTOMOUNT_WAITING] = NAME_ACTIVE,
82 [AUTOMOUNT_RUNNING] = NAME_ACTIVE,
83 [AUTOMOUNT_STOP_PRE] = NAME_DEACTIVATING,
84 [AUTOMOUNT_STOP_POST] = NAME_DEACTIVATING,
85 [AUTOMOUNT_MAINTAINANCE] = NAME_INACTIVE,
86 };
87
88 return table[AUTOMOUNT(n)->state];
89}
90
91static void automount_free_hook(Name *n) {
92 Automount *d = AUTOMOUNT(n);
93
94 assert(d);
95 free(d->path);
96}
97
98const NameVTable automount_vtable = {
99 .suffix = ".mount",
100
101 .load = automount_load,
102 .dump = automount_dump,
103
104 .start = NULL,
105 .stop = NULL,
106 .reload = NULL,
107
108 .active_state = automount_active_state,
109
110 .free_hook = automount_free_hook
111};