X Tutup
Skip to content

Commit ffec78c

Browse files
committed
core: add new PropagateStopTo= dependency (and inverse)
This takes inspiration from PropagatesReloadTo=, but propagates stop jobs instead of restart jobs. This is defined based on exactly two atoms: UNIT_ATOM_PROPAGATE_STOP + UNIT_ATOM_RETROACTIVE_STOP_ON_STOP. The former ensures that when the unit the dependency is originating from is stopped based on user request, we'll propagate the stop job to the target unit, too. In addition, when the originating unit suddenly stops from external causes the stopping is propagated too. Note that this does *not* include the UNIT_ATOM_CANNOT_BE_ACTIVE_WITHOUT atom (which is used by BoundBy=), i.e. this dependency is purely about propagating "edges" and not "levels", i.e. it's about propagating specific events, instead of continious states. This is supposed to be useful for dependencies between .mount units and their backing .device units. So far we either placed a BindsTo= or Requires= dependency between them. The former gave a very clear binding of the to units together, however was problematic if users establish mounnts manually with different block device sources than our configuration defines, as we there might come to the conclusion that the backing device was absent and thus we need to umount again what the user mounted. By combining Requires= with the new StopPropagatedFrom= (i.e. the inverse PropagateStopTo=) we can get behaviour that matches BindsTo= in every single atom but one: UNIT_ATOM_CANNOT_BE_ACTIVE_WITHOUT is absent, and hence the level-triggered logic doesn't apply. Replaces: systemd#11340
1 parent 629b2a6 commit ffec78c

File tree

9 files changed

+46
-8
lines changed

9 files changed

+46
-8
lines changed

man/org.freedesktop.systemd1.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,10 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
16401640
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
16411641
readonly as ReloadPropagatedFrom = ['...', ...];
16421642
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
1643+
readonly as PropagatesStopTo = ['...', ...];
1644+
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
1645+
readonly as StopPropagatedFrom = ['...', ...];
1646+
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
16431647
readonly as JoinsNamespaceOf = ['...', ...];
16441648
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
16451649
readonly as SliceOf = ['...', ...];
@@ -1779,6 +1783,10 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
17791783

17801784
<!--property ReloadPropagatedFrom is not documented!-->
17811785

1786+
<!--property PropagatesStopTo is not documented!-->
1787+
1788+
<!--property StopPropagatedFrom is not documented!-->
1789+
17821790
<!--property JoinsNamespaceOf is not documented!-->
17831791

17841792
<!--property SliceOf is not documented!-->
@@ -1919,6 +1927,10 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice {
19191927

19201928
<variablelist class="dbus-property" generated="True" extra-ref="ReloadPropagatedFrom"/>
19211929

1930+
<variablelist class="dbus-property" generated="True" extra-ref="PropagatesStopTo"/>
1931+
1932+
<variablelist class="dbus-property" generated="True" extra-ref="StopPropagatedFrom"/>
1933+
19221934
<variablelist class="dbus-property" generated="True" extra-ref="JoinsNamespaceOf"/>
19231935

19241936
<variablelist class="dbus-property" generated="True" extra-ref="SliceOf"/>

man/systemd.unit.xml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,20 @@
787787
<term><varname>PropagatesReloadTo=</varname></term>
788788
<term><varname>ReloadPropagatedFrom=</varname></term>
789789

790-
<listitem><para>A space-separated list of one or more units
791-
where reload requests on this unit will be propagated to, or
792-
reload requests on the other unit will be propagated to this
793-
unit, respectively. Issuing a reload request on a unit will
794-
automatically also enqueue a reload request on all units that
795-
the reload request shall be propagated to via these two
796-
settings.</para></listitem>
790+
<listitem><para>A space-separated list of one or more units to which reload requests from this unit
791+
shall be propagated to, or units from which reload requests shall be propagated to this unit,
792+
respectively. Issuing a reload request on a unit will automatically also enqueue reload requests on
793+
all units that are linked to it using these two settings.</para></listitem>
794+
</varlistentry>
795+
796+
<varlistentry>
797+
<term><varname>PropagatesStopTo=</varname></term>
798+
<term><varname>StopPropagatedFrom=</varname></term>
799+
800+
<listitem><para>A space-separated list of one or more units to which stop requests from this unit
801+
shall be propagated to, or units from which stop requests shall be propagated to this unit,
802+
respectively. Issuing a stop request on a unit will automatically also enqueue stop requests on all
803+
units that are linked to it using these two settings.</para></listitem>
797804
</varlistentry>
798805

799806
<varlistentry>

src/basic/unit-def.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
280280
[UNIT_TRIGGERED_BY] = "TriggeredBy",
281281
[UNIT_PROPAGATES_RELOAD_TO] = "PropagatesReloadTo",
282282
[UNIT_RELOAD_PROPAGATED_FROM] = "ReloadPropagatedFrom",
283+
[UNIT_PROPAGATES_STOP_TO] = "PropagatesStopTo",
284+
[UNIT_STOP_PROPAGATED_FROM] = "StopPropagatedFrom",
283285
[UNIT_JOINS_NAMESPACE_OF] = "JoinsNamespaceOf",
284286
[UNIT_REFERENCES] = "References",
285287
[UNIT_REFERENCED_BY] = "ReferencedBy",

src/basic/unit-def.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ typedef enum UnitDependency {
239239
UNIT_PROPAGATES_RELOAD_TO,
240240
UNIT_RELOAD_PROPAGATED_FROM,
241241

242+
/* Propagate stops */
243+
UNIT_PROPAGATES_STOP_TO,
244+
UNIT_STOP_PROPAGATED_FROM,
245+
242246
/* Joins namespace of */
243247
UNIT_JOINS_NAMESPACE_OF,
244248

src/core/dbus-unit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ const sd_bus_vtable bus_unit_vtable[] = {
870870
SD_BUS_PROPERTY("TriggeredBy", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
871871
SD_BUS_PROPERTY("PropagatesReloadTo", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
872872
SD_BUS_PROPERTY("ReloadPropagatedFrom", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
873+
SD_BUS_PROPERTY("PropagatesStopTo", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
874+
SD_BUS_PROPERTY("StopPropagatedFrom", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
873875
SD_BUS_PROPERTY("JoinsNamespaceOf", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
874876
SD_BUS_PROPERTY("SliceOf", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST),
875877
SD_BUS_PROPERTY("RequiresMountsFor", "as", property_get_requires_mounts_for, offsetof(Unit, requires_mounts_for), SD_BUS_VTABLE_PROPERTY_CONST),
@@ -2302,6 +2304,8 @@ static int bus_unit_set_transient_property(
23022304
UNIT_ON_FAILURE,
23032305
UNIT_PROPAGATES_RELOAD_TO,
23042306
UNIT_RELOAD_PROPAGATED_FROM,
2307+
UNIT_PROPAGATES_STOP_TO,
2308+
UNIT_STOP_PROPAGATED_FROM,
23052309
UNIT_JOINS_NAMESPACE_OF))
23062310
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Dependency type %s may not be created transiently.", unit_dependency_to_string(d));
23072311

src/core/load-fragment-gperf.gperf.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ Unit.PropagatesReloadTo, config_parse_unit_deps,
269269
Unit.PropagateReloadTo, config_parse_unit_deps, UNIT_PROPAGATES_RELOAD_TO, 0
270270
Unit.ReloadPropagatedFrom, config_parse_unit_deps, UNIT_RELOAD_PROPAGATED_FROM, 0
271271
Unit.PropagateReloadFrom, config_parse_unit_deps, UNIT_RELOAD_PROPAGATED_FROM, 0
272+
Unit.PropagatesStopTo, config_parse_unit_deps, UNIT_PROPAGATES_STOP_TO, 0
273+
Unit.StopPropagatedFrom, config_parse_unit_deps, UNIT_STOP_PROPAGATED_FROM, 0
272274
Unit.PartOf, config_parse_unit_deps, UNIT_PART_OF, 0
273275
Unit.JoinsNamespaceOf, config_parse_unit_deps, UNIT_JOINS_NAMESPACE_OF, 0
274276
Unit.RequiresOverridable, config_parse_obsolete_unit_deps, UNIT_REQUIRES, 0

src/core/unit-dependency-atom.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ static const UnitDependencyAtom atom_map[_UNIT_DEPENDENCY_MAX] = {
6868
UNIT_ATOM_RETROACTIVE_STOP_ON_START |
6969
UNIT_ATOM_PROPAGATE_STOP_FAILURE,
7070

71+
[UNIT_PROPAGATES_STOP_TO] = UNIT_ATOM_RETROACTIVE_STOP_ON_STOP |
72+
UNIT_ATOM_PROPAGATE_STOP,
73+
7174
/* These are simple dependency types: they consist of a single atom only */
7275
[UNIT_BEFORE] = UNIT_ATOM_BEFORE,
7376
[UNIT_AFTER] = UNIT_ATOM_AFTER,
@@ -86,6 +89,7 @@ static const UnitDependencyAtom atom_map[_UNIT_DEPENDENCY_MAX] = {
8689
* have no effect of their own, they all map to no atoms at all, i.e. the value 0. */
8790
[UNIT_RELOAD_PROPAGATED_FROM] = 0,
8891
[UNIT_ON_FAILURE_OF] = 0,
92+
[UNIT_STOP_PROPAGATED_FROM] = 0,
8993
};
9094

9195
UnitDependencyAtom unit_dependency_to_atom(UnitDependency d) {
@@ -149,7 +153,6 @@ UnitDependency unit_dependency_from_unique_atom(UnitDependencyAtom atom) {
149153
UNIT_ATOM_PROPAGATE_START_FAILURE |
150154
UNIT_ATOM_PINS_STOP_WHEN_UNNEEDED |
151155
UNIT_ATOM_DEFAULT_TARGET_DEPENDENCIES:
152-
case UNIT_ATOM_RETROACTIVE_STOP_ON_STOP:
153156
return UNIT_BOUND_BY;
154157

155158
case UNIT_ATOM_PULL_IN_STOP |

src/core/unit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,8 @@ int unit_add_dependency(
28792879
[UNIT_TRIGGERED_BY] = UNIT_TRIGGERS,
28802880
[UNIT_PROPAGATES_RELOAD_TO] = UNIT_RELOAD_PROPAGATED_FROM,
28812881
[UNIT_RELOAD_PROPAGATED_FROM] = UNIT_PROPAGATES_RELOAD_TO,
2882+
[UNIT_PROPAGATES_STOP_TO] = UNIT_STOP_PROPAGATED_FROM,
2883+
[UNIT_STOP_PROPAGATED_FROM] = UNIT_PROPAGATES_STOP_TO,
28822884
[UNIT_JOINS_NAMESPACE_OF] = UNIT_JOINS_NAMESPACE_OF, /* symmetric! 👓 */
28832885
[UNIT_IN_SLICE] = UNIT_SLICE_OF,
28842886
[UNIT_SLICE_OF] = UNIT_IN_SLICE,

test/fuzz/fuzz-unit-file/directives.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ PartOf=
8080
PropagateReloadFrom=
8181
PropagateReloadTo=
8282
PropagatesReloadTo=
83+
PropagatesStopTo=
8384
RebootArgument=
8485
RefuseManualStart=
8586
RefuseManualStop=
@@ -97,6 +98,7 @@ StartLimitBurst=
9798
StartLimitInterval=
9899
StartLimitIntervalSec=
99100
StopWhenUnneeded=
101+
StopPropagatedFrom=
100102
SuccessAction=
101103
SuccessActionExitStatus=
102104
Wants=

0 commit comments

Comments
 (0)
X Tutup