Commit graph

412 commits

Author SHA1 Message Date
Franck Bui b35f71ac1a locale: when no xvariant match select the entry with an empty xvariant
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.
2023-04-26 08:15:17 +02:00
Franck Bui c821ad7d60 locale: convert generated vconsole keymap to x11 layout automatically
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.
2023-04-24 18:44:57 +02:00
Franck Bui 3c7012cdda localed-util: make use of strdupcspn() 2023-04-24 14:12:58 +02:00
David Tardon 088d71f8ed tree-wide: use TAKE_STRUCT 2023-04-14 10:15:44 +02:00
Olivier Gayot b24b10592d localed: fix invalid free after shifting pointers using strstrip
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.
2023-04-08 00:08:43 +08:00
Daan De Meyer a065dcd239 locale: Add missing libxkbcommon dependency to tests
Fixes opensuse mkosi CI build
2023-03-27 17:15:02 +02:00
Yu Watanabe 566aba0bca locale: also verify keymaps loaded from config file and converted keymaps
If vconsole.conf or friends contain an invalid keymap, then let's
ignore the settings.
2023-03-25 15:36:53 +09:00
Yu Watanabe 0327d5b20f locale: introduce x11_context_verify()
No functional change, preparation for later commits.
2023-03-25 15:36:48 +09:00
Yu Watanabe d45cbc0711 locale: split out xkbcommon related functions to xkbcommon-util.c
Then, use dlopen_many_sym_or_warn() with DLSYM_ARG() macro.
2023-03-25 15:27:23 +09:00
Yu Watanabe 384f22e39f locale: split out checking existence of keymap
No functional change, preparation for later commits.
2023-03-25 15:24:08 +09:00
Yu Watanabe 3017b9b1a6 locale: move x11_convert_to_vconsole() near the relevant functions
No functional changes, just refactoring.
2023-03-25 15:24:08 +09:00
Lennart Poettering b839101aac fileio: add new helper fdopen_independent()
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.
2023-03-23 22:48:00 +00:00
OMOJOLA JOSHUA 71243af72f
updated usage of SD_BUS_METHOD_WITH_NAMES macros to SD_BUS_METHOD_WIT… (#26840)
* localed: update usage of SD_BUS_METHOD_WITH_NAMES macros to SD_BUS_METHOD_WITH_ARGS
2023-03-15 22:52:24 +00:00
OMOJOLA JOSHUA 59228d0dbf
src: changed instances of sd_bus_call_method() to bus_call_method() (#26819)
* src: changed instances of sd_bus_call_method() to bus_call_method()
2023-03-15 00:12:57 +00:00
Lennart Poettering 4870133bfa basic: add RuntimeScope enum
In various tools and services we have a per-system and per-user concept.
So far we sometimes used a boolean indicating whether we are in system
mode, or a reversed boolean indicating whether we are in user mode, or
the LookupScope enum used by the lookup path logic.

Let's address that, in introduce a common enum for this, we can use all
across the board.

This is mostly just search/replace, no actual code changes.
2023-03-10 09:47:39 +01:00
Zbigniew Jędrzejewski-Szmek 080ecabfd7 localed: print a custom message if libxkbcommon.so is unvailable
Follow-up for 82c2095a5e.

> I feel like the logging here may be a bit confusing on the new path.
> Previously you did get a message that explained what was going on. Now you get
> an info message that the layout could not be compiled, and … that's all. I can
> imagine this being a confusing red herring if someone was trying to debug a
> problem and saw this message. Perhaps we should log something else instead/as
> well, on the case where libxkbcommon isn't present, to say that's what we're
> logging about and it just means we can't validate the configuration, not that
> it's definitely invalid?
2023-03-09 11:16:13 +09:00
Zbigniew Jędrzejewski-Szmek 82c2095a5e localed: skip verification when libxkbcommon is not installed
When compliled without libxkbcommon, we do no verification and accept the
arguments as given. When compliled against with, if dlopen() works, we do the
verification. But if dlopen() fails, we would refuse the call and return
SD_BUS_ERROR_INVALID_ARGS. 5de344704d added things
this way when converting to dlopen(), but it seems not very useful: it can be
expected that when the library is supported but missing at runtime, we degrade
softly, and that the behaviour is something inbetween the cases of hard disable
at compilation time and full support. But right now we behave more strictly then
if disabled at compilation. Change the code to just warn if dlopen fails, but
accept the arguments.

(There are various minimization scenarios where forcing the installation of
libxkbcommon is not useful. E.g. a small installation where we want to set the
keymap via logind, but the configuration is managed by a configuration
management system and is known to be valid. Verification via libxkbcommon is
just overhead in this case.)

800f65f827 moved the check earlier, so now even
a noop case of setting the values that were already in place can fail.
C.f. https://bugzilla.redhat.com/show_bug.cgi?id=2175244.
2023-03-08 19:44:12 +09:00
Jan Janssen 822cd3ff25 meson: Use dicts for test definitions
Although this slightly more verbose it makes it much easier to reason
about. The code that produces the tests heavily benefits from this.

Test lists are also now sorted by test name.
2023-02-21 15:10:26 +01:00
Daan De Meyer c17cfe6ef7 copy: Make copy_xattr() more generic
Let's make copy_xattr() a little more generic in preparation for
copying symlink xattrs.
2023-02-14 12:51:40 +01:00
Yu Watanabe c4abc55890 locale: drop context_clear_x11()
It is used at only place, and mostly trivial.
No functional change, just refactoring.
2023-02-02 03:59:21 +09:00
Yu Watanabe 181ba13b23 locale: fix ENOENT handling for vconsole.conf or xorg.conf 2023-02-02 03:59:21 +09:00
Yu Watanabe 7bb322e982 locale: downgrade level of one more log message 2023-01-28 15:06:00 +09:00
Yu Watanabe 8669bbb565 locale: move logging from library-like functions to caller 2023-01-28 15:06:00 +09:00
Yu Watanabe 189cacabe9 locale: decouple vconsole_read_data() from x11_read_data()
Let's make library-functions simple and independent as possible as they
are. No functional change, just refactoring.
2023-01-28 15:05:55 +09:00
Yu Watanabe f41338da6e locale: also check if converted keymap or friends is same as the current settings
Before this commit, if virtual console keymap is unchanged, localed just
returns without modifying anything. However, the X11 part may need updating.
So we should check for both and ensure they are unmodified.

Replaces #26190.
2023-01-28 14:54:50 +09:00
Yu Watanabe 71fa933b46 locale: sync two X11 contexts on update 2023-01-28 14:53:18 +09:00
Yu Watanabe 800f65f827 locale: always check input keyboard layout and friends earlier 2023-01-28 14:47:36 +09:00
Yu Watanabe f59d83afaa locale: replace context_get_x11_context() with context_get_x11_context_safe()
Then, context_get_x11_context() always replies a valid X11 context.
No functional change, just refactoring.
2023-01-28 14:47:36 +09:00
Yu Watanabe 90005a4f0a locale: make vconsole_convert_to_x11() not update Context
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.
2023-01-28 14:47:36 +09:00
Yu Watanabe ba4a886f2d locale: introduce VCContext and several helper functions for the struct
No functional changes, preparation for later commits.
2023-01-28 14:47:36 +09:00
Yu Watanabe e0a720012d locale: add missing logs 2023-01-28 14:47:36 +09:00
Luca Boccassi 1fd579061a locale: rename new XKB variables to match Debian/Ubuntu's
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
2023-01-24 22:09:58 +01:00
Jan Janssen 4a7ee0a521 meson: Do not include headers in source lists
Meson+ninja+compiler do this for us and are better at it.

https://mesonbuild.com/FAQ.html#do-i-need-to-add-my-headers-to-the-sources-list-like-in-autotools
2023-01-24 22:04:03 +01:00
Yu Watanabe 8589823f9d locale: also save XKB settings to vconsole.conf
Closes #24228.
Replaces #25412.
2023-01-23 11:30:03 +00:00
Yu Watanabe 50ec824570 locale: make errors in writing files not critical
Suggested at https://github.com/systemd/systemd/pull/25805#discussion_r1054871210

> we now write multiple files and we cannot possibly guarantee that
> either both updates worked or neither. unix fs apis simply have
> no concept that would allow us to implement that. hence I think
> we should update what we can, log about what we cannot, but return
> success as long as our in-memory state was updated.
2023-01-23 11:30:03 +00:00
Yu Watanabe 4f34fd5d40 locale: merge vconsole_convert_to_x11_and_emit() with method_set_vc_keyboard()
Similary, this also merges x11_convert_to_vconsole_and_emit() with
method_set_x11_keyboard().

No functional changes, preparation for later commits.
2023-01-23 11:30:03 +00:00
Yu Watanabe b41ec10ae4 locale: split out XKB settings to X11Context
No functional changes, just refactoring and preparation for later
commits.
2023-01-23 11:30:03 +00:00
Yu Watanabe c2ddaed483 locale: rename context_free_vconsole() -> context_clear_vconsole()
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.
2023-01-23 11:29:11 +00:00
Yu Watanabe 6f4514e84a locale: do not use alloca() for strings which can be potentially arbitrary 2023-01-23 11:29:11 +00:00
Yu Watanabe 76400a623f locale: several coding style fixlets
- add missing assertions,
- rename arguments for storing results,
- always initialize results on success,
- use _cleanup_ attribute at more places, etc.
2023-01-23 11:29:11 +00:00
Lennart Poettering e8bec6242b string-util: add new strdupcspn()/strdupspn()
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.
2023-01-20 17:27:51 +01:00
Zbigniew Jędrzejewski-Szmek a5937dcf39 tree-wide: change initialization to use EBADF instead of EBADFD
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.
2022-12-19 15:00:59 +01:00
Yu Watanabe 6f3473ca03
Merge pull request #25718 from yuwata/locale-cleanups
locale: avoid TOCTOU in reading config files
2022-12-16 00:51:13 +09:00
Yu Watanabe 62650f4258
Merge pull request #25602 from fbuihuu/fix-TEST-73-LOCALE
localed: reload PID1 configuration after modifying /etc/locale.conf
2022-12-15 17:47:05 +09:00
Yu Watanabe 56b7f112ed locale-setup: avoid TOCTOU in reading locale.conf 2022-12-14 20:18:58 +09:00
Yu Watanabe 7294912f18 localed: avoid TOCTOU in loading config 2022-12-14 20:18:58 +09:00
David Tardon d2b6485385 localed-util: use _cleanup_ harder 2022-12-14 09:57:35 +01:00
Franck Bui c8966e812e localed: reload PID1 configuration after modifying /etc/locale.conf
Since commit 1ad6e8b302, unsetting an environment
variable means restoring it to its default value.

However this doesn't work well when localed updates locale.conf. Indeed when a
variable is removed from that file, localed calls "UnsetAndSetEnvironment"
method which restores the default values of the unset variables obtained by
PID1 when it first read locale.conf. But since locale.conf has been updated,
these default values might be outdated and localed needs to instruct PID1 to
read locale.conf again.

Reloading PID1 configuration is quite an heavy operation for this purpose but
there's no other way unless we change again the meaning of "UnsetEnvironment"
or we introduce a new method that really unset an env variable.

That said given the fact that localed modifies locale.conf, it should have an
effect on PID1 default environment rather than on the environment explicitly
set by the user (m->client_manager).
2022-12-08 18:35:51 +01:00
Lennart Poettering f038576943 localectl,analyze: some minor vertical table rework fixes
Follow-up for #25339
2022-11-16 11:39:32 +01:00
David Tardon c62ca82656 localectl: port to vertical table 2022-11-13 20:22:34 +09:00