1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
7 #include "load-fragment.h"
8 #include "load-dropin.h"
10 static int automount_init(Unit
*u
) {
12 Automount
*a
= AUTOMOUNT(u
);
16 exec_context_init(&a
->exec_context
);
18 /* Load a .automount file */
19 if ((r
= unit_load_fragment(u
)) < 0)
22 /* Load drop-in directory data */
23 if ((r
= unit_load_dropin(u
)) < 0)
29 static void automount_done(Unit
*u
) {
30 Automount
*d
= AUTOMOUNT(u
);
36 static void automount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
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"
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"
56 AutomountExecCommand c
;
57 Automount
*s
= AUTOMOUNT(u
);
62 "%sAutomount State: %s\n"
64 prefix
, state_table
[s
->state
],
67 exec_context_dump(&s
->exec_context
, f
, prefix
);
69 for (c
= 0; c
< _AUTOMOUNT_EXEC_MAX
; c
++) {
72 LIST_FOREACH(command
, i
, s
->exec_command
[c
])
73 fprintf(f
, "%s%s: %s\n", prefix
, command_table
[c
], i
->path
);
77 static UnitActiveState
automount_active_state(Unit
*u
) {
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
,
90 return table
[AUTOMOUNT(u
)->state
];
93 const UnitVTable automount_vtable
= {
96 .init
= automount_init
,
97 .done
= automount_done
,
99 .dump
= automount_dump
,
101 .active_state
= automount_active_state