From: alex Date: Mon, 16 May 2022 01:29:23 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=71411535a1fcbd5037c5abfdfac6d20dc860ffc1;p=cold ... --- diff --git a/inc/main.h b/inc/main.h index 1be3181..4300af8 100644 --- a/inc/main.h +++ b/inc/main.h @@ -3,6 +3,7 @@ #include #include +#include #include #include diff --git a/src/main.c b/src/main.c index 89d7fb2..ae5aa95 100644 --- a/src/main.c +++ b/src/main.c @@ -1,31 +1,40 @@ #include -static int detect_usbs(); +static int detect_usb(); static int on_event(); int main(int argc, char **argv) { - if(detect_usbs()<0) { return EXIT_FAILURE; } + if(detect_usb()<0) { return EXIT_FAILURE; } return EXIT_SUCCESS; } -static int detect_usbs() { +static int detect_usb() { sd_device_monitor *monitor; if(sd_device_monitor_new(&monitor)<0) { return -1; } if(sd_device_monitor_filter_add_match_subsystem_devtype(monitor,"block","disk")!=0) { return -1; } - if(sd_device_monitor_filter_update(monitor)!=0) { return -1; } if(sd_device_monitor_start(monitor,&on_event,NULL)!=0) { return -1; } - while(1) { } + if(sd_event_run(sd_device_monitor_get_event(monitor),UINT64_MAX)<0) { return -1; } return 1; } static int on_event(sd_device_monitor *monitor, sd_device *dev, void *userdata) { - printf("event?\n"); - return -1; + const char *name, *bus; + + if(sd_device_get_devname(dev,&name)!=0) { return -1; } + if(sd_device_get_property_value(dev,"ID_BUS",&bus)!=0) { return -1; } + + if(strcmp(bus,"usb")!=0) { return -1; } + + printf("dev name: %s\n",name); + + if(sd_device_monitor_stop(monitor)!=0) { return -1; } + + return 0; }