From fee2f5ca3fc64c343806323548360dbca38cbcea Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 10 May 2025 16:11:37 +0900 Subject: [PATCH] core/mount,swap: reload unit when manually mounted/started and we previously failed to load Otherwise, neither unit_patch_contexts() nor unit_add_exec_dependencies() is called for the unit. --- src/core/mount.c | 6 ++++-- src/core/swap.c | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/mount.c b/src/core/mount.c index c496375a21..2541a4888c 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -1855,9 +1855,11 @@ static int mount_setup_existing_unit( if (UNIT_IS_LOAD_ERROR(u->load_state)) { /* The unit was previously not found or otherwise not loaded. Now that the unit shows up in - * /proc/self/mountinfo we should reconsider it this, hence set it to UNIT_LOADED. */ - u->load_state = UNIT_LOADED; + * /proc/self/mountinfo we should reconsider that. Hence, let's reset the load state and load + * error, and add the unit to load queue. */ + u->load_state = UNIT_STUB; u->load_error = 0; + unit_add_to_load_queue(u); flags |= MOUNT_PROC_JUST_CHANGED; } diff --git a/src/core/swap.c b/src/core/swap.c index 6d505c2acf..668e1bcf6c 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -406,8 +406,6 @@ static int swap_setup_unit( s->what = strdup(what); if (!s->what) return log_oom(); - - unit_add_to_load_queue(u); } SwapParameters *p = &s->parameters_proc_swaps; @@ -418,13 +416,15 @@ static int swap_setup_unit( return log_oom(); } - /* The unit is definitely around now, mark it as loaded if it was previously referenced but - * could not be loaded. After all we can load it now, from the data in /proc/swaps. */ + /* The unit is definitely around now. When we previously fail to load the unit, let's reload the unit + * by resetting the load state and load error, and adding the unit to the load queue. */ if (UNIT_IS_LOAD_ERROR(u->load_state)) { - u->load_state = UNIT_LOADED; + u->load_state = UNIT_STUB; u->load_error = 0; } + unit_add_to_load_queue(u); + if (set_flags) { s->is_active = true; s->just_activated = !s->from_proc_swaps;