...
authoralex <[email protected]>
Sat, 14 May 2022 05:08:47 +0000 (22:08 -0700)
committeralex <[email protected]>
Sat, 14 May 2022 05:08:47 +0000 (22:08 -0700)
configure.ac
inc/main.h
src/main.c

index 82d2bd2fa2767693a32b17bb9eb97c0e31ec9946..d1dc9c409feb4ade81b1a6830cce19225945e9e6 100644 (file)
@@ -54,7 +54,7 @@ AM_CONDITIONAL([ENABLE_MEMCHECK],[test x$enable_memcheck = xyes])
 AC_PROG_CC
 
 # Checks for libraries.
-AC_CHECK_LIB([udev],[udev_new])
+AC_CHECK_LIB([systemd],[sd_device_enumerator_new])
 
 # Checks for header files.
 AC_CHECK_HEADERS([stdlib.h])
index b3ec90b8aa7f5c800aff587f0323b0843d0a89ab..1be31819312160016fa9d457245a27357a365fb0 100644 (file)
@@ -3,8 +3,9 @@
 
 #include<stdio.h>
 #include<stdlib.h>
+#include<unistd.h>
 
-#include<libudev.h>
+#include<systemd/sd-device.h>
 
 int main(int,char**);
 
index 5932bcabdb612198072c5116775d313f2f5f629a..89d7fb2b6ea311aea3cc173c35ac903113fd6573 100644 (file)
@@ -1,24 +1,31 @@
 #include<main.h>
 
+static int detect_usbs();
+static int on_event();
+
 int main(int argc, char **argv) {
-       struct udev *udev;
-       struct udev_monitor *monitor;
-       int fd;
+       if(detect_usbs()<0) { return EXIT_FAILURE; }
 
-       udev = udev_new();
-       if(NULL==udev) { return EXIT_FAILURE; }
-       
-       monitor = udev_monitor_new_from_netlink(udev, "udev");
-       if(NULL==monitor) { return EXIT_FAILURE; }
+       return EXIT_SUCCESS;
+}
 
-       if(udev_monitor_filter_add_match_subsystem_devtype(monitor,"block","disk")<0) { return EXIT_FAILURE; }
+static int detect_usbs() {
+       sd_device_monitor *monitor;
 
-       while(1) {
-               fd = udev_monitor_get_fd(monitor);
-               if(fd<0) { return EXIT_FAILURE; }
-       }
+       if(sd_device_monitor_new(&monitor)<0) { return -1; }
 
-       udev_unref(udev);
+       if(sd_device_monitor_filter_add_match_subsystem_devtype(monitor,"block","disk")!=0) { return -1; }
 
-       return EXIT_SUCCESS;
+       if(sd_device_monitor_filter_update(monitor)!=0) { return -1; }
+
+       if(sd_device_monitor_start(monitor,&on_event,NULL)!=0) { return -1; }
+
+       while(1) { }
+
+       return 1;
+}
+
+static int on_event(sd_device_monitor *monitor, sd_device *dev, void *userdata) {
+       printf("event?\n");
+       return -1;
 }