Reputation: 4030
I need to find a way to detect when a usb device is plugged in C on an old embedded Linux (CentOs 4).
libudev
and libusb
are not available so I'm a little clueless with my options here. There is dbus
, however I cannot use udisks
as the device I need to detect is not a storage device.
Thanks.
Upvotes: 3
Views: 1561
Reputation: 2731
You can try to write a custom script and register it in /proc/sys/kernel/hotplug
. When a uevent occurs, the kernel will invoke your script and pass the subsystem (usb in your case) as an argument. Then you will have to match the device (I don't know how to do that, that's probably the most tricky part).
Skeleton for your custom hotplug script that matches the USB subsystem:
$ cat my_hotplug.sh #!/bin/sh [ "$1" = usb ] || exit 0 echo "Do something here"
Registering your hotplug script as the uevent helper:
echo /path/to/my_hotplug.sh > /proc/sys/kernel/hotplug
Upvotes: 3