diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-19 21:12:59 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-20 20:52:36 +0100 |
commit | 718db96199eb307751264e4163555662c9a389fa (patch) | |
tree | 9ec8467596ba1acba76bb6273c7797baf68c1a00 /src/core/scope.c | |
parent | 3febea3a0b0a968ea281e7959c1654cbaf95c9bf (diff) |
core: convert PID 1 to libsystemd-bus
This patch converts PID 1 to libsystemd-bus and thus drops the
dependency on libdbus. The only remaining code using libdbus is a test
case that validates our bus marshalling against libdbus' marshalling,
and this dependency can be turned off.
This patch also adds a couple of things to libsystem-bus, that are
necessary to make the port work:
- Synthesizing of "Disconnected" messages when bus connections are
severed.
- Support for attaching multiple vtables for the same interface on the
same path.
This patch also fixes the SetDefaultTarget() and GetDefaultTarget() bus
calls which used an inappropriate signature.
As a side effect we will now generate PropertiesChanged messages which
carry property contents, rather than just invalidation information.
Diffstat (limited to 'src/core/scope.c')
-rw-r--r-- | src/core/scope.c | 70 |
1 files changed, 44 insertions, 26 deletions
diff --git a/src/core/scope.c b/src/core/scope.c index 41da3b9378..a3c94794b1 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -40,6 +40,8 @@ static const UnitActiveState state_translation_table[_SCOPE_STATE_MAX] = { [SCOPE_FAILED] = UNIT_FAILED }; +static int scope_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata); + static void scope_init(Unit *u) { Scope *s = SCOPE(u); @@ -48,8 +50,6 @@ static void scope_init(Unit *u) { s->timeout_stop_usec = u->manager->default_timeout_stop_usec; - watch_init(&s->timer_watch); - cgroup_context_init(&s->cgroup_context); kill_context_init(&s->kill_context); @@ -67,7 +67,28 @@ static void scope_done(Unit *u) { set_free(s->pids); s->pids = NULL; - unit_unwatch_timer(u, &s->timer_watch); + s->timer_event_source = sd_event_source_unref(s->timer_event_source); +} + +static int scope_arm_timer(Scope *s) { + int r; + + assert(s); + + if (s->timeout_stop_usec <= 0) { + s->timer_event_source = sd_event_source_unref(s->timer_event_source); + return 0; + } + + if (s->timer_event_source) { + r = sd_event_source_set_time(s->timer_event_source, now(CLOCK_MONOTONIC) + s->timeout_stop_usec); + if (r < 0) + return r; + + return sd_event_source_set_enabled(s->timer_event_source, SD_EVENT_ONESHOT); + } + + return sd_event_add_monotonic(UNIT(s)->manager->event, now(CLOCK_MONOTONIC) + s->timeout_stop_usec, 0, scope_dispatch_timer, s, &s->timer_event_source); } static void scope_set_state(Scope *s, ScopeState state) { @@ -79,7 +100,7 @@ static void scope_set_state(Scope *s, ScopeState state) { if (state != SCOPE_STOP_SIGTERM && state != SCOPE_STOP_SIGKILL) - unit_unwatch_timer(UNIT(s), &s->timer_watch); + s->timer_event_source = sd_event_source_unref(s->timer_event_source); if (state != old_state) log_debug("%s changed %s -> %s", @@ -158,11 +179,9 @@ static int scope_coldplug(Unit *u) { if (s->deserialized_state != s->state) { - if ((s->deserialized_state == SCOPE_STOP_SIGKILL || s->deserialized_state == SCOPE_STOP_SIGTERM) - && s->timeout_stop_usec > 0) { - r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->timeout_stop_usec, &s->timer_watch); + if (s->deserialized_state == SCOPE_STOP_SIGKILL || s->deserialized_state == SCOPE_STOP_SIGTERM) { + r = scope_arm_timer(s); if (r < 0) - return r; } @@ -214,11 +233,9 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) { goto fail; if (r > 0) { - if (s->timeout_stop_usec > 0) { - r = unit_watch_timer(UNIT(s), CLOCK_MONOTONIC, true, s->timeout_stop_usec, &s->timer_watch); - if (r < 0) - goto fail; - } + r = scope_arm_timer(s); + if (r < 0) + goto fail; scope_set_state(s, state); } else @@ -297,7 +314,7 @@ static void scope_reset_failed(Unit *u) { s->result = SCOPE_SUCCESS; } -static int scope_kill(Unit *u, KillWho who, int signo, DBusError *error) { +static int scope_kill(Unit *u, KillWho who, int signo, sd_bus_error *error) { return unit_kill_common(u, who, signo, -1, -1, error); } @@ -353,34 +370,35 @@ static bool scope_check_gc(Unit *u) { return false; } -static void scope_timer_event(Unit *u, uint64_t elapsed, Watch*w) { - Scope *s = SCOPE(u); +static int scope_dispatch_timer(sd_event_source *source, usec_t usec, void *userdata) { + Scope *s = SCOPE(userdata); assert(s); - assert(elapsed == 1); - assert(w == &s->timer_watch); + assert(s->timer_event_source == source); switch (s->state) { case SCOPE_STOP_SIGTERM: if (s->kill_context.send_sigkill) { - log_warning_unit(u->id, "%s stopping timed out. Killing.", u->id); + log_warning_unit(UNIT(s)->id, "%s stopping timed out. Killing.", UNIT(s)->id); scope_enter_signal(s, SCOPE_STOP_SIGKILL, SCOPE_FAILURE_TIMEOUT); } else { - log_warning_unit(u->id, "%s stopping timed out. Skipping SIGKILL.", u->id); + log_warning_unit(UNIT(s)->id, "%s stopping timed out. Skipping SIGKILL.", UNIT(s)->id); scope_enter_dead(s, SCOPE_FAILURE_TIMEOUT); } break; case SCOPE_STOP_SIGKILL: - log_warning_unit(u->id, "%s still around after SIGKILL. Ignoring.", u->id); + log_warning_unit(UNIT(s)->id, "%s still around after SIGKILL. Ignoring.", UNIT(s)->id); scope_enter_dead(s, SCOPE_FAILURE_TIMEOUT); break; default: assert_not_reached("Timeout at wrong time."); } + + return 0; } static void scope_notify_cgroup_empty_event(Unit *u) { @@ -435,13 +453,14 @@ DEFINE_STRING_TABLE_LOOKUP(scope_result, ScopeResult); const UnitVTable scope_vtable = { .object_size = sizeof(Scope), + .cgroup_context_offset = offsetof(Scope, cgroup_context), + .kill_context_offset = offsetof(Scope, kill_context), + .sections = "Unit\0" "Scope\0" "Install\0", - .private_section = "Scope", - .cgroup_context_offset = offsetof(Scope, cgroup_context), .no_alias = true, .no_instances = true, @@ -467,14 +486,13 @@ const UnitVTable scope_vtable = { .check_gc = scope_check_gc, - .timer_event = scope_timer_event, - .reset_failed = scope_reset_failed, .notify_cgroup_empty = scope_notify_cgroup_empty_event, .bus_interface = "org.freedesktop.systemd1.Scope", - .bus_message_handler = bus_scope_message_handler, + .bus_vtable = bus_scope_vtable, + .bus_changing_properties = bus_scope_changing_properties, .bus_set_property = bus_scope_set_property, .bus_commit_properties = bus_scope_commit_properties, |