From 629b2a6f7be7b5b7ec2c35aceeeb82cedc08bef3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 13 Apr 2021 20:50:21 +0200 Subject: [PATCH] core: add a reverse dep for OnFailure= Let's add an implicit reverse dep OnFailureOf=. This is exposed via the bus to make things more debuggable: you can now ask systemd for which units a specific unit is the failure handler. OnFailure= was the only dependency type that had no inverse, this fixes that. Now that deps are a bit cheaper, it should be OK to add deps that only serve debug purposes. --- man/org.freedesktop.systemd1.xml | 6 ++++++ src/basic/unit-def.c | 1 + src/basic/unit-def.h | 1 + src/core/dbus-unit.c | 1 + src/core/unit-dependency-atom.c | 1 + src/core/unit.c | 3 ++- 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml index de724126405..36bd7173d4c 100644 --- a/man/org.freedesktop.systemd1.xml +++ b/man/org.freedesktop.systemd1.xml @@ -1630,6 +1630,8 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly as OnFailure = ['...', ...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") + readonly as OnFailureOf = ['...', ...]; + @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly as Triggers = ['...', ...]; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly as TriggeredBy = ['...', ...]; @@ -1773,6 +1775,8 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { + + @@ -1905,6 +1909,8 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { + + diff --git a/src/basic/unit-def.c b/src/basic/unit-def.c index 56516203178..fd7615de881 100644 --- a/src/basic/unit-def.c +++ b/src/basic/unit-def.c @@ -275,6 +275,7 @@ static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = { [UNIT_BEFORE] = "Before", [UNIT_AFTER] = "After", [UNIT_ON_FAILURE] = "OnFailure", + [UNIT_ON_FAILURE_OF] = "OnFailureOf", [UNIT_TRIGGERS] = "Triggers", [UNIT_TRIGGERED_BY] = "TriggeredBy", [UNIT_PROPAGATES_RELOAD_TO] = "PropagatesReloadTo", diff --git a/src/basic/unit-def.h b/src/basic/unit-def.h index 7d76576de10..ec40bab01f0 100644 --- a/src/basic/unit-def.h +++ b/src/basic/unit-def.h @@ -229,6 +229,7 @@ typedef enum UnitDependency { /* On Failure */ UNIT_ON_FAILURE, + UNIT_ON_FAILURE_OF, /* Triggers (i.e. a socket triggers a service) */ UNIT_TRIGGERS, diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index a1278dd6e98..6ca16262ab6 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -865,6 +865,7 @@ const sd_bus_vtable bus_unit_vtable[] = { SD_BUS_PROPERTY("Before", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("After", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("OnFailure", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("OnFailureOf", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Triggers", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("TriggeredBy", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("PropagatesReloadTo", "as", property_get_dependencies, 0, SD_BUS_VTABLE_PROPERTY_CONST), diff --git a/src/core/unit-dependency-atom.c b/src/core/unit-dependency-atom.c index cfd5acd33b4..c4fbfee015c 100644 --- a/src/core/unit-dependency-atom.c +++ b/src/core/unit-dependency-atom.c @@ -85,6 +85,7 @@ static const UnitDependencyAtom atom_map[_UNIT_DEPENDENCY_MAX] = { * things discoverable/debuggable as they are the inverse dependencies to some of the above. As they * have no effect of their own, they all map to no atoms at all, i.e. the value 0. */ [UNIT_RELOAD_PROPAGATED_FROM] = 0, + [UNIT_ON_FAILURE_OF] = 0, }; UnitDependencyAtom unit_dependency_to_atom(UnitDependency d) { diff --git a/src/core/unit.c b/src/core/unit.c index c94f4e75236..708c725b498 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2871,7 +2871,8 @@ int unit_add_dependency( [UNIT_CONFLICTED_BY] = UNIT_CONFLICTS, [UNIT_BEFORE] = UNIT_AFTER, [UNIT_AFTER] = UNIT_BEFORE, - [UNIT_ON_FAILURE] = _UNIT_DEPENDENCY_INVALID, + [UNIT_ON_FAILURE] = UNIT_ON_FAILURE_OF, + [UNIT_ON_FAILURE_OF] = UNIT_ON_FAILURE, [UNIT_REFERENCES] = UNIT_REFERENCED_BY, [UNIT_REFERENCED_BY] = UNIT_REFERENCES, [UNIT_TRIGGERS] = UNIT_TRIGGERED_BY,