X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flocale%2Flocalectl.c;h=b5cd344397c859d5b92555ca26d161898cefd9df;hp=5328ac41a5b704d289d40da338d5a81d35307602;hb=546158bc6f46f8004cc11e81d19d223e0da56730;hpb=b92bea5d2a9481de69bb627a7b442a9f58fca43d diff --git a/src/locale/localectl.c b/src/locale/localectl.c index 5328ac41a..b5cd34439 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -37,6 +37,7 @@ #include "pager.h" #include "set.h" #include "path-util.h" +#include "utf8.h" static bool arg_no_pager = false; static enum transport { @@ -222,7 +223,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) { static int set_locale(DBusConnection *bus, char **args, unsigned n) { _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL; - dbus_bool_t interactive = true; + dbus_bool_t interactive = arg_ask_password; DBusError error; DBusMessageIter iter; int r; @@ -359,15 +360,17 @@ static int add_locales_from_archive(Set *locales) { if (e[i].locrec_offset == 0) continue; + if (!utf8_is_valid((char*) p + e[i].name_offset)) + continue; + z = strdup((char*) p + e[i].name_offset); if (!z) { r = log_oom(); goto finish; } - r = set_put(locales, z); + r = set_consume(locales, z); if (r < 0) { - free(z); log_error("Failed to add locale: %s", strerror(-r)); goto finish; } @@ -383,7 +386,7 @@ static int add_locales_from_archive(Set *locales) { } static int add_locales_from_libdir (Set *locales) { - DIR _cleanup_closedir_ *dir; + _cleanup_closedir_ DIR *dir; struct dirent *entry; int r; @@ -407,14 +410,10 @@ static int add_locales_from_libdir (Set *locales) { if (!z) return log_oom(); - r = set_put(locales, z); - if (r < 0) { - free(z); - - if (r != -EEXIST) { - log_error("Failed to add locale: %s", strerror(-r)); - return r; - } + r = set_consume(locales, z); + if (r < 0 && r != -EEXIST) { + log_error("Failed to add locale: %s", strerror(-r)); + return r; } errno = 0; @@ -460,7 +459,7 @@ static int list_locales(DBusConnection *bus, char **args, unsigned n) { static int set_vconsole_keymap(DBusConnection *bus, char **args, unsigned n) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; - dbus_bool_t interactive = true, b; + dbus_bool_t interactive = arg_ask_password, b; const char *map, *toggle_map; assert(bus); @@ -522,12 +521,9 @@ static int nftw_cb( if (e) *e = 0; - r = set_put(keymaps, p); - if (r == -EEXIST) - free(p); - else if (r < 0) { + r = set_consume(keymaps, p); + if (r < 0 && r != -EEXIST) { log_error("Can't add keymap: %s", strerror(-r)); - free(p); return r; } @@ -535,7 +531,7 @@ static int nftw_cb( } static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) { - char _cleanup_strv_free_ **l = NULL; + _cleanup_strv_free_ char **l = NULL; keymaps = set_new(string_hash_func, string_compare_func); if (!keymaps) @@ -569,7 +565,7 @@ static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) { static int set_x11_keymap(DBusConnection *bus, char **args, unsigned n) { _cleanup_dbus_message_unref_ DBusMessage *reply = NULL; - dbus_bool_t interactive = true, b; + dbus_bool_t interactive = arg_ask_password, b; const char *layout, *model, *variant, *options; assert(bus); @@ -607,7 +603,7 @@ static int set_x11_keymap(DBusConnection *bus, char **args, unsigned n) { static int list_x11_keymaps(DBusConnection *bus, char **args, unsigned n) { _cleanup_fclose_ FILE *f = NULL; - char _cleanup_strv_free_ **list = NULL; + _cleanup_strv_free_ char **list = NULL; char line[LINE_MAX]; enum { NONE, @@ -623,7 +619,7 @@ static int list_x11_keymaps(DBusConnection *bus, char **args, unsigned n) { return -EINVAL; } - f = fopen("/usr/share/X11/xkb/rules/xorg.lst", "re"); + f = fopen("/usr/share/X11/xkb/rules/base.lst", "re"); if (!f) { log_error("Failed to open keyboard mapping list. %m"); return -errno; @@ -716,6 +712,7 @@ static int help(void) { " --version Show package version\n" " --no-convert Don't convert keyboard mappings\n" " --no-pager Do not pipe output into a pager\n" + " -P --privileged Acquire privileges before execution\n" " --no-ask-password Do not prompt for password\n" " -H --host=[USER@]HOST Operate on remote host\n\n" "Commands:\n" @@ -761,7 +758,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 0); assert(argv); - while ((c = getopt_long(argc, argv, "has:H:P", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hH:P", options, NULL)) >= 0) { switch (c) { @@ -791,6 +788,10 @@ static int parse_argv(int argc, char *argv[]) { arg_no_pager = true; break; + case ARG_NO_ASK_PASSWORD: + arg_ask_password = false; + break; + case '?': return -EINVAL;