From 7f4c4d42dcbbfe4a89963096e3c0ed2292cc61c9 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Sat, 18 Nov 2023 15:39:41 +0100 Subject: [PATCH] Avoid deadlock when /dev/input node is hung up. --- application/input/input_linux.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/application/input/input_linux.cpp b/application/input/input_linux.cpp index a285495c..8381c704 100644 --- a/application/input/input_linux.cpp +++ b/application/input/input_linux.cpp @@ -381,11 +381,14 @@ bool LinuxInputManager::poll() { for (int i = 0; i < ret; i++) { - if (events[i].events & EPOLLIN) + auto &device = *static_cast(events[i].data.ptr); + if ((events[i].events & (EPOLLHUP | EPOLLERR)) != 0) + { + remove_device(device.devnode.c_str()); + } + else if ((events[i].events & EPOLLIN) != 0) { struct input_event input_events[32]; - auto &device = *static_cast(events[i].data.ptr); - ssize_t len; while ((len = read(device.fd, input_events, sizeof(input_events))) > 0) {