diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-07-10 23:31:40 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-07-10 23:41:03 +0200 |
commit | 6797c324a653f119a3d7133122648aaa4878ddd6 (patch) | |
tree | eca8fabe59addcf4762bf934df623c176bc23242 /src/machine | |
parent | 72673e866a83e6aafdbb599eb3eff2617b7dc79d (diff) |
logind: don't misunderstand UnitRemoved signals during reloading
When PID 1 reloads the units logind/machined will see UnitRemoved
signals for all units. Instead of trusting these immediately, let's
check the actual unit state before considering a unit gone, so that
reloading PID 1 is not mistaken as the end of all sessions.
Diffstat (limited to 'src/machine')
-rw-r--r-- | src/machine/machined-dbus.c | 51 | ||||
-rw-r--r-- | src/machine/machined.c | 12 |
2 files changed, 56 insertions, 7 deletions
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 1b1eb3a333..4664c73a9c 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -583,12 +583,28 @@ DBusHandlerResult bus_message_filter( } mm = hashmap_get(m->machine_units, unit); - if (mm) { - hashmap_remove(m->machine_units, mm->scope); - free(mm->scope); - mm->scope = NULL; - + if (mm) machine_add_to_gc_queue(mm); + + } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Manager", "Reloading")) { + dbus_bool_t b; + + if (!dbus_message_get_args(message, &error, + DBUS_TYPE_BOOLEAN, &b, + DBUS_TYPE_INVALID)) { + log_error("Failed to parse Reloading message: %s", bus_error_message(&error)); + goto finish; + } + + /* systemd finished reloading, let's recheck all our machines */ + if (!b) { + Machine *mm; + Iterator i; + + log_debug("System manager has been reloaded, rechecking machines..."); + + HASHMAP_FOREACH(mm, m->machines, i) + machine_add_to_gc_queue(mm); } } @@ -727,6 +743,16 @@ int manager_stop_unit(Manager *manager, const char *unit, DBusError *error, char DBUS_TYPE_STRING, &fail, DBUS_TYPE_INVALID); if (r < 0) { + if (dbus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT) || + dbus_error_has_name(error, BUS_ERROR_LOAD_FAILED)) { + + if (job) + *job = NULL; + + dbus_error_free(error); + return 0; + } + log_error("Failed to stop unit %s: %s", unit, bus_error(error, r)); return r; } @@ -749,7 +775,7 @@ int manager_stop_unit(Manager *manager, const char *unit, DBusError *error, char *job = copy; } - return 0; + return 1; } int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, DBusError *error) { @@ -814,8 +840,19 @@ int manager_unit_is_active(Manager *manager, const char *unit) { DBUS_TYPE_STRING, &interface, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID); - if (r < 0) { + if (dbus_error_has_name(&error, DBUS_ERROR_NO_REPLY) || + dbus_error_has_name(&error, DBUS_ERROR_DISCONNECTED)) { + dbus_error_free(&error); + return true; + } + + if (dbus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT) || + dbus_error_has_name(&error, BUS_ERROR_LOAD_FAILED)) { + dbus_error_free(&error); + return false; + } + log_error("Failed to query ActiveState: %s", bus_error(&error, r)); dbus_error_free(&error); return r; diff --git a/src/machine/machined.c b/src/machine/machined.c index f2803a18c9..c7c4ecc375 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -233,6 +233,18 @@ static int manager_connect_bus(Manager *m) { dbus_error_free(&error); } + dbus_bus_add_match(m->bus, + "type='signal'," + "sender='org.freedesktop.systemd1'," + "interface='org.freedesktop.systemd1.Manager'," + "member='Reloading'," + "path='/org/freedesktop/systemd1'", + &error); + if (dbus_error_is_set(&error)) { + log_error("Failed to add match for Reloading: %s", bus_error_message(&error)); + dbus_error_free(&error); + } + r = bus_method_call_with_reply( m->bus, "org.freedesktop.systemd1", |