]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: fix unit_merge() load state check evaluating after state overwrite
authordongshengyuan <545258830@qq.com>
Thu, 11 Jun 2026 07:14:49 +0000 (15:14 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 16 Jun 2026 14:43:37 +0000 (15:43 +0100)
The condition on line 1206 checks other->load_state != UNIT_STUB to
decide whether to call the vtable done() callback, but the state was
already overwritten to UNIT_MERGED on line 1198, making the condition
always true.

Save the original load_state before overwriting it, so that units in
UNIT_STUB state (which never went through a load attempt) correctly
skip the done() call.

Signed-off-by: dongshengyuan <dongshengyuan@uniontech.com>
Co-developed-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
src/core/unit.c

index 2205ad0e2bc63ae996622bea20dd3b5eff9c6e72..8684471d57ee1dfdd4e9939e7c955540116f62a0 100644 (file)
@@ -1195,6 +1195,8 @@ int unit_merge(Unit *u, Unit *other) {
         if (r < 0)
                 return r;
 
+        UnitLoadState saved_load_state = other->load_state;
+
         other->load_state = UNIT_MERGED;
         other->merged_into = u;
 
@@ -1203,7 +1205,7 @@ int unit_merge(Unit *u, Unit *other) {
 
         /* If there is still some data attached to the other node, we
          * don't need it anymore, and can free it. */
-        if (other->load_state != UNIT_STUB)
+        if (saved_load_state != UNIT_STUB)
                 if (UNIT_VTABLE(other)->done)
                         UNIT_VTABLE(other)->done(other);