X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flocaled.c;h=fbb5a41d1a1232312affa6d473d69e5fbf4b924e;hb=958ae0d75176a65dc6694829667a5cc9fead8cbc;hp=d7dcc9e95bbb465761ff368e5c490f2c314ec61e;hpb=07bceef2a9c520e24da427c7ce500ad36ad37571;p=elogind.git diff --git a/src/localed.c b/src/localed.c index d7dcc9e95..fbb5a41d1 100644 --- a/src/localed.c +++ b/src/localed.c @@ -29,6 +29,7 @@ #include "strv.h" #include "dbus-common.h" #include "polkit.h" +#include "def.h" #define INTERFACE \ " \n" \ @@ -108,6 +109,8 @@ static char *data[_PROP_MAX] = { NULL }; +static usec_t remain_until = 0; + static void free_data(void) { int p; @@ -212,6 +215,7 @@ static int write_data(void) { } if (strv_isempty(l)) { + strv_free(l); if (unlink("/etc/locale.conf") < 0) return errno == ENOENT ? 0 : -errno; @@ -456,6 +460,8 @@ static DBusHandlerResult locale_message_handler( } } + strv_free(l); + for (p = 0; p < _PROP_MAX; p++) { if (passed[p]) continue; @@ -537,7 +543,10 @@ static int connect_bus(DBusConnection **_bus) { goto fail; } - if (!dbus_connection_register_object_path(bus, "/org/freedesktop/locale1", &locale_vtable, NULL)) { + dbus_connection_set_exit_on_disconnect(bus, FALSE); + + if (!dbus_connection_register_object_path(bus, "/org/freedesktop/locale1", &locale_vtable, NULL) || + !dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) { log_error("Not enough memory"); r = -ENOMEM; goto fail; @@ -573,6 +582,7 @@ fail: int main(int argc, char *argv[]) { int r; DBusConnection *bus = NULL; + bool exiting = false; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); @@ -604,8 +614,17 @@ int main(int argc, char *argv[]) { if (r < 0) goto finish; - while (dbus_connection_read_write_dispatch(bus, -1)) - ; + remain_until = now(CLOCK_MONOTONIC) + DEFAULT_EXIT_USEC; + for (;;) { + + if (!dbus_connection_read_write_dispatch(bus, exiting ? -1 : (int) (DEFAULT_EXIT_USEC/USEC_PER_MSEC))) + break; + + if (!exiting && remain_until < now(CLOCK_MONOTONIC)) { + exiting = true; + bus_async_unregister_and_exit(bus, "org.freedesktop.locale1"); + } + } r = 0;