diff options
Diffstat (limited to 'src/locale/localed-util.c')
-rw-r--r-- | src/locale/localed-util.c | 30 |
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); |