X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udevtrigger.c;h=bf5ec25aca66d124794824cb626ed4b7aa79ca11;hp=571bcadfc5323a844fdb8b260202d45ebe3a8c0b;hb=f14326adfe13d244b40286357655958ed52e9458;hpb=a44a30f6642ce49280012c551b532936a3a68729 diff --git a/udevtrigger.c b/udevtrigger.c index 571bcadfc..bf5ec25ac 100644 --- a/udevtrigger.c +++ b/udevtrigger.c @@ -71,8 +71,8 @@ LIST_HEAD(device_first_list); LIST_HEAD(device_default_list); LIST_HEAD(device_last_list); -LIST_HEAD(filter_subsytem_match_list); -LIST_HEAD(filter_subsytem_nomatch_list); +LIST_HEAD(filter_subsystem_match_list); +LIST_HEAD(filter_subsystem_nomatch_list); LIST_HEAD(filter_attr_match_list); LIST_HEAD(filter_attr_nomatch_list); @@ -176,14 +176,14 @@ static int subsystem_filtered(const char *subsystem) struct name_entry *loop_name; /* skip devices matching the listed subsystems */ - list_for_each_entry(loop_name, &filter_subsytem_nomatch_list, node) - if (fnmatch(subsystem, loop_name->name, 0) == 0) + list_for_each_entry(loop_name, &filter_subsystem_nomatch_list, node) + if (fnmatch(loop_name->name, subsystem, 0) == 0) return 1; /* skip devices not matching the listed subsystems */ - if (!list_empty(&filter_subsytem_match_list)) { - list_for_each_entry(loop_name, &filter_subsytem_match_list, node) - if (fnmatch(subsystem, loop_name->name, 0) == 0) + if (!list_empty(&filter_subsystem_match_list)) { + list_for_each_entry(loop_name, &filter_subsystem_match_list, node) + if (fnmatch(loop_name->name, subsystem, 0) == 0) return 0; return 1; } @@ -433,30 +433,30 @@ static void scan_failed(void) struct dirent *dent; strlcpy(base, udev_root, sizeof(base)); - strlcat(base, "/", sizeof(base)); - strlcat(base, EVENT_FAILED_DIR, sizeof(base)); + strlcat(base, "/" EVENT_FAILED_DIR, sizeof(base)); dir = opendir(base); if (dir != NULL) { for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) { - char linkname[PATH_SIZE]; - char target[PATH_SIZE]; - int len; + char device[PATH_SIZE]; + size_t start, end, i; if (dent->d_name[0] == '.') continue; - strlcpy(linkname, base, sizeof(linkname)); - strlcat(linkname, "/", sizeof(linkname)); - strlcat(linkname, dent->d_name, sizeof(linkname)); + strlcpy(device, sysfs_path, sizeof(device)); + start = strlcat(device, "/", sizeof(device)); + end = strlcat(device, dent->d_name, sizeof(device)); + if (end > sizeof(device)) + end = sizeof(device); - len = readlink(linkname, target, sizeof(target)); - if (len <= 0) - continue; - target[len] = '\0'; + /* replace PATH_TO_NAME_CHAR with '/' */ + for (i = start; i < end; i++) + if (device[i] == PATH_TO_NAME_CHAR) + device[i] = '/'; - if (is_device(target)) - device_list_insert(target); + if (is_device(device)) + device_list_insert(device); else continue; } @@ -468,7 +468,7 @@ int main(int argc, char *argv[], char *envp[]) { int failed = 0; int option; - struct option options[] = { + static const struct option options[] = { { "verbose", 0, NULL, 'v' }, { "dry-run", 0, NULL, 'n' }, { "retry-failed", 0, NULL, 'F' }, @@ -501,10 +501,10 @@ int main(int argc, char *argv[], char *envp[]) failed = 1; break; case 's': - name_list_add(&filter_subsytem_match_list, optarg, 0); + name_list_add(&filter_subsystem_match_list, optarg, 0); break; case 'S': - name_list_add(&filter_subsytem_nomatch_list, optarg, 0); + name_list_add(&filter_subsystem_nomatch_list, optarg, 0); break; case 'a': name_list_add(&filter_attr_match_list, optarg, 0); @@ -514,14 +514,17 @@ int main(int argc, char *argv[], char *envp[]) break; case 'h': printf("Usage: udevtrigger OPTIONS\n" - " --verbose print the list of devices which will be triggered\n" - " --dry-run do not actually trigger the event\n" - " --retry-failed trigger only the events which are failed during a previous run\n" - " --subsystem-match= select only devices from the specified subystem\n" - " --subsystem-nomatch= exclude devices from the specified subystem\n" - " --attr-match=]> select only devices with a matching sysfs attribute\n" - " --attr-nomatch=]> exclude devices with a matching sysfs attribute\n" - " --help print this text\n" + " --verbose print the list of devices while running\n" + " --dry-run do not actually trigger the events\n" + " --retry-failed trigger only the events which have been\n" + " marked as failed during a previous run\n" + " --subsystem-match= trigger devices from a matching subystem\n" + " --subsystem-nomatch= exclude devices from a matching subystem\n" + " --attr-match=]> trigger devices with a matching sysfs\n" + " attribute\n" + " --attr-nomatch=]> exclude devices with a matching sysfs\n" + " attribute\n" + " --help print this text\n" "\n"); goto exit; default: @@ -539,8 +542,8 @@ int main(int argc, char *argv[], char *envp[]) exec_lists(); exit: - name_list_cleanup(&filter_subsytem_match_list); - name_list_cleanup(&filter_subsytem_nomatch_list); + name_list_cleanup(&filter_subsystem_match_list); + name_list_cleanup(&filter_subsystem_nomatch_list); name_list_cleanup(&filter_attr_match_list); name_list_cleanup(&filter_attr_nomatch_list);