summaryrefslogtreecommitdiff
path: root/src/timedated.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-09-03 03:26:58 +0200
committerLennart Poettering <lennart@poettering.net>2011-09-03 03:26:58 +0200
commitad740100d108282d0244d5739d4dcc86fe4c5fde (patch)
tree0f2be481f6ac03fb5426e450978c558c3be89ffa /src/timedated.c
parent43de46ab92e3b343c2e35b42cf0728a9adf48f1c (diff)
dbus: terminate mechanism daemons after a while
Diffstat (limited to 'src/timedated.c')
-rw-r--r--src/timedated.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/timedated.c b/src/timedated.c
index 734538882f..b2a56e7cb0 100644
--- a/src/timedated.c
+++ b/src/timedated.c
@@ -29,6 +29,7 @@
#include "strv.h"
#include "dbus-common.h"
#include "polkit.h"
+#include "def.h"
#define NULL_ADJTIME_UTC "0.0 0 0\n0\nUTC\n"
#define NULL_ADJTIME_LOCAL "0.0 0 0\n0\nLOCAL\n"
@@ -77,6 +78,8 @@ static char *zone = NULL;
static bool local_rtc = false;
static int use_ntp = -1;
+static usec_t remain_until = 0;
+
static void free_data(void) {
free(zone);
zone = NULL;
@@ -788,7 +791,10 @@ static int connect_bus(DBusConnection **_bus) {
goto fail;
}
- if (!dbus_connection_register_object_path(bus, "/org/freedesktop/timedate1", &timedate_vtable, NULL)) {
+ dbus_connection_set_exit_on_disconnect(bus, FALSE);
+
+ if (!dbus_connection_register_object_path(bus, "/org/freedesktop/timedate1", &timedate_vtable, NULL) ||
+ !dbus_connection_add_filter(bus, bus_exit_idle_filter, &remain_until, NULL)) {
log_error("Not enough memory");
r = -ENOMEM;
goto fail;
@@ -824,6 +830,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();
@@ -861,8 +868,17 @@ int main(int argc, char *argv[]) {
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.hostname1");
+ }
+ }
r = 0;