summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2011-07-21 15:13:40 +1000
committerHenrik Rydberg <rydberg@euromail.se>2011-09-12 14:19:45 +0200
commit9752b50e922572e4cd214ac45ed95e4ee410fe24 (patch)
tree2d848c2d2aebc27958ffcb817fcc4e09a2ad5088
parent06c11ce16fdf9ecfda3b4f4f74b62814c104f9e0 (diff)
evemu-device: Use signal handler for all terminationHEADmaster
If evemu-device is backgrounded it can only be killed with SIGTERM. That again doesn't clean up properly. Since we didn't do anything with the read(2) data anyway, replace it with a sleep(3) and set the signal handler to terminate the loop on SIGINT and a few other signals. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--tools/evemu-device.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/tools/evemu-device.c b/tools/evemu-device.c
index 26da7d9..eea6b18 100644
--- a/tools/evemu-device.c
+++ b/tools/evemu-device.c
@@ -43,15 +43,16 @@
43#include "evemu.h" 43#include "evemu.h"
44#include <stdio.h> 44#include <stdio.h>
45#include <fcntl.h> 45#include <fcntl.h>
46#include <signal.h>
46#include <string.h> 47#include <string.h>
47#include <unistd.h> 48#include <unistd.h>
48 49
49#define UINPUT_NODE "/dev/uinput" 50#define UINPUT_NODE "/dev/uinput"
50#define MAX_EVENT_NODE 32 51#define MAX_EVENT_NODE 32
51 52
52static void hold_device(const struct evemu_device *dev) 53static int find_and_report_device(const struct evemu_device *dev)
53{ 54{
54 char node[256], data[256]; 55 char node[256];
55 int fd, ret, i; 56 int fd, ret, i;
56 57
57 memset(node, 0, sizeof(node)); 58 memset(node, 0, sizeof(node));
@@ -70,13 +71,31 @@ static void hold_device(const struct evemu_device *dev)
70 close(fd); 71 close(fd);
71 } 72 }
72 73
73 fd = open(node, O_RDONLY); 74 if (!node[0]) {
74 if (fd < 0) 75 fprintf(stderr, "%s: input node not found larger than %d?\n",
75 return; 76 evemu_get_name(dev), MAX_EVENT_NODE);
77 return 0;
78 }
79
76 fprintf(stdout, "%s: %s\n", evemu_get_name(dev), node); 80 fprintf(stdout, "%s: %s\n", evemu_get_name(dev), node);
77 fflush(stdout); 81 fflush(stdout);
78 while ((ret = read(fd, data, sizeof(data))) > 0); 82 return 1;
79 close(fd); 83}
84
85static int stop;
86
87static void signal_handler(int signal)
88{
89 stop = 1;
90}
91
92static void wait_for_signal(const struct evemu_device *dev)
93{
94 signal(SIGINT, signal_handler);
95 signal(SIGTTIN, signal_handler);
96 signal(SIGTTOU, signal_handler);
97
98 while (!stop && sleep(10000));
80} 99}
81 100
82static int evemu_device(FILE *fp) 101static int evemu_device(FILE *fp)
@@ -102,7 +121,12 @@ static int evemu_device(FILE *fp)
102 ret = evemu_create(dev, fd); 121 ret = evemu_create(dev, fd);
103 if (ret < 0) 122 if (ret < 0)
104 goto out_close; 123 goto out_close;
105 hold_device(dev); 124
125 ret = find_and_report_device(dev);
126 if (ret <= 0)
127 goto out_close;
128
129 wait_for_signal(dev);
106 evemu_destroy(fd); 130 evemu_destroy(fd);
107 131
108out_close: 132out_close: