X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flocale%2Flocalectl.c;h=fb21bfd7f76726c07728ae1742de605d792f9dde;hb=ffc06c3513d9a0693c7f810d03b20705127ba55a;hp=f08c1f4d199223f317544a2146becd49f5add1e6;hpb=4d7859d173282e16bb75254c2b4ec14a915ef30b;p=elogind.git diff --git a/src/locale/localectl.c b/src/locale/localectl.c index f08c1f4d1..fb21bfd7f 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -102,125 +102,30 @@ static void print_status_info(StatusInfo *i) { printf(" X11 Options: %s\n", i->x11_options); } -static int status_read_property(const char *name, sd_bus_message *property, StatusInfo *i) { - char type; - const char *contents; - int r; - - assert(name); - assert(property); - - r = sd_bus_message_peek_type(property, &type, &contents); - if (r < 0) { - log_error("Could not determine type of message: %s", strerror(-r)); - return r; - } - - switch (type) { - - case SD_BUS_TYPE_STRING: { - const char *s; - - sd_bus_message_read_basic(property, type, &s); - if (isempty(s)) - break; - - if (streq(name, "VConsoleKeymap")) - i->vconsole_keymap = s; - else if (streq(name, "VConsoleKeymapToggle")) - i->vconsole_keymap_toggle = s; - else if (streq(name, "X11Layout")) - i->x11_layout = s; - else if (streq(name, "X11Model")) - i->x11_model = s; - else if (streq(name, "X11Variant")) - i->x11_variant = s; - else if (streq(name, "X11Options")) - i->x11_options = s; - - break; - } - - case SD_BUS_TYPE_ARRAY: { - _cleanup_strv_free_ char **l = NULL; - - if (!streq(contents, "s")) - break; - - if (!streq(name, "Locale")) - break; - - r = bus_message_read_strv_extend(property, &l); - if (r < 0) - break; - - strv_free(i->locale); - i->locale = l; - l = NULL; - - break; - } - } - - return r; -} - static int show_status(sd_bus *bus, char **args, unsigned n) { - _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; - _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - int r; StatusInfo info = {}; + const struct bus_properties_map map[] = { + { "s", "VConsoleKeymap", &info.vconsole_keymap }, + { "s", "VConsoleKeymap", &info.vconsole_keymap }, + { "s", "VConsoleKeymapToggle", &info.vconsole_keymap_toggle}, + { "s", "X11Layout", &info.x11_layout }, + { "s", "X11Model", &info.x11_model }, + { "s", "X11Variant", &info.x11_variant }, + { "s", "X11Options", &info.x11_options }, + { "as", "Locale", &info.locale }, + {} + }; + int r; - assert(args); - - r = sd_bus_call_method( bus, - "org.freedesktop.locale1", - "/org/freedesktop/locale1", - "org.freedesktop.DBus.Properties", - "GetAll", - &error, - &reply, - "s", ""); - if (r < 0) { - log_error("Could not get properties: %s", bus_error_message(&error, -r)); - return r; - } + assert(bus); - r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_ARRAY, "{sv}"); + r = bus_map_all_properties(bus, + "org.freedesktop.locale1", + "/org/freedesktop/locale1", + map); if (r < 0) goto fail; - while ((r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_DICT_ENTRY, "sv")) > 0) { - const char *name; - const char *contents; - - r = sd_bus_message_read_basic(reply, SD_BUS_TYPE_STRING, &name); - if (r < 0) - goto fail; - - r = sd_bus_message_peek_type(reply, NULL, &contents); - if (r < 0) - goto fail; - - r = sd_bus_message_enter_container(reply, SD_BUS_TYPE_VARIANT, contents); - if (r < 0) - goto fail; - - r = status_read_property(name, reply, &info); - if (r < 0) { - log_error("Failed to parse reply."); - return r; - } - - r = sd_bus_message_exit_container(reply); - if (r < 0) - goto fail; - - r = sd_bus_message_exit_container(reply); - if (r < 0) - goto fail; - } - print_status_info(&info); fail: @@ -256,9 +161,8 @@ static int set_locale(sd_bus *bus, char **args, unsigned n) { return r; r = sd_bus_send_with_reply_and_block(bus, m, 0, &error, NULL); - if (r < 0) { - log_error("Failed to issue method call: %s", strerror(-r)); + log_error("Failed to issue method call: %s", bus_error_message(&error, -r)); return r; } @@ -460,6 +364,7 @@ static int set_vconsole_keymap(sd_bus *bus, char **args, unsigned n) { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; const char *map, *toggle_map; + int r; assert(bus); assert(args); @@ -474,7 +379,8 @@ static int set_vconsole_keymap(sd_bus *bus, char **args, unsigned n) { map = args[1]; toggle_map = n > 2 ? args[2] : ""; - return sd_bus_call_method(bus, + r = sd_bus_call_method( + bus, "org.freedesktop.locale1", "/org/freedesktop/locale1", "org.freedesktop.locale1", @@ -482,6 +388,10 @@ static int set_vconsole_keymap(sd_bus *bus, char **args, unsigned n) { &error, NULL, "ssbb", map, toggle_map, arg_convert, arg_ask_password); + if (r < 0) + log_error("Failed to set keymap: %s", bus_error_message(&error, -r)); + + return r; } static Set *keymaps = NULL; @@ -561,6 +471,7 @@ static int set_x11_keymap(sd_bus *bus, char **args, unsigned n) { _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; const char *layout, *model, *variant, *options; + int r; assert(bus); assert(args); @@ -577,7 +488,8 @@ static int set_x11_keymap(sd_bus *bus, char **args, unsigned n) { variant = n > 3 ? args[3] : ""; options = n > 4 ? args[4] : ""; - return sd_bus_call_method(bus, + r = sd_bus_call_method( + bus, "org.freedesktop.locale1", "/org/freedesktop/locale1", "org.freedesktop.locale1", @@ -586,6 +498,10 @@ static int set_x11_keymap(sd_bus *bus, char **args, unsigned n) { NULL, "ssssbb", layout, model, variant, options, arg_convert, arg_ask_password); + if (r < 0) + log_error("Failed to set keymap: %s", bus_error_message(&error, -r)); + + return r; } static int list_x11_keymaps(sd_bus *bus, char **args, unsigned n) { @@ -701,7 +617,7 @@ static int help(void) { " --no-pager Do not pipe output into a pager\n" " --no-ask-password Do not prompt for password\n" " -H --host=[USER@]HOST Operate on remote host\n" - " -M --machine=CONTAINER Operate on local container\n\n" + " -M --machine=CONTAINER Operate on local container\n\n" "Commands:\n" " status Show current locale settings\n" " set-locale LOCALE... Set system locale\n" @@ -745,7 +661,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "hH:M:P", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) { switch (c) {