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>
This commit is contained in:
Peter Hutterer 2015-01-29 06:57:08 +10:00
parent 412c1ad90d
commit 3e81e4adca
1 changed files with 8 additions and 2 deletions

View File

@ -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",