#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
-#include <syslog.h>
#include <fnmatch.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "udev.h"
#include "udev-util.h"
+#include "udevadm-util.h"
#include "util.h"
static int verbose;
static int dry_run;
-static void exec_list(struct udev_enumerate *udev_enumerate, const char *action)
-{
+static void exec_list(struct udev_enumerate *udev_enumerate, const char *action) {
struct udev_list_entry *entry;
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(udev_enumerate)) {
}
}
-static const char *keyval(const char *str, const char **val, char *buf, size_t size)
-{
+static const char *keyval(const char *str, const char **val, char *buf, size_t size) {
char *pos;
strscpy(buf, size,str);
" -h,--help\n\n");
}
-static int adm_trigger(struct udev *udev, int argc, char *argv[])
-{
+static int adm_trigger(struct udev *udev, int argc, char *argv[]) {
static const struct option options[] = {
{ "verbose", no_argument, NULL, 'v' },
{ "dry-run", no_argument, NULL, 'n' },
udev_enumerate_add_match_sysname(udev_enumerate, optarg);
break;
case 'b': {
- char path[UTIL_PATH_SIZE];
- struct udev_device *dev;
-
- /* add sys dir if needed */
- if (!startswith(optarg, "/sys"))
- strscpyl(path, sizeof(path), "/sys", optarg, NULL);
- else
- strscpy(path, sizeof(path), optarg);
- util_remove_trailing_chars(path, '/');
- dev = udev_device_new_from_syspath(udev, path);
+ _cleanup_udev_device_unref_ struct udev_device *dev;
+
+ dev = find_device(udev, optarg, "/sys");
if (dev == NULL) {
log_error("unable to open the device '%s'", optarg);
return 2;
}
+
udev_enumerate_add_match_parent(udev_enumerate, dev);
- /* drop reference immediately, enumerate pins the device as long as needed */
- udev_device_unref(dev);
break;
}
+
case 'h':
help();
return 0;