Use the ratelimit helpers for SYN_DROPPED logging. This guarantees that we
will still receive SYN_DROPPED log-messages after multiple days of
runtime, even though there might have been a SYN_DROPPED flood at one
point in time.

Signed-off-by: David Herrmann <[email protected]>
---
 src/evdev.c | 18 ++++++++++++------
 src/evdev.h |  4 +---
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index 3aa87a7..0e2d54d 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -926,15 +926,19 @@ evdev_device_dispatch(void *data)
                rc = libevdev_next_event(device->evdev,
                                         LIBEVDEV_READ_FLAG_NORMAL, &ev);
                if (rc == LIBEVDEV_READ_STATUS_SYNC) {
-                       if (device->syn_drops_received < 10) {
-                               device->syn_drops_received++;
+                       switch (ratelimit_test(&device->syn_drop_limit)) {
+                       case RATELIMIT_PASS:
                                log_info(libinput, "SYN_DROPPED event from "
                                         "\"%s\" - some input events have "
                                         "been lost.\n", device->devname);
-                               if (device->syn_drops_received == 10)
-                                       log_info(libinput, "No longer logging "
-                                                "SYN_DROPPED events for "
-                                                "\"%s\"\n", device->devname);
+                               break;
+                       case RATELIMIT_THRESHOLD:
+                               log_info(libinput, "SYN_DROPPED flood "
+                                        "from \"%s\"\n",
+                                        device->devname);
+                               break;
+                       case RATELIMIT_EXCEEDED:
+                               break;
                        }
 
                        /* send one more sync event so we handle all
@@ -1296,6 +1300,8 @@ evdev_device_create(struct libinput_seat *seat,
        device->scroll.threshold = 5.0; /* Default may be overridden */
        device->scroll.direction = 0;
        device->dpi = DEFAULT_MOUSE_DPI;
+       /* at most 5 SYN_DROPPED log-messages per 30s */
+       ratelimit_init(&device->syn_drop_limit, 30ULL * 1000, 5);
 
        matrix_init_identity(&device->abs.calibration);
        matrix_init_identity(&device->abs.usermatrix);
diff --git a/src/evdev.h b/src/evdev.h
index 666c8dc..eefbb79 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -137,9 +137,7 @@ struct evdev_device {
        } buttons;
 
        int dpi; /* HW resolution */
-       /* The number of times libevdev processes a SYN_DROPPED, so we can
-        * stop logging them to avoid flooding the logs. */
-       int syn_drops_received;
+       struct ratelimit syn_drop_limit; /* ratelimit for SYN_DROPPED logging */
 };
 
 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
-- 
2.1.3

_______________________________________________
wayland-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to