summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/timedate/timedatectl.c21
-rw-r--r--src/timedate/timedated.c23
2 files changed, 41 insertions, 3 deletions
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 24b103bbb7..1e7b26276a 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -283,12 +283,27 @@ static int set_ntp(int argc, char **argv, void *userdata) {
}
static int list_timezones(int argc, char **argv, void *userdata) {
- _cleanup_strv_free_ char **zones = NULL;
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ sd_bus *bus = userdata;
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
+ char** zones;
+
+ r = sd_bus_call_method(bus,
+ "org.freedesktop.timedate1",
+ "/org/freedesktop/timedate1",
+ "org.freedesktop.timedate1",
+ "ListTimezones",
+ &error,
+ &reply,
+ NULL);
+ if (r < 0)
+ return log_error_errno(r, "Failed to request list of time zones: %s",
+ bus_error_message(&error, r));
- r = get_timezones(&zones);
+ r = sd_bus_message_read_strv(reply, &zones);
if (r < 0)
- return log_error_errno(r, "Failed to read list of time zones: %m");
+ return bus_log_parse_error(r);
(void) pager_open(arg_pager_flags);
strv_print(zones);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 5a432fea24..e16888945c 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -916,6 +916,28 @@ static int method_set_ntp(sd_bus_message *m, void *userdata, sd_bus_error *error
return sd_bus_reply_method_return(m, NULL);
}
+static int method_list_timezones(sd_bus_message *m, void *userdata, sd_bus_error *error) {
+ _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
+ _cleanup_strv_free_ char **zones = NULL;
+ int r;
+
+ assert(m);
+
+ r = get_timezones(&zones);
+ if (r < 0)
+ return sd_bus_error_set_errnof(error, r, "Failed to read list of time zones: %m");
+
+ r = sd_bus_message_new_method_return(m, &reply);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_append_strv(reply, zones);
+ if (r < 0)
+ return r;
+
+ return sd_bus_send(NULL, reply, NULL);
+}
+
static const sd_bus_vtable timedate_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Timezone", "s", NULL, offsetof(Context, zone), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
@@ -929,6 +951,7 @@ static const sd_bus_vtable timedate_vtable[] = {
SD_BUS_METHOD("SetTimezone", "sb", NULL, method_set_timezone, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetLocalRTC", "bbb", NULL, method_set_local_rtc, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetNTP", "bb", NULL, method_set_ntp, SD_BUS_VTABLE_UNPRIVILEGED),
+ SD_BUS_METHOD("ListTimezones", NULL, "as", method_list_timezones, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END,
};