From 4156e767f68016b45f7927e818e0514628afd43f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 31 May 2018 16:27:07 +0900 Subject: [PATCH] locale: assume locale is for LANG= when variable name is not specified Closes #6070. --- man/localectl.xml | 9 +++++---- src/locale/localed.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/man/localectl.xml b/man/localectl.xml index 0a763f2524..b32c0fb4d6 100644 --- a/man/localectl.xml +++ b/man/localectl.xml @@ -121,11 +121,12 @@ - set-locale LOCALE… + set-locale LOCALE + set-locale VARIABLE=LOCALE… - Set the system locale. This takes one or more - assignments such as "LANG=de_DE.utf8", - "LC_MESSAGES=en_GB.utf8", and so on. See + Set the system locale. This takes one locale such as en_US.UTF-8, or takes one or more + locale assignments such as LANG=de_DE.utf8, LC_MESSAGES=en_GB.utf8, and so on. If + one locale without variable name is provided, then LANG= locale variable will be set. See locale7 for details on the available settings and their meanings. Use list-locales for a list of available diff --git a/src/locale/localed.c b/src/locale/localed.c index 823bcd52b8..d4835eb0a1 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -284,6 +284,18 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er if (r < 0) return r; + /* If single locale without variable name is provided, then we assume it is LANG=. */ + if (strv_length(l) == 1 && !strchr(*l, '=')) { + if (!locale_is_valid(*l)) + return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid Locale data."); + + new_locale[VARIABLE_LANG] = strdup(*l); + if (!new_locale[VARIABLE_LANG]) + return -ENOMEM; + + l = strv_free(l); + } + /* Check whether a variable is valid */ STRV_FOREACH(i, l) { bool valid = false;