new/buildroot/package/input-event-daemon/0003-Support-dynamic-remove-devices-when-not-available.patch

68 lines
2.2 KiB
Diff
Raw Normal View History

2025-05-10 21:58:58 +08:00
From fca8f74afe7d96c37d1649350d2fda0b7f0f9151 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Mon, 13 May 2019 17:45:21 +0800
Subject: [PATCH 3/7] Support dynamic remove devices when not available.
It's the same behaviour as triggerhappy.
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
input-event-daemon.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/input-event-daemon.c b/input-event-daemon.c
index 646d00d..f124250 100644
--- a/input-event-daemon.c
+++ b/input-event-daemon.c
@@ -690,19 +690,23 @@ void daemon_start_listener() {
signal(SIGCHLD, SIG_IGN);
FD_ZERO(&initial_fdset);
+ fd_len = 0;
for(i=0; i < MAX_LISTENER && conf.listen[i] != NULL; i++) {
conf.listen_fd[i] = open(conf.listen[i], O_RDONLY);
if(conf.listen_fd[i] < 0) {
fprintf(stderr, PROGRAM": open(%s): %s\n",
conf.listen[i], strerror(errno));
- exit(EXIT_FAILURE);
+ conf.listen_fd[i] = 0;
+ continue;
+ }
+ if(conf.verbose) {
+ fprintf(stderr, PROGRAM": Adding device: %s...\n", conf.listen[i]);
}
FD_SET(conf.listen_fd[i], &initial_fdset);
+ fd_len++;
}
- fd_len = i;
-
if(fd_len == 0) {
fprintf(stderr, PROGRAM": no listener found!\n");
return;
@@ -749,12 +753,18 @@ void daemon_start_listener() {
idle_time = 0;
}
- for(i=0; i<fd_len; i++) {
+ for(i=0; i<MAX_LISTENER; i++) {
if(FD_ISSET(conf.listen_fd[i], &fdset)) {
if(read(conf.listen_fd[i], &event, sizeof(event)) < 0) {
fprintf(stderr, PROGRAM": read(%s): %s\n",
conf.listen[i], strerror(errno));
- break;
+
+ /* read error? Remove the device! */
+ FD_CLR(conf.listen_fd[i], &initial_fdset);
+ close(conf.listen_fd[i]);
+ conf.listen_fd[i] = 0;
+ fd_len --;
+ continue;
}
input_parse_event(&event, conf.listen[i]);
}
--
2.20.1