summaryrefslogtreecommitdiff
path: root/src/basic/locale-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-07-12 13:38:43 +0200
committerLennart Poettering <lennart@poettering.net>2019-07-14 11:05:34 +0200
commita7d9fccd0e15bed540bed897569d8d9e00f09125 (patch)
tree0bab0c1a9cebdc76a09d3f4cf0fbb6dc86d2bb1f /src/basic/locale-util.c
parent13f45806268bca2c20caee4d042f12dfe68f5a1f (diff)
downloadsystemd-a7d9fccd0e15bed540bed897569d8d9e00f09125.tar.gz
systemd-a7d9fccd0e15bed540bed897569d8d9e00f09125.tar.bz2
systemd-a7d9fccd0e15bed540bed897569d8d9e00f09125.zip
locale-util: suppress non-UTF-8 locales when enumerating them
Let's hide non-UTF-8 locales by default. It's 2019 after all. Let's add an undocumented env var to reenable listing them though. This should substantially shorten the list of choices we offer users, and only show realistic choices. note that only firstboot and localectl make use of this information, and both allow configuration of values outside of these lists, hence all this change does is hide legacy options, but they are still available if you know what you do, and that's how it should be.
Diffstat (limited to 'src/basic/locale-util.c')
-rw-r--r--src/basic/locale-util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c
index 17302abf58..039e965bc4 100644
--- a/src/basic/locale-util.c
+++ b/src/basic/locale-util.c
@@ -211,6 +211,25 @@ int get_locales(char ***ret) {
if (!l)
return -ENOMEM;
+ r = getenv_bool("SYSTEMD_LIST_NON_UTF8_LOCALES");
+ if (r == -ENXIO || r == 0) {
+ char **a, **b;
+
+ /* Filter out non-UTF-8 locales, because it's 2019, by default */
+ for (a = b = l; *a; a++) {
+
+ if (endswith(*a, "UTF-8") ||
+ strstr(*a, ".UTF-8@"))
+ *(b++) = *a;
+ else
+ free(*a);
+ }
+
+ *b = NULL;
+
+ } else if (r < 0)
+ log_debug_errno(r, "Failed to parse $SYSTEMD_LIST_NON_UTF8_LOCALES as boolean");
+
strv_sort(l);
*ret = TAKE_PTR(l);