[PATCH evemu] tools: handle holes in the event node lists
Peter Hutterer
peter.hutterer at who-t.net
Tue Jan 27 16:02:17 PST 2015
The current code simply counts the number of directory entries and takes that
as the maximum event node given. That isn't true if we have a hole in the
event range after removing a device, making the last device in the list
unaccessible.
Fix this by actually looking at the event node numbers.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
tools/find_event_devices.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tools/find_event_devices.c b/tools/find_event_devices.c
index fd975aa..1f7539a 100644
--- a/tools/find_event_devices.c
+++ b/tools/find_event_devices.c
@@ -46,6 +46,7 @@ char* find_event_devices(void)
struct dirent **namelist;
int i, ndev, devnum;
char *filename;
+ int max_device = 0;
ndev = scandir(DEV_INPUT_EVENT, &namelist, is_event_device, versionsort);
if (ndev <= 0)
@@ -68,13 +69,18 @@ char* find_event_devices(void)
fprintf(stderr, "%s: %s\n", fname, name);
close(fd);
+
+ sscanf(namelist[i]->d_name, "event%d", &devnum);
+ if (devnum > max_device)
+ max_device = devnum;
+
free(namelist[i]);
}
- fprintf(stderr, "Select the device event number [0-%d]: ", ndev - 1);
+ fprintf(stderr, "Select the device event number [0-%d]: ", max_device);
scanf("%d", &devnum);
- if (devnum >= ndev || devnum < 0)
+ if (devnum > max_device || devnum < 0)
return NULL;
asprintf(&filename, "%s/%s%d",
--
2.1.0
More information about the Input-tools
mailing list