chiark / gitweb /
journal: add new system-cat tool as kind of a more powerfull BSD logger
[elogind.git] / src / unit.c
index 8630c3c59d6cc2c9f247c587b5600e43e84b11dc..1fbfb1dea5fb7df643f04ed5d46b1abe1c171c77 100644 (file)
@@ -377,12 +377,15 @@ void unit_free(Unit *u) {
 
         free(u->meta.description);
         free(u->meta.fragment_path);
+        free(u->meta.instance);
 
         set_free_free(u->meta.names);
 
         condition_free_list(u->meta.conditions);
 
-        free(u->meta.instance);
+        while (u->meta.refs)
+                unit_ref_unset(u->meta.refs);
+
         free(u);
 }
 
@@ -498,6 +501,10 @@ int unit_merge(Unit *u, Unit *other) {
         /* Merge names */
         merge_names(u, other);
 
+        /* Redirect all references */
+        while (other->meta.refs)
+                unit_ref_set(other->meta.refs, u);
+
         /* Merge dependencies */
         for (d = 0; d < _UNIT_DEPENDENCY_MAX; d++)
                 merge_dependencies(u, other, d);
@@ -1331,7 +1338,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
                 }
         }
 
-        manager_recheck_syslog(u->meta.manager);
+        manager_recheck_journal(u->meta.manager);
 
         /* Maybe we finished startup and are now ready for being
          * stopped because unneeded? */
@@ -1530,7 +1537,11 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
                 [UNIT_AFTER] = UNIT_BEFORE,
                 [UNIT_ON_FAILURE] = _UNIT_DEPENDENCY_INVALID,
                 [UNIT_REFERENCES] = UNIT_REFERENCED_BY,
-                [UNIT_REFERENCED_BY] = UNIT_REFERENCES
+                [UNIT_REFERENCED_BY] = UNIT_REFERENCES,
+                [UNIT_TRIGGERS] = UNIT_TRIGGERED_BY,
+                [UNIT_TRIGGERED_BY] = UNIT_TRIGGERS,
+                [UNIT_PROPAGATE_RELOAD_TO] = UNIT_PROPAGATE_RELOAD_FROM,
+                [UNIT_PROPAGATE_RELOAD_FROM] = UNIT_PROPAGATE_RELOAD_TO
         };
         int r, q = 0, v = 0, w = 0;
 
@@ -2592,6 +2603,28 @@ UnitFileState unit_get_unit_file_state(Unit *u) {
         return u->meta.unit_file_state;
 }
 
+Unit* unit_ref_set(UnitRef *ref, Unit *u) {
+        assert(ref);
+        assert(u);
+
+        if (ref->unit)
+                unit_ref_unset(ref);
+
+        ref->unit = u;
+        LIST_PREPEND(UnitRef, refs, u->meta.refs, ref);
+        return u;
+}
+
+void unit_ref_unset(UnitRef *ref) {
+        assert(ref);
+
+        if (!ref->unit)
+                return;
+
+        LIST_REMOVE(UnitRef, refs, ref->unit->meta.refs, ref);
+        ref->unit = NULL;
+}
+
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",
@@ -2630,7 +2663,11 @@ static const char* const unit_dependency_table[_UNIT_DEPENDENCY_MAX] = {
         [UNIT_AFTER] = "After",
         [UNIT_REFERENCES] = "References",
         [UNIT_REFERENCED_BY] = "ReferencedBy",
-        [UNIT_ON_FAILURE] = "OnFailure"
+        [UNIT_ON_FAILURE] = "OnFailure",
+        [UNIT_TRIGGERS] = "Triggers",
+        [UNIT_TRIGGERED_BY] = "TriggeredBy",
+        [UNIT_PROPAGATE_RELOAD_TO] = "PropagateReloadTo",
+        [UNIT_PROPAGATE_RELOAD_FROM] = "PropagateReloadFrom"
 };
 
 DEFINE_STRING_TABLE_LOOKUP(unit_dependency, UnitDependency);