...
authoralex <[email protected]>
Fri, 13 May 2022 00:47:20 +0000 (17:47 -0700)
committeralex <[email protected]>
Fri, 13 May 2022 00:47:20 +0000 (17:47 -0700)
src/main.c

index 3eeea7ed4e66d7024ff2f2267b6379184d3a5c10..5932bcabdb612198072c5116775d313f2f5f629a 100644 (file)
@@ -1,31 +1,24 @@
 #include<main.h>
 
 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;
 }