Michal Schmidt e43452
From ca96079f33b100e32dd2eb624a946058b6ff49f1 Mon Sep 17 00:00:00 2001
Michal Schmidt e43452
From: Lennart Poettering <lennart@poettering.net>
Michal Schmidt e43452
Date: Wed, 11 Jan 2012 02:47:14 +0100
Michal Schmidt f1996e
Subject: [PATCH] unit: implement new PropagateReloadTo=/PropagateReloadFrom=
Michal Schmidt f1996e
 operations (cherry picked from commit
Michal Schmidt e43452
 4dcc1cb4155c4a72155e36a5461ab0847d4f1bf1)
Michal Schmidt e43452
Michal Schmidt e43452
---
Michal Schmidt e43452
 man/systemd.unit.xml             |   16 ++++++++++++++++
Michal Schmidt e43452
 src/dbus-unit.h                  |    6 ++++++
Michal Schmidt e43452
 src/load-fragment-gperf.gperf.m4 |    2 ++
Michal Schmidt e43452
 src/manager.c                    |   18 +++++++++++++++++-
Michal Schmidt e43452
 src/unit.c                       |    8 ++++++--
Michal Schmidt e43452
 src/unit.h                       |    4 ++++
Michal Schmidt e43452
 6 files changed, 51 insertions(+), 3 deletions(-)
Michal Schmidt e43452
Michal Schmidt e43452
diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml
Michal Schmidt e43452
index 897f99f..30559b9 100644
Michal Schmidt e43452
--- a/man/systemd.unit.xml
Michal Schmidt e43452
+++ b/man/systemd.unit.xml
Michal Schmidt e43452
@@ -510,6 +510,22 @@
Michal Schmidt e43452
                         </varlistentry>
Michal Schmidt e43452
 
Michal Schmidt e43452
                         <varlistentry>
Michal Schmidt e43452
+                                <term><varname>PropagateReloadTo=</varname></term>
Michal Schmidt e43452
+                                <term><varname>PropagateReloadFrom=</varname></term>
Michal Schmidt e43452
+
Michal Schmidt e43452
+                                <listitem><para>Lists one or more
Michal Schmidt e43452
+                                units where reload requests on the
Michal Schmidt e43452
+                                unit will be propagated to/on the
Michal Schmidt e43452
+                                other unit will be propagated
Michal Schmidt e43452
+                                from. Issuing a reload request on a
Michal Schmidt e43452
+                                unit will automatically also enqueue a
Michal Schmidt e43452
+                                reload request on all units that the
Michal Schmidt e43452
+                                reload request shall be propagated to
Michal Schmidt e43452
+                                via these two
Michal Schmidt e43452
+                                settings.</para></listitem>
Michal Schmidt e43452
+                        </varlistentry>
Michal Schmidt e43452
+
Michal Schmidt e43452
+                        <varlistentry>
Michal Schmidt e43452
                                 <term><varname>OnFailureIsolate=</varname></term>
Michal Schmidt e43452
 
Michal Schmidt e43452
                                 <listitem><para>Takes a boolean
Michal Schmidt e43452
diff --git a/src/dbus-unit.h b/src/dbus-unit.h
Michal Schmidt e43452
index 20d5506..7a43410 100644
Michal Schmidt e43452
--- a/src/dbus-unit.h
Michal Schmidt e43452
+++ b/src/dbus-unit.h
Michal Schmidt e43452
@@ -80,6 +80,10 @@
Michal Schmidt e43452
         "  <property name=\"Before\" type=\"as\" access=\"read\"/>\n"   \
Michal Schmidt e43452
         "  <property name=\"After\" type=\"as\" access=\"read\"/>\n"    \
Michal Schmidt e43452
         "  <property name=\"OnFailure\" type=\"as\" access=\"read\"/>\n"    \
Michal Schmidt e43452
+        "  <property name=\"Triggers\" type=\"as\" access=\"read\"/>\n"    \
Michal Schmidt e43452
+        "  <property name=\"TriggeredBy\" type=\"as\" access=\"read\"/>\n"    \
Michal Schmidt e43452
+        "  <property name=\"PropagateReloadTo\" type=\"as\" access=\"read\"/>\n" \
Michal Schmidt e43452
+        "  <property name=\"PropagateReloadFrom\" type=\"as\" access=\"read\"/>\n" \
Michal Schmidt e43452
         "  <property name=\"Description\" type=\"s\" access=\"read\"/>\n" \
Michal Schmidt e43452
         "  <property name=\"LoadState\" type=\"s\" access=\"read\"/>\n" \
Michal Schmidt e43452
         "  <property name=\"ActiveState\" type=\"s\" access=\"read\"/>\n" \
Michal Schmidt e43452
@@ -143,6 +147,8 @@
Michal Schmidt e43452
         { "org.freedesktop.systemd1.Unit", "OnFailure",            bus_unit_append_dependencies,   "as",   u->meta.dependencies[UNIT_ON_FAILURE] }, \
Michal Schmidt e43452
         { "org.freedesktop.systemd1.Unit", "Triggers",             bus_unit_append_dependencies,   "as",   u->meta.dependencies[UNIT_TRIGGERS] }, \
Michal Schmidt e43452
         { "org.freedesktop.systemd1.Unit", "TriggeredBy",          bus_unit_append_dependencies,   "as",   u->meta.dependencies[UNIT_TRIGGERED_BY] }, \
Michal Schmidt e43452
+        { "org.freedesktop.systemd1.Unit", "PropagateReloadTo",    bus_unit_append_dependencies,   "as",   u->meta.dependencies[UNIT_PROPAGATE_RELOAD_TO] }, \
Michal Schmidt e43452
+        { "org.freedesktop.systemd1.Unit", "PropagateReloadFrom",  bus_unit_append_dependencies,   "as",   u->meta.dependencies[UNIT_PROPAGATE_RELOAD_FROM] }, \
Michal Schmidt e43452
         { "org.freedesktop.systemd1.Unit", "Description",          bus_unit_append_description,    "s",    u                                 }, \
Michal Schmidt e43452
         { "org.freedesktop.systemd1.Unit", "LoadState",            bus_unit_append_load_state,     "s",    &u->meta.load_state               }, \
Michal Schmidt e43452
         { "org.freedesktop.systemd1.Unit", "ActiveState",          bus_unit_append_active_state,   "s",    u                                 }, \
Michal Schmidt e43452
diff --git a/src/load-fragment-gperf.gperf.m4 b/src/load-fragment-gperf.gperf.m4
Michal Schmidt e43452
index 81e186c..11e6324 100644
Michal Schmidt e43452
--- a/src/load-fragment-gperf.gperf.m4
Michal Schmidt e43452
+++ b/src/load-fragment-gperf.gperf.m4
Michal Schmidt e43452
@@ -100,6 +100,8 @@ Unit.Conflicts,                  config_parse_unit_deps,             UNIT_CONFLI
Michal Schmidt e43452
 Unit.Before,                     config_parse_unit_deps,             UNIT_BEFORE,                   0
Michal Schmidt e43452
 Unit.After,                      config_parse_unit_deps,             UNIT_AFTER,                    0
Michal Schmidt e43452
 Unit.OnFailure,                  config_parse_unit_deps,             UNIT_ON_FAILURE,               0
Michal Schmidt e43452
+Unit.PropagateReloadTo,          config_parse_unit_deps,             UNIT_PROPAGATE_RELOAD_TO,      0
Michal Schmidt e43452
+Unit.PropagateReloadFrom,        config_parse_unit_deps,             UNIT_PROPAGATE_RELOAD_FROM,    0
Michal Schmidt e43452
 Unit.StopWhenUnneeded,           config_parse_bool,                  0,                             offsetof(Meta, stop_when_unneeded)
Michal Schmidt e43452
 Unit.RefuseManualStart,          config_parse_bool,                  0,                             offsetof(Meta, refuse_manual_start)
Michal Schmidt e43452
 Unit.RefuseManualStop,           config_parse_bool,                  0,                             offsetof(Meta, refuse_manual_stop)
Michal Schmidt e43452
diff --git a/src/manager.c b/src/manager.c
Michal Schmidt e43452
index 6acc821..98106dd 100644
Michal Schmidt e43452
--- a/src/manager.c
Michal Schmidt e43452
+++ b/src/manager.c
Michal Schmidt e43452
@@ -1609,7 +1609,9 @@ static int transaction_add_job_and_dependencies(
Michal Schmidt e43452
                                                 dbus_error_free(e);
Michal Schmidt e43452
                                 }
Michal Schmidt e43452
 
Michal Schmidt e43452
-                } else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
Michal Schmidt e43452
+                }
Michal Schmidt e43452
+
Michal Schmidt e43452
+                if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
Michal Schmidt e43452
 
Michal Schmidt e43452
                         SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_REQUIRED_BY], i)
Michal Schmidt e43452
                                 if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, override, false, false, ignore_order, e, NULL)) < 0) {
Michal Schmidt e43452
@@ -1632,6 +1634,20 @@ static int transaction_add_job_and_dependencies(
Michal Schmidt e43452
                                 }
Michal Schmidt e43452
                 }
Michal Schmidt e43452
 
Michal Schmidt e43452
+                if (type == JOB_RELOAD || type == JOB_RELOAD_OR_START) {
Michal Schmidt e43452
+
Michal Schmidt e43452
+                        SET_FOREACH(dep, ret->unit->meta.dependencies[UNIT_PROPAGATE_RELOAD_TO], i) {
Michal Schmidt e43452
+                                r = transaction_add_job_and_dependencies(m, JOB_RELOAD, dep, ret, false, override, false, false, ignore_order, e, NULL);
Michal Schmidt e43452
+
Michal Schmidt e43452
+                                if (r < 0) {
Michal Schmidt e43452
+                                        log_warning("Cannot add dependency reload job for unit %s, ignoring: %s", dep->meta.id, bus_error(e, r));
Michal Schmidt e43452
+
Michal Schmidt e43452
+                                        if (e)
Michal Schmidt e43452
+                                                dbus_error_free(e);
Michal Schmidt e43452
+                                }
Michal Schmidt e43452
+                        }
Michal Schmidt e43452
+                }
Michal Schmidt e43452
+
Michal Schmidt e43452
                 /* JOB_VERIFY_STARTED, JOB_RELOAD require no dependency handling */
Michal Schmidt e43452
         }
Michal Schmidt e43452
 
Michal Schmidt e43452
diff --git a/src/unit.c b/src/unit.c
Michal Schmidt e43452
index 7ce783e..143b0e3 100644
Michal Schmidt e43452
--- a/src/unit.c
Michal Schmidt e43452
+++ b/src/unit.c
Michal Schmidt e43452
@@ -1535,7 +1535,9 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
Michal Schmidt e43452
                 [UNIT_REFERENCES] = UNIT_REFERENCED_BY,
Michal Schmidt e43452
                 [UNIT_REFERENCED_BY] = UNIT_REFERENCES,
Michal Schmidt e43452
                 [UNIT_TRIGGERS] = UNIT_TRIGGERED_BY,
Michal Schmidt e43452
-                [UNIT_TRIGGERED_BY] = UNIT_TRIGGERS
Michal Schmidt e43452
+                [UNIT_TRIGGERED_BY] = UNIT_TRIGGERS,
Michal Schmidt e43452
+                [UNIT_PROPAGATE_RELOAD_TO] = UNIT_PROPAGATE_RELOAD_FROM,
Michal Schmidt e43452
+                [UNIT_PROPAGATE_RELOAD_FROM] = UNIT_PROPAGATE_RELOAD_TO
Michal Schmidt e43452
         };
Michal Schmidt e43452
         int r, q = 0, v = 0, w = 0;
Michal Schmidt e43452
 
Michal Schmidt e43452
@@ -2659,7 +2661,9 @@ static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
Michal Schmidt e43452
         [UNIT_REFERENCED_BY] = "ReferencedBy",
Michal Schmidt e43452
         [UNIT_ON_FAILURE] = "OnFailure",
Michal Schmidt e43452
         [UNIT_TRIGGERS] = "Triggers",
Michal Schmidt e43452
-        [UNIT_TRIGGERED_BY] = "TriggeredBy"
Michal Schmidt e43452
+        [UNIT_TRIGGERED_BY] = "TriggeredBy",
Michal Schmidt e43452
+        [UNIT_PROPAGATE_RELOAD_TO] = "PropagateReloadTo",
Michal Schmidt e43452
+        [UNIT_PROPAGATE_RELOAD_FROM] = "PropagateReloadFrom"
Michal Schmidt e43452
 };
Michal Schmidt e43452
 
Michal Schmidt e43452
 DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);
Michal Schmidt e43452
diff --git a/src/unit.h b/src/unit.h
Michal Schmidt e43452
index 4d83309..19314d6 100644
Michal Schmidt e43452
--- a/src/unit.h
Michal Schmidt e43452
+++ b/src/unit.h
Michal Schmidt e43452
@@ -124,6 +124,10 @@ enum UnitDependency {
Michal Schmidt e43452
         UNIT_TRIGGERS,
Michal Schmidt e43452
         UNIT_TRIGGERED_BY,
Michal Schmidt e43452
 
Michal Schmidt e43452
+        /* Propagate reloads */
Michal Schmidt e43452
+        UNIT_PROPAGATE_RELOAD_TO,
Michal Schmidt e43452
+        UNIT_PROPAGATE_RELOAD_FROM,
Michal Schmidt e43452
+
Michal Schmidt e43452
         /* Reference information for GC logic */
Michal Schmidt e43452
         UNIT_REFERENCES,              /* Inverse of 'references' is 'referenced_by' */
Michal Schmidt e43452
         UNIT_REFERENCED_BY,