summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Kharlamov <Hi-Angel@yandex.ru>2019-01-12 02:15:20 +0300
committerKonstantin Kharlamov <Hi-Angel@yandex.ru>2019-01-17 13:08:14 +0300
commit15e64b7b60af56a31006bd4742dab3b275d47108 (patch)
tree30de4b31fdc7026da569468812aec628f8a697a5
parentd9338b001c6c5d6bd4cdf7357713462f74dd93be (diff)
downloadlibinput-15e64b7b60af56a31006bd4742dab3b275d47108.tar.gz
evdev: don't execute snprintf if not gonna print
Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
-rw-r--r--src/evdev.h6
-rw-r--r--src/libinput-private.h9
-rw-r--r--src/libinput.c3
3 files changed, 16 insertions, 2 deletions
diff --git a/src/evdev.h b/src/evdev.h
index cb765344..3a613eb5 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -713,6 +713,9 @@ evdev_log_msg(struct evdev_device *device,
va_list args;
char buf[1024];
+ if (!is_logged(evdev_libinput_context(device), priority))
+ return;
+
/* Anything info and above is user-visible, use the device name */
snprintf(buf,
sizeof(buf),
@@ -741,6 +744,9 @@ evdev_log_msg_ratelimit(struct evdev_device *device,
enum ratelimit_state state;
+ if (!is_logged(evdev_libinput_context(device), priority))
+ return;
+
state = ratelimit_test(ratelimit);
if (state == RATELIMIT_EXCEEDED)
return;
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 34cf90df..ad92cde8 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -404,6 +404,15 @@ typedef void (*libinput_source_dispatch_t)(void *data);
#define log_bug_libinput_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
#define log_bug_client_ratelimit(li_, r_, ...) log_msg_ratelimit((li_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
+static inline bool
+is_logged(const struct libinput *libinput,
+ enum libinput_log_priority priority)
+{
+ return libinput->log_handler &&
+ libinput->log_priority <= priority;
+}
+
+
void
log_msg_ratelimit(struct libinput *libinput,
struct ratelimit *ratelimit,
diff --git a/src/libinput.c b/src/libinput.c
index 01f53974..c17cc1af 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -262,8 +262,7 @@ log_msg_va(struct libinput *libinput,
const char *format,
va_list args)
{
- if (libinput->log_handler &&
- libinput->log_priority <= priority)
+ if (is_logged(libinput, priority))
libinput->log_handler(libinput, priority, format, args);
}