chiark / gitweb /
systemctl: before spawning pager cache number of columns
[elogind.git] / src / unit.c
index fb5583bfb2d589b3fbb451f3be777c08127d6bab..7d673e138d291340b7eb334ea620bf51eb8060c7 100644 (file)
@@ -655,13 +655,11 @@ void unit_dump(Unit *u, FILE *f, const char *prefix) {
                         "%s\tStopWhenUnneeded: %s\n"
                         "%s\tRefuseManualStart: %s\n"
                         "%s\tRefuseManualStop: %s\n"
-                        "%s\tDefaultDependencies: %s\n"
-                        "%s\tIgnoreDependencyFailure: %s\n",
+                        "%s\tDefaultDependencies: %s\n",
                         prefix, yes_no(u->meta.stop_when_unneeded),
                         prefix, yes_no(u->meta.refuse_manual_start),
                         prefix, yes_no(u->meta.refuse_manual_stop),
-                        prefix, yes_no(u->meta.default_dependencies),
-                        prefix, yes_no(u->meta.ignore_dependency_failure));
+                        prefix, yes_no(u->meta.default_dependencies));
 
                 LIST_FOREACH(by_unit, b, u->meta.cgroup_bondings)
                         fprintf(f, "%s\tControlGroup: %s:%s\n",
@@ -828,6 +826,7 @@ fail:
  */
 int unit_start(Unit *u) {
         UnitActiveState state;
+        Unit *following;
 
         assert(u);
 
@@ -842,16 +841,22 @@ int unit_start(Unit *u) {
         if (UNIT_IS_ACTIVE_OR_RELOADING(state))
                 return -EALREADY;
 
-        /* If it is stopped, but we cannot start it, then fail */
-        if (!UNIT_VTABLE(u)->start)
-                return -EBADR;
-
         /* If the conditions failed, don't do anything at all */
         if (!condition_test_list(u->meta.conditions)) {
                 log_debug("Starting of %s requested but condition failed. Ignoring.", u->meta.id);
                 return -EALREADY;
         }
 
+        /* Forward to the main object, if we aren't it. */
+        if ((following = unit_following(u))) {
+                log_debug("Redirecting start request from %s to %s.", u->meta.id, following->meta.id);
+                return unit_start(following);
+        }
+
+        /* If it is stopped, but we cannot start it, then fail */
+        if (!UNIT_VTABLE(u)->start)
+                return -EBADR;
+
         /* We don't suppress calls to ->start() here when we are
          * already starting, to allow this request to be used as a
          * "hurry up" call, for example when the unit is in some "auto
@@ -861,7 +866,6 @@ int unit_start(Unit *u) {
         unit_add_to_dbus_queue(u);
 
         unit_status_printf(u, "Starting %s...\n", unit_description(u));
-
         return UNIT_VTABLE(u)->start(u);
 }
 
@@ -885,6 +889,7 @@ bool unit_can_isolate(Unit *u) {
  */
 int unit_stop(Unit *u) {
         UnitActiveState state;
+        Unit *following;
 
         assert(u);
 
@@ -892,13 +897,17 @@ int unit_stop(Unit *u) {
         if (UNIT_IS_INACTIVE_OR_FAILED(state))
                 return -EALREADY;
 
+        if ((following = unit_following(u))) {
+                log_debug("Redirecting stop request from %s to %s.", u->meta.id, following->meta.id);
+                return unit_stop(following);
+        }
+
         if (!UNIT_VTABLE(u)->stop)
                 return -EBADR;
 
         unit_add_to_dbus_queue(u);
 
         unit_status_printf(u, "Stopping %s...\n", unit_description(u));
-
         return UNIT_VTABLE(u)->stop(u);
 }
 
@@ -909,6 +918,7 @@ int unit_stop(Unit *u) {
  */
 int unit_reload(Unit *u) {
         UnitActiveState state;
+        Unit *following;
 
         assert(u);
 
@@ -925,6 +935,11 @@ int unit_reload(Unit *u) {
         if (state != UNIT_ACTIVE)
                 return -ENOEXEC;
 
+        if ((following = unit_following(u))) {
+                log_debug("Redirecting reload request from %s to %s.", u->meta.id, following->meta.id);
+                return unit_reload(following);
+        }
+
         unit_add_to_dbus_queue(u);
         return UNIT_VTABLE(u)->reload(u);
 }
@@ -1388,9 +1403,9 @@ bool unit_job_is_applicable(Unit *u, JobType j) {
 
         case JOB_VERIFY_ACTIVE:
         case JOB_START:
+        case JOB_STOP:
                 return true;
 
-        case JOB_STOP:
         case JOB_RESTART:
         case JOB_TRY_RESTART:
                 return unit_can_start(u);
@@ -1441,15 +1456,6 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
         if (u == other)
                 return 0;
 
-        if (UNIT_VTABLE(u)->no_requires &&
-            (d == UNIT_REQUIRES ||
-             d == UNIT_REQUIRES_OVERRIDABLE ||
-             d == UNIT_REQUISITE ||
-             d == UNIT_REQUISITE_OVERRIDABLE ||
-             d == UNIT_BIND_TO)) {
-                    return -EINVAL;
-        }
-
         if ((r = set_ensure_allocated(&u->meta.dependencies[d], trivial_hash_func, trivial_compare_func)) < 0)
                 return r;
 
@@ -1676,7 +1682,6 @@ char *unit_dbus_path(Unit *u) {
 }
 
 int unit_add_cgroup(Unit *u, CGroupBonding *b) {
-        CGroupBonding *l;
         int r;
 
         assert(u);
@@ -1691,12 +1696,16 @@ int unit_add_cgroup(Unit *u, CGroupBonding *b) {
         /* Ensure this hasn't been added yet */
         assert(!b->unit);
 
-        l = hashmap_get(u->meta.manager->cgroup_bondings, b->path);
-        LIST_PREPEND(CGroupBonding, by_path, l, b);
+        if (streq(b->controller, SYSTEMD_CGROUP_CONTROLLER)) {
+                CGroupBonding *l;
 
-        if ((r = hashmap_replace(u->meta.manager->cgroup_bondings, b->path, l)) < 0) {
-                LIST_REMOVE(CGroupBonding, by_path, l, b);
-                return r;
+                l = hashmap_get(u->meta.manager->cgroup_bondings, b->path);
+                LIST_PREPEND(CGroupBonding, by_path, l, b);
+
+                if ((r = hashmap_replace(u->meta.manager->cgroup_bondings, b->path, l)) < 0) {
+                        LIST_REMOVE(CGroupBonding, by_path, l, b);
+                        return r;
+                }
         }
 
         LIST_PREPEND(CGroupBonding, by_unit, u->meta.cgroup_bondings, b);
@@ -1761,8 +1770,7 @@ int unit_add_cgroup_from_text(Unit *u, const char *name) {
 
         b->controller = controller;
         b->path = path;
-        b->only_us = false;
-        b->clean_up = false;
+        b->ours = false;
 
         if ((r = unit_add_cgroup(u, b)) < 0)
                 goto fail;
@@ -1777,25 +1785,29 @@ fail:
         return r;
 }
 
-int unit_add_default_cgroup(Unit *u) {
-        CGroupBonding *b;
+static int unit_add_one_default_cgroup(Unit *u, const char *controller) {
+        CGroupBonding *b = NULL;
         int r = -ENOMEM;
 
         assert(u);
 
-        /* Adds in the default cgroup data, if it wasn't specified yet */
+        if (!controller)
+                controller = SYSTEMD_CGROUP_CONTROLLER;
 
-        if (unit_get_default_cgroup(u))
+        if (cgroup_bonding_find_list(u->meta.cgroup_bondings, controller))
                 return 0;
 
         if (!(b = new0(CGroupBonding, 1)))
                 return -ENOMEM;
 
+        if (!(b->controller = strdup(controller)))
+                goto fail;
+
         if (!(b->path = default_cgroup_path(u)))
                 goto fail;
 
-        b->clean_up = true;
-        b->only_us = true;
+        b->ours = true;
+        b->essential = streq(controller, SYSTEMD_CGROUP_CONTROLLER);
 
         if ((r = unit_add_cgroup(u, b)) < 0)
                 goto fail;
@@ -1810,6 +1822,24 @@ fail:
         return r;
 }
 
+int unit_add_default_cgroups(Unit *u) {
+        char **c;
+        int r;
+        assert(u);
+
+        /* Adds in the default cgroups, if they weren't specified
+         * otherwise. */
+
+        if ((r = unit_add_one_default_cgroup(u, NULL)) < 0)
+                return r;
+
+        STRV_FOREACH(c, u->meta.manager->default_controllers)
+                if ((r = unit_add_one_default_cgroup(u, *c)) < 0)
+                        return r;
+
+        return 0;
+}
+
 CGroupBonding* unit_get_default_cgroup(Unit *u) {
         assert(u);
 
@@ -2304,6 +2334,18 @@ int unit_kill(Unit *u, KillWho w, KillMode m, int signo, DBusError *error) {
         return UNIT_VTABLE(u)->kill(u, w, m, signo, error);
 }
 
+
+int unit_following_set(Unit *u, Set **s) {
+        assert(u);
+        assert(s);
+
+        if (UNIT_VTABLE(u)->following_set)
+                return UNIT_VTABLE(u)->following_set(u, s);
+
+        *s = NULL;
+        return 0;
+}
+
 static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = {
         [UNIT_STUB] = "stub",
         [UNIT_LOADED] = "loaded",