xref: /OK3568_Linux_fs/buildroot/package/input-event-daemon/0005-Support-sync-events.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From 740cfb20ae7e386391fb6528a8765e5827c9781c Mon Sep 17 00:00:00 2001
2From: Jeffy Chen <jeffy.chen@rock-chips.com>
3Date: Wed, 26 May 2021 07:10:47 +0800
4Subject: [PATCH] Support sync events
5
6Wait for child process when handling sync events(start with '*').
7
8For example:
9[Keys]
10*POWER:1      = /etc/power-key.sh press
11*POWER:0      = /etc/power-key.sh release
12
13Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
14---
15 input-event-daemon.c | 23 +++++++++++++++++++----
16 input-event-daemon.h |  4 +++-
17 2 files changed, 22 insertions(+), 5 deletions(-)
18
19diff --git a/input-event-daemon.c b/input-event-daemon.c
20index 4bf2a33..e1528a6 100644
21--- a/input-event-daemon.c
22+++ b/input-event-daemon.c
23@@ -233,7 +233,7 @@ static int idle_event_parse(unsigned long idle) {
24
25             fprintf(stderr, "  exec     : \"%s\"\n\n", fired_idle_event->exec);
26         }
27-        daemon_exec(fired_idle_event->exec);
28+        daemon_exec(fired_idle_event->exec, 0);
29     }
30
31     return (fired_idle_event != NULL);
32@@ -371,7 +371,7 @@ static void input_parse_event(struct input_event *event, const char *src) {
33             fired_key_event = key_event_parse(event->code, event->value, src);
34
35             if(fired_key_event != NULL) {
36-                daemon_exec(fired_key_event->exec);
37+                daemon_exec(fired_key_event->exec, fired_key_event->sync);
38             }
39             break;
40         case EV_SW:
41@@ -379,7 +379,7 @@ static void input_parse_event(struct input_event *event, const char *src) {
42                 switch_event_parse(event->code, event->value, src);
43
44             if(fired_switch_event != NULL) {
45-                daemon_exec(fired_switch_event->exec);
46+                daemon_exec(fired_switch_event->exec, fired_switch_event->sync);
47             }
48
49             break;
50@@ -549,6 +549,12 @@ static const char *config_key_event(char *shortcut, char *exec) {
51     strsep(&value, ":");
52     shortcut = config_trim_string(shortcut);
53
54+	new_key_event->sync = 0;
55+	if (shortcut[0] == '*') {
56+		new_key_event->sync = 1;
57+		shortcut++;
58+	}
59+
60     if((code = strrchr(shortcut, '+')) != NULL) {
61         *code = '\0';
62         code = config_trim_string(code+1);
63@@ -650,6 +656,12 @@ static const char *config_switch_event(char *switchcode, char *exec) {
64     code = config_trim_string(code);
65     value = config_trim_string(value);
66
67+	new_switch_event->sync = 0;
68+	if (code[0] == '*') {
69+		new_switch_event->sync = 1;
70+		code++;
71+	}
72+
73     new_switch_event->code = strdup(code);
74     new_switch_event->value = atoi(value);
75     new_switch_event->exec = strdup(exec);
76@@ -783,8 +795,9 @@ void daemon_start_listener() {
77     }
78 }
79
80-static void daemon_exec(const char *command) {
81+static void daemon_exec(const char *command, int sync) {
82     pid_t pid = fork();
83+
84     if(pid == 0) {
85         const char *args[] = {
86             "sh", "-c", command, NULL
87@@ -810,6 +823,8 @@ static void daemon_exec(const char *command) {
88         _exit(127);
89     } else if(pid < 0) {
90         perror(PROGRAM": fork()");
91+    } else if (sync) {
92+        waitpid(pid, NULL, 0);
93     }
94
95     return;
96diff --git a/input-event-daemon.h b/input-event-daemon.h
97index 7cab13d..4a6944b 100644
98--- a/input-event-daemon.h
99+++ b/input-event-daemon.h
100@@ -41,6 +41,7 @@ typedef struct key_event {
101     const char *modifiers[MAX_MODIFIERS];
102     size_t     modifier_n;
103     const char *exec;
104+    int sync;
105 } key_event_t;
106
107
108@@ -53,6 +54,7 @@ typedef struct switch_event {
109     const char *code;
110     signed int value;
111     const char *exec;
112+    int sync;
113 } switch_event_t;
114
115 /**
116@@ -109,7 +111,7 @@ static char         *config_trim_string(char *str);
117
118 void        daemon_init();
119 void        daemon_start_listener();
120-static void daemon_exec(const char *command);
121+static void daemon_exec(const char *command, int sync);
122 void        daemon_clean();
123 static void daemon_print_help();
124 static void daemon_print_version();
125--
1262.20.1
127
128