mirror of
https://github.com/systemd/systemd.git
synced 2025-01-03 05:18:09 +03:00
core/service: preserve RuntimeDirectory= even if oneshot service exits
Follow-up for c26948c6da
We only want to get rid of cred mount here, and RuntimeDirectory=
is documented to be retained for SERVICE_EXITED state.
Fixes #35427
This commit is contained in:
parent
d5df77b474
commit
703b1b7f24
@ -910,7 +910,7 @@ static void mount_enter_dead(Mount *m, MountResult f, bool flush_result) {
|
||||
|
||||
m->exec_runtime = exec_runtime_destroy(m->exec_runtime);
|
||||
|
||||
unit_destroy_runtime_data(UNIT(m), &m->exec_context);
|
||||
unit_destroy_runtime_data(UNIT(m), &m->exec_context, /* destroy_runtime_dir = */ true);
|
||||
|
||||
unit_unref_uid_gid(UNIT(m), true);
|
||||
|
||||
|
@ -1341,7 +1341,7 @@ static void service_set_state(Service *s, ServiceState state) {
|
||||
}
|
||||
|
||||
if (start_only)
|
||||
unit_destroy_runtime_data(u, &s->exec_context);
|
||||
unit_destroy_runtime_data(u, &s->exec_context, /* destroy_runtime_dir = */ false);
|
||||
}
|
||||
|
||||
if (old_state != state)
|
||||
@ -2163,7 +2163,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
|
||||
s->exec_runtime = exec_runtime_destroy(s->exec_runtime);
|
||||
|
||||
/* Also, remove the runtime directory */
|
||||
unit_destroy_runtime_data(UNIT(s), &s->exec_context);
|
||||
unit_destroy_runtime_data(UNIT(s), &s->exec_context, /* destroy_runtime_dir = */ true);
|
||||
|
||||
/* Also get rid of the fd store, if that's configured. */
|
||||
if (s->fd_store_preserve_mode == EXEC_PRESERVE_NO)
|
||||
|
@ -2070,7 +2070,7 @@ static void socket_enter_dead(Socket *s, SocketResult f) {
|
||||
|
||||
s->exec_runtime = exec_runtime_destroy(s->exec_runtime);
|
||||
|
||||
unit_destroy_runtime_data(UNIT(s), &s->exec_context);
|
||||
unit_destroy_runtime_data(UNIT(s), &s->exec_context, /* destroy_runtime_dir = */ true);
|
||||
|
||||
unit_unref_uid_gid(UNIT(s), true);
|
||||
}
|
||||
|
@ -676,7 +676,7 @@ static void swap_enter_dead(Swap *s, SwapResult f) {
|
||||
|
||||
s->exec_runtime = exec_runtime_destroy(s->exec_runtime);
|
||||
|
||||
unit_destroy_runtime_data(UNIT(s), &s->exec_context);
|
||||
unit_destroy_runtime_data(UNIT(s), &s->exec_context, /* destroy_runtime_dir = */ true);
|
||||
|
||||
unit_unref_uid_gid(UNIT(s), true);
|
||||
}
|
||||
|
@ -6148,13 +6148,13 @@ int unit_test_trigger_loaded(Unit *u) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unit_destroy_runtime_data(Unit *u, const ExecContext *context) {
|
||||
void unit_destroy_runtime_data(Unit *u, const ExecContext *context, bool destroy_runtime_dir) {
|
||||
assert(u);
|
||||
assert(u->manager);
|
||||
assert(context);
|
||||
|
||||
/* EXEC_PRESERVE_RESTART is handled via unit_release_resources()! */
|
||||
if (context->runtime_directory_preserve_mode == EXEC_PRESERVE_NO)
|
||||
if (destroy_runtime_dir && context->runtime_directory_preserve_mode == EXEC_PRESERVE_NO)
|
||||
exec_context_destroy_runtime_directory(context, u->manager->prefix[EXEC_DIRECTORY_RUNTIME]);
|
||||
|
||||
exec_context_destroy_credentials(context, u->manager->prefix[EXEC_DIRECTORY_RUNTIME], u->id);
|
||||
|
@ -1036,7 +1036,7 @@ int unit_failure_action_exit_status(Unit *u);
|
||||
|
||||
int unit_test_trigger_loaded(Unit *u);
|
||||
|
||||
void unit_destroy_runtime_data(Unit *u, const ExecContext *context);
|
||||
void unit_destroy_runtime_data(Unit *u, const ExecContext *context, bool destroy_runtime_dir);
|
||||
int unit_clean(Unit *u, ExecCleanMask mask);
|
||||
int unit_can_clean(Unit *u, ExecCleanMask *ret_mask);
|
||||
|
||||
|
@ -5,8 +5,6 @@
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
# Test RuntimeDirectoryPreserve=yes
|
||||
|
||||
at_exit() {
|
||||
set +e
|
||||
|
||||
@ -15,6 +13,21 @@ at_exit() {
|
||||
|
||||
trap at_exit EXIT
|
||||
|
||||
# RuntimeDirectory= should be preserved for oneshot units if RemainAfterExit=yes
|
||||
|
||||
systemd-run --service-type=oneshot --remain-after-exit \
|
||||
-u TEST-23-remain-after-exit.service \
|
||||
-p RuntimeDirectory=TEST-23-remain-after-exit \
|
||||
true
|
||||
|
||||
[[ -d /run/TEST-23-remain-after-exit ]]
|
||||
|
||||
systemctl stop TEST-23-remain-after-exit.service
|
||||
|
||||
[[ ! -e /run/TEST-23-remain-after-exit ]]
|
||||
|
||||
# Test RuntimeDirectoryPreserve=yes
|
||||
|
||||
systemd-mount -p RuntimeDirectory=hoge -p RuntimeDirectoryPreserve=yes -t tmpfs tmpfs /tmp/aaa
|
||||
|
||||
touch /run/hoge/foo
|
Loading…
Reference in New Issue
Block a user