From: Lennart Poettering Date: Wed, 13 May 2026 13:19:54 +0000 (+0200) Subject: core: when figuring out whether to create orphanage units, consult vtable instead... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8b73a3baeadf94c86a17f8bf62f113195769d09;p=thirdparty%2Fsystemd.git core: when figuring out whether to create orphanage units, consult vtable instead of allowlist As per https://github.com/systemd/systemd/pull/41986#pullrequestreview-4281939586 This also corrects the list of unit types a bit: 1. this removes the mount/automount unit type from the list, since for these types we do not allow aliases/renaming anyway. 2. this adds socket + swap units to the list, since they can change name, and for both of them we actually do fork off processes hence track resources. Follow-up for: #41986 --- diff --git a/src/core/manager-serialize.c b/src/core/manager-serialize.c index 9a64be40397..d3549d81294 100644 --- a/src/core/manager-serialize.c +++ b/src/core/manager-serialize.c @@ -270,8 +270,8 @@ static int manager_synthesize_orphaned_unit( "Cannot synthesize unit for '%s' (overridden by alias to '%s'): invalid unit type. Skipping stale state.", original_name, canonical_name); - /* Only transition units that track external resources, forget internal ones (eg: timers) */ - if (!IN_SET(t, UNIT_SERVICE, UNIT_SCOPE, UNIT_MOUNT, UNIT_AUTOMOUNT)) + /* Only transition units that track external resources and can be renamed/know aliases, forget internal ones (eg: timers) */ + if (!unit_vtable[t]->track_orphaned) return log_warning_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Cannot synthesize unit for '%s' (overridden by alias to '%s'): unsupported unit type. Skipping stale state.", original_name, canonical_name); diff --git a/src/core/mount.c b/src/core/mount.c index c57f6e8a667..408274c3864 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -2509,6 +2509,8 @@ const UnitVTable mount_vtable = { .can_transient = true, .can_fail = true, .exclude_from_switch_root_serialization = true, + .notify_plymouth = true, + .track_orphaned = true, .init = mount_init, .load = mount_load, @@ -2576,6 +2578,4 @@ const UnitVTable mount_vtable = { }, .test_startable = mount_test_startable, - - .notify_plymouth = true, }; diff --git a/src/core/scope.c b/src/core/scope.c index 21520d9d194..167d3a37bd9 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -744,6 +744,7 @@ const UnitVTable scope_vtable = { .can_fail = true, .once_only = true, .can_set_managed_oom = true, + .track_orphaned = true, .init = scope_init, .load = scope_load, diff --git a/src/core/service.c b/src/core/service.c index 4e1d1d38d03..445812f9522 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -6149,6 +6149,8 @@ const UnitVTable service_vtable = { .can_delegate = true, .can_fail = true, .can_set_managed_oom = true, + .notify_plymouth = true, + .track_orphaned = true, .init = service_init, .done = service_done, @@ -6213,8 +6215,6 @@ const UnitVTable service_vtable = { .test_startable = service_test_startable, - .notify_plymouth = true, - .audit_start_message_type = AUDIT_SERVICE_START, .audit_stop_message_type = AUDIT_SERVICE_STOP, }; diff --git a/src/core/socket.c b/src/core/socket.c index fbf0dfd9332..3c4742fba11 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -3726,6 +3726,7 @@ const UnitVTable socket_vtable = { .can_transient = true, .can_trigger = true, .can_fail = true, + .track_orphaned = true, .init = socket_init, .done = socket_done, diff --git a/src/core/swap.c b/src/core/swap.c index cedabc430dc..88e992bd750 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -1616,6 +1616,7 @@ const UnitVTable swap_vtable = { .private_section = "Swap", .can_fail = true, + .track_orphaned = true, .init = swap_init, .load = swap_load, diff --git a/src/core/unit.h b/src/core/unit.h index d79bb7a98a5..d20e46ab579 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -771,6 +771,10 @@ typedef struct UnitVTable { /* If true, we'll notify a surrounding VMM/container manager about this unit becoming available */ bool notify_supervisor; + /* If true, we'll synthesize an 'orphaned' unit if a unit becomes an alias of another unit during a + * reload cycle, but still has resources assigned to it */ + bool track_orphaned; + /* The audit events to generate on start + stop (or 0 if none shall be generated) */ int audit_start_message_type; int audit_stop_message_type;