]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd-terminal/idev-keyboard.c
treewide: no need to negate errno for log_*_errno()
[thirdparty/systemd.git] / src / libsystemd-terminal / idev-keyboard.c
index eca38fc7a9dd5de7b1d6dbb08da133e30ab9b0d6..a26a49a80d204446178bcb88deeef3855c9cb6fa 100644 (file)
@@ -377,7 +377,7 @@ static int kbdctx_set_locale(sd_bus *bus, const char *member, sd_bus_message *m,
 
 error:
         if (r < 0)
-                log_debug("idev-keyboard: cannot parse locale property from locale1: %s", strerror(-r));
+                log_debug_errno(r, "idev-keyboard: cannot parse locale property from locale1: %m");
 
         return r;
 }
@@ -448,7 +448,7 @@ static int kbdctx_query_locale(kbdctx *kc) {
         return 0;
 
 error:
-        log_debug("idev-keyboard: cannot send GetAll to locale1: %s", strerror(-r));
+        log_debug_errno(r, "idev-keyboard: cannot send GetAll to locale1: %m");
         return r;
 }
 
@@ -480,7 +480,7 @@ static int kbdctx_locale_props_changed_fn(sd_bus *bus,
         return 0;
 
 error:
-        log_debug("idev-keyboard: cannot handle PropertiesChanged from locale1: %s", strerror(-r));
+        log_debug_errno(r, "idev-keyboard: cannot handle PropertiesChanged from locale1: %m");
         return r;
 }
 
@@ -497,13 +497,34 @@ static int kbdctx_setup_bus(kbdctx *kc) {
                              kbdctx_locale_props_changed_fn,
                              kc);
         if (r < 0) {
-                log_debug("idev-keyboard: cannot setup locale1 link: %s", strerror(-r));
+                log_debug_errno(r, "idev-keyboard: cannot setup locale1 link: %m");
                 return r;
         }
 
         return kbdctx_query_locale(kc);
 }
 
+static void kbdctx_log_fn(struct xkb_context *ctx, enum xkb_log_level lvl, const char *format, va_list args) {
+        char buf[LINE_MAX];
+        int sd_lvl;
+
+        if (lvl >= XKB_LOG_LEVEL_DEBUG)
+                sd_lvl = LOG_DEBUG;
+        else if (lvl >= XKB_LOG_LEVEL_INFO)
+                sd_lvl = LOG_INFO;
+        else if (lvl >= XKB_LOG_LEVEL_WARNING)
+                sd_lvl = LOG_INFO; /* most XKB warnings really are informational */
+        else if (lvl >= XKB_LOG_LEVEL_ERROR)
+                sd_lvl = LOG_ERR;
+        else if (lvl >= XKB_LOG_LEVEL_CRITICAL)
+                sd_lvl = LOG_CRIT;
+        else
+                sd_lvl = LOG_CRIT;
+
+        snprintf(buf, sizeof(buf), "idev-xkb: %s", format);
+        log_internalv(sd_lvl, 0, __FILE__, __LINE__, __func__, buf, args);
+}
+
 static kbdctx *kbdctx_ref(kbdctx *kc) {
         assert_return(kc, NULL);
         assert_return(kc->ref > 0, NULL);
@@ -558,10 +579,13 @@ static int kbdctx_new(kbdctx **out, idev_context *c) {
         kc->context = c;
 
         errno = 0;
-        kc->xkb_context = xkb_context_new(0);
+        kc->xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
         if (!kc->xkb_context)
                 return errno > 0 ? -errno : -EFAULT;
 
+        xkb_context_set_log_fn(kc->xkb_context, kbdctx_log_fn);
+        xkb_context_set_log_level(kc->xkb_context, XKB_LOG_LEVEL_DEBUG);
+
         r = kbdctx_refresh_keymap(kc);
         if (r < 0)
                 return r;