]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
locale: assume locale is for LANG= when variable name is not specified 9115/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 31 May 2018 07:27:07 +0000 (16:27 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 31 May 2018 08:57:41 +0000 (17:57 +0900)
Closes #6070.

man/localectl.xml
src/locale/localed.c

index 0a763f2524468a176629801f76f91ed83557d864..b32c0fb4d600bcec587f674b9b24011f01c0d61a 100644 (file)
       </varlistentry>
 
       <varlistentry>
-        <term><command>set-locale LOCALE…</command></term>
+        <term><command>set-locale LOCALE</command></term>
+        <term><command>set-locale VARIABLE=LOCALE…</command></term>
 
-        <listitem><para>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
+        <listitem><para>Set the system locale. This takes one locale such as <literal>en_US.UTF-8</literal>, or takes one or more
+        locale assignments such as <literal>LANG=de_DE.utf8</literal>, <literal>LC_MESSAGES=en_GB.utf8</literal>, and so on. If
+        one locale without variable name is provided, then <literal>LANG=</literal> locale variable will be set. See
         <citerefentry project='man-pages'><refentrytitle>locale</refentrytitle><manvolnum>7</manvolnum></citerefentry>
         for details on the available settings and their meanings. Use
         <command>list-locales</command> for a list of available
index 823bcd52b88fa5358ba311717190684a15a4c191..d4835eb0a1837ea2ab0151ba3d3a888754df7c98 100644 (file)
@@ -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;