struct udev_list_node sysattr_nomatch_list;
struct udev_list_node subsystem_match_list;
struct udev_list_node subsystem_nomatch_list;
+ struct udev_list_node sysname_match_list;
struct udev_list_node properties_match_list;
struct udev_list_node devices_list;
struct syspath *devices;
udev_list_init(&udev_enumerate->sysattr_nomatch_list);
udev_list_init(&udev_enumerate->subsystem_match_list);
udev_list_init(&udev_enumerate->subsystem_nomatch_list);
+ udev_list_init(&udev_enumerate->sysname_match_list);
udev_list_init(&udev_enumerate->properties_match_list);
udev_list_init(&udev_enumerate->devices_list);
return udev_enumerate;
udev_list_cleanup_entries(udev_enumerate->udev, &udev_enumerate->sysattr_nomatch_list);
udev_list_cleanup_entries(udev_enumerate->udev, &udev_enumerate->subsystem_match_list);
udev_list_cleanup_entries(udev_enumerate->udev, &udev_enumerate->subsystem_nomatch_list);
+ udev_list_cleanup_entries(udev_enumerate->udev, &udev_enumerate->sysname_match_list);
udev_list_cleanup_entries(udev_enumerate->udev, &udev_enumerate->properties_match_list);
udev_list_cleanup_entries(udev_enumerate->udev, &udev_enumerate->devices_list);
for (i = 0; i < udev_enumerate->devices_cur; i++)
return 0;
}
+/**
+ * udev_enumerate_add_match_sysname:
+ * @udev_enumerate: context
+ * @sysname: filter for the name of the device to include in the list
+ *
+ * Returns: 0 on success, otherwise a negative error value.
+ */
+int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
+{
+ if (udev_enumerate == NULL)
+ return -EINVAL;
+ if (sysname == NULL)
+ return 0;
+ if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
+ &udev_enumerate->sysname_match_list, sysname, NULL, 1, 0) == NULL)
+ return -ENOMEM;
+ return 0;
+}
+
static int match_sysattr(struct udev_enumerate *udev_enumerate, const char *syspath)
{
struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
return match;
}
+static int match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname)
+{
+ struct udev_list_entry *list_entry;
+
+ if (udev_list_get_entry(&udev_enumerate->sysname_match_list) == NULL)
+ return 1;
+
+ udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_enumerate->sysname_match_list)) {
+ if (fnmatch(udev_list_entry_get_name(list_entry), sysname, 0) != 0)
+ continue;
+ return 1;
+ }
+ return 0;
+}
+
static int scan_dir_and_add_devices(struct udev_enumerate *udev_enumerate,
const char *basedir, const char *subdir1, const char *subdir2)
{
if (dent->d_name[0] == '.')
continue;
+ if (!match_sysname(udev_enumerate, dent->d_name))
+ continue;
+
util_strscpyl(syspath, sizeof(syspath), path, "/", dent->d_name, NULL);
if (lstat(syspath, &statbuf) != 0)
continue;
int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, const char *sysattr, const char *value);
int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, const char *property, const char *value);
+int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, const char *sysname);
int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char *syspath);
/* run enumeration with active filters */
int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate);
{ "attr-match", required_argument, NULL, 'a' },
{ "attr-nomatch", required_argument, NULL, 'A' },
{ "property-match", required_argument, NULL, 'p' },
+ { "sysname-match", required_argument, NULL, 'y' },
{ "help", no_argument, NULL, 'h' },
{}
};
const char *val;
char buf[UTIL_PATH_SIZE];
- option = getopt_long(argc, argv, "vnFo:t:hcp:s:S:a:A:", options, NULL);
+ option = getopt_long(argc, argv, "vnFo:t:hcp:s:S:a:A:y:", options, NULL);
if (option == -1)
break;
key = keyval(optarg, &val, buf, sizeof(buf));
udev_enumerate_add_match_property(udev_enumerate, key, val);
break;
+ case 'y':
+ udev_enumerate_add_match_sysname(udev_enumerate, optarg);
+ break;
case 'h':
printf("Usage: udevadm trigger OPTIONS\n"
" --verbose print the list of devices while running\n"
" --attr-match=<file[=<value>]> trigger devices with a matching attribute\n"
" --attr-nomatch=<file[=<value>]> exclude devices with a matching attribute\n"
" --property-match=<key>=<value> trigger devices with a matching property\n"
+ " --sysname-match=<name> trigger devices with a matching name\n"
" --help\n\n");
goto exit;
default: