diff options
author | tblume <Thomas.Blume@suse.com> | 2017-11-10 10:31:44 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-11-10 10:31:44 +0100 |
commit | ed457f1380d690e26163fd3ad6aff946048e1064 (patch) | |
tree | 07c2a15860d38190ffb4457e31fa4ff741c4042c /src/basic/locale-util.c | |
parent | c54515b1e42384ad4c582f7fb13434f9224c148f (diff) | |
download | systemd-ed457f1380d690e26163fd3ad6aff946048e1064.tar.gz systemd-ed457f1380d690e26163fd3ad6aff946048e1064.tar.bz2 systemd-ed457f1380d690e26163fd3ad6aff946048e1064.zip |
systemd-firstboot: add vconsole keymap support (#7035)
Enable systemd-firstboot to set the keymap.
RFE:
https://github.com/systemd/systemd/issues/6346
Diffstat (limited to 'src/basic/locale-util.c')
-rw-r--r-- | src/basic/locale-util.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index ada0a28cd8..0e546c0507 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -20,6 +20,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <ftw.h> #include <langinfo.h> #include <libintl.h> #include <locale.h> @@ -30,6 +31,7 @@ #include <sys/mman.h> #include <sys/stat.h> +#include "def.h" #include "dirent-util.h" #include "fd-util.h" #include "hashmap.h" @@ -270,6 +272,99 @@ out: return (bool) cached_answer; } +static thread_local Set *keymaps = NULL; + +static int nftw_cb( + const char *fpath, + const struct stat *sb, + int tflag, + struct FTW *ftwbuf) { + + char *p, *e; + int r; + + if (tflag != FTW_F) + return 0; + + if (!endswith(fpath, ".map") && + !endswith(fpath, ".map.gz")) + return 0; + + p = strdup(basename(fpath)); + if (!p) + return FTW_STOP; + + e = endswith(p, ".map"); + if (e) + *e = 0; + + e = endswith(p, ".map.gz"); + if (e) + *e = 0; + + r = set_consume(keymaps, p); + if (r < 0 && r != -EEXIST) + return r; + + return 0; +} + +int get_keymaps(char ***ret) { + _cleanup_strv_free_ char **l = NULL; + const char *dir; + int r; + + keymaps = set_new(&string_hash_ops); + if (!keymaps) + return -ENOMEM; + + NULSTR_FOREACH(dir, KBD_KEYMAP_DIRS) { + r = nftw(dir, nftw_cb, 20, FTW_MOUNT|FTW_PHYS|FTW_ACTIONRETVAL); + + if (r == FTW_STOP) + log_debug("Directory not found %s", dir); + else if (r < 0) + log_debug_errno(r, "Can't add keymap: %m"); + } + + l = set_get_strv(keymaps); + if (!l) { + set_free_free(keymaps); + return -ENOMEM; + } + + set_free(keymaps); + + if (strv_isempty(l)) + return -ENOENT; + + strv_sort(l); + + *ret = l; + l = NULL; + + return 0; +} + +bool keymap_is_valid(const char *name) { + + if (isempty(name)) + return false; + + if (strlen(name) >= 128) + return false; + + if (!utf8_is_valid(name)) + return false; + + if (!filename_is_valid(name)) + return false; + + if (!string_is_safe(name)) + return false; + + return true; +} const char *special_glyph(SpecialGlyph code) { |