From cbf4bc912c074fb09d4345f7d374fc000cf79d03 Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 12 May 2022 17:47:20 -0700 Subject: [PATCH] ... --- src/main.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/main.c b/src/main.c index 3eeea7e..5932bca 100644 --- a/src/main.c +++ b/src/main.c @@ -1,31 +1,24 @@ #include int main(int argc, char **argv) { - struct udev *monitor; //, *dev; - struct udev_enumerate *enumerate; - struct udev_list_entry *devices, *dev_list_entry; - const char *path; + struct udev *udev; + struct udev_monitor *monitor; + int fd; - monitor = udev_new(); - if(NULL==monitor) { return EXIT_FAILURE; } + udev = udev_new(); + if(NULL==udev) { return EXIT_FAILURE; } - enumerate = udev_enumerate_new(monitor); + monitor = udev_monitor_new_from_netlink(udev, "udev"); + if(NULL==monitor) { return EXIT_FAILURE; } - udev_enumerate_add_match_subsystem(enumerate, "usb"); - udev_enumerate_add_nomatch_sysattr(enumerate, "bDeviceClass", "09"); - udev_enumerate_add_nomatch_sysattr(enumerate, "bInterfaceNumber", NULL); - udev_enumerate_scan_devices(enumerate); - - devices = udev_enumerate_get_list_entry(enumerate); - - udev_list_entry_foreach(dev_list_entry, devices) { - path = udev_list_entry_get_name(dev_list_entry); -// dev = udev_device_new_from_syspath(monitor, path); + if(udev_monitor_filter_add_match_subsystem_devtype(monitor,"block","disk")<0) { return EXIT_FAILURE; } - printf("found: %s\n",path); + while(1) { + fd = udev_monitor_get_fd(monitor); + if(fd<0) { return EXIT_FAILURE; } } - udev_unref(monitor); + udev_unref(udev); return EXIT_SUCCESS; } -- 2.39.5