summaryrefslogtreecommitdiff
path: root/src/locale/localed-util.c
Commit message (Collapse)AuthorAgeFilesLines
* locale: when no xvariant match select the entry with an empty xvariantFranck Bui2023-04-261-1/+15
| | | | | | When doing a conversion and the specified 'xc->xvariant' has no match, select the x11 layout entry with a matching layout and an empty xvariant if such entry exists. It's still better than no conversion at all.
* locale: convert generated vconsole keymap to x11 layout automaticallyFranck Bui2023-04-241-5/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When doing x11->console conversions, find_converted_keymap() searches automatically for a candidate in the converted keymap directory for a given x11 layout. However doing console->x11 conversions, this automatic search is not done hence simple conversion in this direction can't be achieved without populating kbd-model-map with entries for converted keymaps. For example, let's consider "at" layout which is not part of kbd-model-map. The "at" x11 layout has a generated keymap "/usr/share/kbd/keymaps/xkb/at.map.gz". If we configure "at" for the x11 layout, localed is able to automatically find the "at" converted vc layout and the conversion just works : $ localectl set-x11-keymap at $ localectl System Locale: LANG=en_US.UTF-8 VC Keymap: at X11 Layout: at However in the opposite direction, ie when setting the vc keymap to "at", no conversion is done and the x11 layout is not defined: $ localectl set-keymap at $ localectl System Locale: LANG=en_US.UTF-8 VC Keymap: at X11 Layout: (unset) This patch fixes this limitation as the implemenation is relatively simple and it removes the need to populate kbd-model-map with (many) entries for converted keymaps. However the patch doesn't remove the existing entries in kbd-model-map which became unneeded after this change to be on the safe side. Note: by default the automatically generated x11 keyboard configs use keyboard model "microsoftpro" which should be equivalent to "pc105" model but with the internet/media key mapping added.
* localed-util: make use of strdupcspn()Franck Bui2023-04-241-2/+2
|
* tree-wide: use TAKE_STRUCTDavid Tardon2023-04-141-4/+2
|
* localed: fix invalid free after shifting pointers using strstripOlivier Gayot2023-04-081-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | After manually editing /etc/locale.gen, calling localectl set-locale sometimes fails. When it fails, the systemd journal shows: systemd-localed: free() / invalid pointer. It turned out that it only fails if some of the uncommented lines in /etc/locale.gen have leading spaces, as in: * C.UTF-8 <= OK * en_US.UTF-8 <= OK * fr_FR.UTF-8 <= NOK After parsing a line from /etc/locale.gen, we use strstrip() to obtain the "trimmed" line (without leading or trailing spaces). However, we store the result of strstrip() in the original pointer containing the untrimmed line. This pointer is later passed to free (this is done automatically using _cleanup_free_). This is a problem because if any leading space is present, the pointer will essentially be shifted from its original value. This will result in an invalid free upon cleanup. The same issue is present in the locale_gen_locale_supported function. Fixed by storing the result of strstrip() in a different pointer.
* locale: also verify keymaps loaded from config file and converted keymapsYu Watanabe2023-03-251-14/+34
| | | | | If vconsole.conf or friends contain an invalid keymap, then let's ignore the settings.
* locale: introduce x11_context_verify()Yu Watanabe2023-03-251-0/+30
| | | | No functional change, preparation for later commits.
* locale: split out checking existence of keymapYu Watanabe2023-03-251-0/+40
| | | | No functional change, preparation for later commits.
* locale: move x11_convert_to_vconsole() near the relevant functionsYu Watanabe2023-03-251-24/+24
| | | | No functional changes, just refactoring.
* fileio: add new helper fdopen_independent()Lennart Poettering2023-03-231-10/+4
| | | | | | | | This is a combination of fdopen() and fd_reopen(). i.e. it first reopens the fd, and then converts that into a FILE*. We do this at various places already manually. let's move this into a helper call of its own.
* copy: Make copy_xattr() more genericDaan De Meyer2023-02-141-1/+1
| | | | | Let's make copy_xattr() a little more generic in preparation for copying symlink xattrs.
* locale: drop context_clear_x11()Yu Watanabe2023-02-021-8/+2
| | | | | It is used at only place, and mostly trivial. No functional change, just refactoring.
* locale: fix ENOENT handling for vconsole.conf or xorg.confYu Watanabe2023-02-021-1/+2
|
* locale: downgrade level of one more log messageYu Watanabe2023-01-281-1/+1
|
* locale: move logging from library-like functions to callerYu Watanabe2023-01-281-16/+1
|
* locale: decouple vconsole_read_data() from x11_read_data()Yu Watanabe2023-01-281-4/+0
| | | | | Let's make library-functions simple and independent as possible as they are. No functional change, just refactoring.
* locale: sync two X11 contexts on updateYu Watanabe2023-01-281-13/+0
|
* locale: replace context_get_x11_context() with context_get_x11_context_safe()Yu Watanabe2023-01-281-12/+7
| | | | | Then, context_get_x11_context() always replies a valid X11 context. No functional change, just refactoring.
* locale: make vconsole_convert_to_x11() not update ContextYu Watanabe2023-01-281-92/+83
| | | | | | | This also makes x11_convert_to_vconsole() changed in the same way. Then, their callers update Context if necessary. No functional change, just preparation for later commits.
* locale: introduce VCContext and several helper functions for the structYu Watanabe2023-01-281-23/+74
| | | | No functional changes, preparation for later commits.
* locale: rename new XKB variables to match Debian/Ubuntu'sLuca Boccassi2023-01-241-8/+8
| | | | | | | | | | | | Debian/Ubuntu use almost the same variables, but without '_'. Given our usage is new, rename them so that they match and downstream tech debt can be removed. Follow-up for https://github.com/systemd/systemd/pull/25805 See: https://github.com/systemd/systemd/issues/24228 https://github.com/systemd/systemd/pull/25412
* locale: also save XKB settings to vconsole.confYu Watanabe2023-01-231-2/+49
| | | | | Closes #24228. Replaces #25412.
* locale: split out XKB settings to X11ContextYu Watanabe2023-01-231-68/+172
| | | | | No functional changes, just refactoring and preparation for later commits.
* locale: rename context_free_vconsole() -> context_clear_vconsole()Yu Watanabe2023-01-231-16/+16
| | | | | | | Similary, this also renames context_free_x11() -> context_clear_x11(), to make it clear that these functions do not free Context. Also, this makes context_clear() support to be called more than once.
* locale: do not use alloca() for strings which can be potentially arbitraryYu Watanabe2023-01-231-6/+13
|
* locale: several coding style fixletsYu Watanabe2023-01-231-41/+58
| | | | | | | - add missing assertions, - rename arguments for storing results, - always initialize results on success, - use _cleanup_ attribute at more places, etc.
* string-util: add new strdupcspn()/strdupspn()Lennart Poettering2023-01-201-1/+3
| | | | | | | | These combine strndup() + strspn()/strcspn() into one. There are a bunch of strndupa() calls that could use similar treatment (or should be converted to strdup[c]spn(), but this commit doesn't bother with that.
* tree-wide: change initialization to use EBADF instead of EBADFDZbigniew Jędrzejewski-Szmek2022-12-191-2/+2
| | | | | Those fds never were, so it's not fair to say that they are in "bad state". Let's use the shorter and more direct errno.
* localed: avoid TOCTOU in loading configYu Watanabe2022-12-141-32/+41
|
* localed-util: use _cleanup_ harderDavid Tardon2022-12-141-12/+4
|
* nulstr-util: Declare NULSTR_FOREACH() iterator inlineDaan De Meyer2022-11-111-1/+0
|
* localed: don't fail if we cannot copy an xattrLennart Poettering2022-07-251-1/+1
| | | | | | | We ignore xattr copy failures on all other cases, and we should do so here too. Fixes: #24106
* locale: rename keymap-util.[ch] -> localed-util.[ch]Yu Watanabe2022-06-141-0/+846
As the file contains not only keymap related functions.