*/
int unit_start(Unit *u) {
UnitActiveState state;
+ Unit *following;
assert(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
unit_add_to_dbus_queue(u);
unit_status_printf(u, "Starting %s...\n", unit_description(u));
-
return UNIT_VTABLE(u)->start(u);
}
*/
int unit_stop(Unit *u) {
UnitActiveState state;
+ Unit *following;
assert(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);
}
*/
int unit_reload(Unit *u) {
UnitActiveState state;
+ Unit *following;
assert(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);
}
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;
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",