I am facing a certain issue with libudev. I have written a listener thread that constantly keeps listening for devices connected over usb. I have used the libudev API udev_monitor_receive_device at the start of a continuous while loop as it is a blocking call. The source works fine with libudev v1.6.3, but when upgraded to v1.7.2, the call to udev_monitor_receive_device is not blocking anymore and the while loop keeps running continuously and the api keeps returning NULL. Below is a portion of the code that will help you understand the libudev usage in my code..
struct udev *udevObject ;
struct udev_device *mDev;
struct udev_enumerate *enumerate;
struct udev_monitor *mUdevMonitorObject;
udevObject = udev_new();
if(NULL == udevObject){
LOGERR((TEXT("Listener thread :: Error initialising Udev Library\r\n")));
return false;
}
mUdevMonitorObject = udev_monitor_new_from_netlink(udevObject, "udev");
udev_monitor_enable_receiving(mUdevMonitorObject);
// enumerate = udev_enumerate_new(udevObject);
// udev_enumerate_scan_devices(enumerate);
while(1)
{
// This loop keeps running continuously on libudev v1.7.3, but the call blocks for v1.6.3
mDev = udev_monitor_receive_device(mUdevMonitorObject);
LOGINFO((TEXT("Listener thread:: Processing UDEV trigger\r\n")));
}
This problem has been bugging me for a long time. Any help would be appreciated.
Yeah I see the same thing. Seems the only way to interact with udev_monitor_receive_device these days is with select/poll – I have a similar loop to you, and adding these lines before udev_monitor_recieve_device makes everything act sensible:
It would be nice if receive_device still blocked until there was data ready instead of making you do this dance, but there you go.