]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: when figuring out whether to create orphanage units, consult vtable instead...
authorLennart Poettering <lennart@amutable.com>
Wed, 13 May 2026 13:19:54 +0000 (15:19 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 13 May 2026 21:44:52 +0000 (22:44 +0100)
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

src/core/manager-serialize.c
src/core/mount.c
src/core/scope.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/unit.h

index 9a64be40397dec81811ff01bae31c770f156780e..d3549d81294eab12928e4b4b91f67d2bd374c8ae 100644 (file)
@@ -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);
index c57f6e8a667cfcd65e509a290fa3adf1363939c5..408274c3864becb181cdbffcb800a31bb68ad6de 100644 (file)
@@ -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,
 };
index 21520d9d1943b994a3f7b01af70cbed876f29869..167d3a37bd9b504b611b86d0fa99a10abdc3d5a9 100644 (file)
@@ -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,
index 4e1d1d38d03bd9e4447c68bd688fbb7e3bd63a19..445812f9522d53098cc2378784ea8aebec7a6ec1 100644 (file)
@@ -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,
 };
index fbf0dfd9332aee7ca03ca151b2b5648f704c07b5..3c4742fba11ebc8c817bab098a0c70eeaf010eb3 100644 (file)
@@ -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,
index cedabc430dc0ccddb2c215d0c23850620198c58a..88e992bd7504088999a5b9075db0c57d91152a22 100644 (file)
@@ -1616,6 +1616,7 @@ const UnitVTable swap_vtable = {
         .private_section = "Swap",
 
         .can_fail = true,
+        .track_orphaned = true,
 
         .init = swap_init,
         .load = swap_load,
index d79bb7a98a57d12c2ab5e2a406941b4b857d2830..d20e46ab57927f548afd9ed5c60ff8c082c0fde0 100644 (file)
@@ -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;