From 0413f63ee064897f26b6ef0e4eb979a6de993cc4 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Mon, 4 Mar 2013 16:35:02 -0500 Subject: [PATCH] timedated: add CanNTP property If we can't successfully query any ntpd units, set CanNTP to false. GNOME wants to use this to grey out the NTP switch in the UI. https://bugs.freedesktop.org/show_bug.cgi?id=61816 --- src/timedate/timedated.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 80c24eb..7753493 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -45,6 +45,7 @@ " \n" \ " \n" \ " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -84,10 +85,12 @@ const char timedate_interface[] _introspect_("timedate1") = INTERFACE; typedef struct TZ { char *zone; bool local_rtc; + int can_ntp; int use_ntp; } TZ; static TZ tz = { + .can_ntp = -1, .use_ntp = -1, }; @@ -387,6 +390,7 @@ static int read_ntp(DBusConnection *bus) { goto finish; } + tz.can_ntp = 1; tz.use_ntp = streq(s, "enabled") || streq(s, "enabled-runtime"); @@ -395,6 +399,7 @@ static int read_ntp(DBusConnection *bus) { } /* NTP is not installed. */ + tz.can_ntp = 0; tz.use_ntp = 0; r = 0; @@ -588,6 +593,20 @@ finish: return r; } +static int property_append_can_ntp(DBusMessageIter *i, const char *property, void *data) { + dbus_bool_t db; + + assert(i); + assert(property); + + db = tz.can_ntp > 0; + + if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &db)) + return -ENOMEM; + + return 0; +} + static int property_append_ntp(DBusMessageIter *i, const char *property, void *data) { dbus_bool_t db; @@ -605,6 +624,7 @@ static int property_append_ntp(DBusMessageIter *i, const char *property, void *d static const BusProperty bus_timedate_properties[] = { { "Timezone", bus_property_append_string, "s", offsetof(TZ, zone), true }, { "LocalRTC", bus_property_append_bool, "b", offsetof(TZ, local_rtc) }, + { "CanNTP", property_append_can_ntp, "b", offsetof(TZ, can_ntp) }, { "NTP", property_append_ntp, "b", offsetof(TZ, use_ntp) }, { NULL, } }; -- 1.8.1.4