From 719a359dde1af0c227095052c2ed1e5a865c54c7 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 13 May 2022 22:08:47 -0700 Subject: [PATCH] ... --- configure.ac | 2 +- inc/main.h | 3 ++- src/main.c | 37 ++++++++++++++++++++++--------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 82d2bd2..d1dc9c4 100644 --- a/configure.ac +++ b/configure.ac @@ -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]) diff --git a/inc/main.h b/inc/main.h index b3ec90b..1be3181 100644 --- a/inc/main.h +++ b/inc/main.h @@ -3,8 +3,9 @@ #include #include +#include -#include +#include int main(int,char**); diff --git a/src/main.c b/src/main.c index 5932bca..89d7fb2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,24 +1,31 @@ #include +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; } -- 2.30.2