X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flocale%2Flocalectl.c;h=cd7356a1e13f8d8612ccaba1e270c0441999b70f;hp=eb94d13ad5b7104c2306e314ea36d9409ec38720;hb=7085053a437456ab87d726f3697002dd811fdf7a;hpb=c62e11ce3966c55d23520b9f0785c7e839cf7f37 diff --git a/src/locale/localectl.c b/src/locale/localectl.c index eb94d13ad..cd7356a1e 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -46,7 +46,8 @@ static enum transport { TRANSPORT_POLKIT } arg_transport = TRANSPORT_NORMAL; static bool arg_ask_password = true; -static const char *arg_host = NULL; +static char *arg_host = NULL; +static char *arg_user = NULL; static bool arg_convert = true; static void pager_open_if_enabled(void) { @@ -223,7 +224,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; @@ -369,9 +370,8 @@ static int add_locales_from_archive(Set *locales) { 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; } @@ -387,7 +387,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; @@ -411,14 +411,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; @@ -464,7 +460,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); @@ -526,12 +522,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; } @@ -539,7 +532,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) @@ -573,7 +566,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); @@ -611,7 +604,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, @@ -720,6 +713,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" @@ -765,7 +759,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) { @@ -784,7 +778,7 @@ static int parse_argv(int argc, char *argv[]) { case 'H': arg_transport = TRANSPORT_SSH; - arg_host = optarg; + parse_user_at_host(optarg, &arg_user, &arg_host); break; case ARG_NO_CONVERT: @@ -795,6 +789,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;