X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftimedated.c;h=16f54b59d263ecdd9b43cc9919b2fa1550a8fb5b;hb=66ccd0387e528567dff92239e85c962d2f140ef1;hp=734538882f8ba4bb9156f8297e11a7a1643e4de5;hpb=c5f0532ff10abcf6808ff503fb10ca9f4df81efd;p=elogind.git diff --git a/src/timedated.c b/src/timedated.c index 734538882..16f54b59d 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" @@ -69,7 +70,7 @@ #define INTERFACES_LIST \ BUS_GENERIC_INTERFACES_LIST \ - "org.freedesktop.locale1\0" + "org.freedesktop.timedate1\0" const char timedate_interface[] _introspect_("timedate1") = INTERFACE; @@ -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; @@ -167,8 +170,24 @@ static int read_data(void) { free_data(); r = read_one_line_file("/etc/timezone", &zone); - if (r < 0 && r != -ENOENT) - return r; + if (r < 0) { + if (r != -ENOENT) + log_warning("Failed to read /etc/timezone: %s", strerror(-r)); + +#ifdef TARGET_FEDORA + r = parse_env_file("/etc/sysconfig/clock", NEWLINE, + "ZONE", &zone, + NULL); + + if (r < 0 && r != -ENOENT) + log_warning("Failed to read /etc/sysconfig/clock: %s", strerror(-r)); +#endif + } + + if (isempty(zone)) { + free(zone); + zone = NULL; + } verify_timezone(); @@ -243,7 +262,7 @@ static int write_data_local_rtc(void) { p++; e = strchr(p, '\n'); - if (!p) { + if (!e) { free(s); return -EIO; } @@ -788,7 +807,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 +846,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 +884,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;