aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2015-01-29 06:57:08 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2015-01-29 06:57:45 +1000
commit3e81e4adca50ba5765cd1d8fe252d52917a224c9 (patch)
tree8c864ff2939a661a4f81549bd596d2f3c47fe76e
parent412c1ad90de654d152d1d9813f81a6e9d08283fe (diff)
downloadexternal_evtest-3e81e4adca50ba5765cd1d8fe252d52917a224c9.tar.gz
external_evtest-3e81e4adca50ba5765cd1d8fe252d52917a224c9.tar.bz2
external_evtest-3e81e4adca50ba5765cd1d8fe252d52917a224c9.zip
Handle holes in the event node lists
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@who-t.net>
-rw-r--r--evtest.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/evtest.c b/evtest.c
index f4b9897..0fe7aa6 100644
--- a/evtest.c
+++ b/evtest.c
@@ -684,6 +684,7 @@ static char* scan_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)
@@ -706,13 +707,18 @@ static char* scan_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",