hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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