{0, 0}, NULL
};
+/*
+ * Values that are read only via sysfs node
+ */
+static sysfs = 0;
+static char *node_input = NULL, *node_event = NULL;
+static char *drv_name = NULL, *keytable_name = NULL;
+
struct keytable *nextkey = &keys;
static error_t parse_keyfile(char *fname)
do {
old = uevent;
uevent = uevent->next;
- free (old);
+ if (old->key)
+ free(old->key);
+ if (old->value)
+ free(old->value);
+ free(old);
} while (uevent);
}
struct uevents *next, *uevent;
char *event = "uevent", *file, s[4096];
- next = uevent = malloc(sizeof(*uevent));
+ next = uevent = calloc(1, sizeof(*uevent));
file = malloc(strlen(dname) + strlen(event) + 1);
strcpy(file, dname);
strcpy(next->key, p);
p = strtok(NULL, "\n");
- if (!next->value) {
+ if (!p) {
fprintf(stderr, "Error on uevent information\n");
fclose(fp);
free(file);
if (debug)
fprintf(stderr, "%s uevent %s=%s\n", file, next->key, next->value);
- next->next = malloc(sizeof(*next));
+ next->next = calloc(1, sizeof(*next));
if (!next->next) {
perror("next->next");
free(file);
return uevent;
}
-static char *node_input, *node_event;
-
static char *find_device(void)
{
struct uevents *uevent;
while (uevent->next) {
if (!strcmp(uevent->key, "DEVNAME")) {
- name = malloc(strlen(uevent->key) + strlen(DEV) + 1);
+ name = malloc(strlen(uevent->value) + strlen(DEV) + 1);
strcpy(name, DEV);
strcat(name, uevent->value);
break;
}
free_uevent(uevent);
+ uevent = read_sysfs_uevents(dname);
+ if (!uevent)
+ return NULL;
+ while (uevent->next) {
+ if (!strcmp(uevent->key, "DRV_NAME")) {
+ drv_name = malloc(strlen(uevent->value) + 1);
+ strcpy(drv_name, uevent->value);
+ }
+ if (!strcmp(uevent->key, "NAME")) {
+ keytable_name = malloc(strlen(uevent->value) + 1);
+ strcpy(keytable_name, uevent->value);
+ }
+ uevent = uevent->next;
+ }
+ free_uevent(uevent);
+
if (debug)
fprintf(stderr, "input device is %s\n", name);
+ sysfs++;
+
return name;
}
return -1;
dev_from_class++;
}
+ if (sysfs)
+ printf("Kernel driver %s, using table %s\n", drv_name, keytable_name);
+
if (debug)
fprintf(stderr, "Opening %s\n",devname);
if ((fd = open(devname, O_RDONLY)) < 0) {