}
}
-static int mount_spawn(Mount *m, ExecCommand *c, PidRef *ret_pid) {
- _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(
- EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN);
+static ExecFlags mount_exec_flags(MountState state) {
+ ExecFlags flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN;
+
+ assert(IN_SET(state, MOUNT_MOUNTING, MOUNT_REMOUNTING, MOUNT_UNMOUNTING));
+
+ if (IN_SET(state, MOUNT_MOUNTING, MOUNT_REMOUNTING))
+ flags |= EXEC_SETUP_CREDENTIALS;
+
+ return flags;
+}
+
+static int mount_spawn(Mount *m, ExecCommand *c, ExecFlags flags, PidRef *ret_pid) {
+ _cleanup_(exec_params_shallow_clear) ExecParameters exec_params = EXEC_PARAMETERS_INIT(flags);
_cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
int r;
mount_unwatch_control_pid(m);
- r = mount_spawn(m, m->control_command, &m->control_pid);
+ r = mount_spawn(m, m->control_command, mount_exec_flags(MOUNT_UNMOUNTING), &m->control_pid);
if (r < 0) {
log_unit_warning_errno(UNIT(m), r, "Failed to spawn 'umount' task: %m");
goto fail;
mount_unwatch_control_pid(m);
- r = mount_spawn(m, m->control_command, &m->control_pid);
+ r = mount_spawn(m, m->control_command, mount_exec_flags(MOUNT_MOUNTING), &m->control_pid);
if (r < 0) {
log_unit_warning_errno(UNIT(m), r, "Failed to spawn 'mount' task: %m");
goto fail;
mount_unwatch_control_pid(m);
- r = mount_spawn(m, m->control_command, &m->control_pid);
+ r = mount_spawn(m, m->control_command, mount_exec_flags(MOUNT_REMOUNTING), &m->control_pid);
if (r < 0) {
log_unit_warning_errno(UNIT(m), r, "Failed to spawn 'remount' task: %m");
goto fail;