1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
7 #include "load-fragment.h"
8 #include "load-fstab.h"
9 #include "load-dropin.h"
11 static int automount_init(Unit
*u
) {
13 Automount
*a
= AUTOMOUNT(u
);
17 exec_context_init(&a
->exec_context
);
19 /* Load a .automount file */
20 if ((r
= unit_load_fragment(u
)) < 0 && errno
!= -ENOENT
)
23 /* Load entry from /etc/fstab */
24 if ((r
= unit_load_fstab(u
)) < 0)
27 /* Load drop-in directory data */
28 if ((r
= unit_load_dropin(u
)) < 0)
34 static void automount_done(Unit
*u
) {
35 Automount
*d
= AUTOMOUNT(u
);
41 static void automount_dump(Unit
*u
, FILE *f
, const char *prefix
) {
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"
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"
61 AutomountExecCommand c
;
62 Automount
*s
= AUTOMOUNT(u
);
67 "%sAutomount State: %s\n"
69 prefix
, state_table
[s
->state
],
72 exec_context_dump(&s
->exec_context
, f
, prefix
);
74 for (c
= 0; c
< _AUTOMOUNT_EXEC_MAX
; c
++) {
77 LIST_FOREACH(command
, i
, s
->exec_command
[c
])
78 fprintf(f
, "%s%s: %s\n", prefix
, command_table
[c
], i
->path
);
82 static UnitActiveState
automount_active_state(Unit
*u
) {
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
,
95 return table
[AUTOMOUNT(u
)->state
];
98 const UnitVTable automount_vtable
= {
101 .init
= automount_init
,
102 .done
= automount_done
,
104 .dump
= automount_dump
,
106 .active_state
= automount_active_state