summaryrefslogtreecommitdiff
path: root/src/locale/localed-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-02-02 02:53:35 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-25 15:36:48 +0900
commit0327d5b20f9e845dc310cb9e87207ac982c8bbd0 (patch)
treeff0fbcd62adbdd0641564972ed2c7efdd2a45695 /src/locale/localed-util.c
parentd45cbc071144c5003d2dc35d388790dacad6e6f0 (diff)
downloadsystemd-0327d5b20f9e845dc310cb9e87207ac982c8bbd0.tar.gz
locale: introduce x11_context_verify()
No functional change, preparation for later commits.
Diffstat (limited to 'src/locale/localed-util.c')
-rw-r--r--src/locale/localed-util.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c
index f955a74a8a..bb08c0b78a 100644
--- a/src/locale/localed-util.c
+++ b/src/locale/localed-util.c
@@ -24,6 +24,7 @@
#include "string-util.h"
#include "strv.h"
#include "tmpfile-util.h"
+#include "xkbcommon-util.h"
static bool startswith_comma(const char *s, const char *prefix) {
assert(s);
@@ -154,6 +155,35 @@ int x11_context_copy(X11Context *dest, const X11Context *src) {
return modified;
}
+int x11_context_verify_and_warn(const X11Context *xc, int log_level, sd_bus_error *error) {
+ int r;
+
+ assert(xc);
+
+ if (!x11_context_is_safe(xc)) {
+ if (error)
+ sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid X11 keyboard layout.");
+ return log_full_errno(log_level, SYNTHETIC_ERRNO(EINVAL), "Invalid X11 keyboard layout.");
+ }
+
+ r = verify_xkb_rmlvo(xc->model, xc->layout, xc->variant, xc->options);
+ if (r == -EOPNOTSUPP) {
+ log_full_errno(MAX(log_level, LOG_NOTICE), r,
+ "Cannot verify if new keymap is correct, libxkbcommon.so unavailable.");
+ return 0;
+ }
+ if (r < 0) {
+ if (error)
+ sd_bus_error_set_errnof(error, r, "Specified keymap cannot be compiled, refusing as invalid.");
+ return log_full_errno(log_level, r,
+ "Cannot compile XKB keymap for x11 keyboard layout "
+ "(model='%s' / layout='%s' / variant='%s' / options='%s'): %m",
+ strempty(xc->model), strempty(xc->layout), strempty(xc->variant), strempty(xc->options));
+ }
+
+ return 0;
+}
+
void vc_context_clear(VCContext *vc) {
assert(vc);