How to detect USB drive insertion in Linux?

I wrote an application for the linux embedded project, and I want my application to display a specific menu when a user inserts a USB drive. I am programming a C ++ application with Qt.

There is no d-bus on my system, but it uses udev. It seems to me that udev is the β€œright” way to make this detection, but it seems complicated.

Can someone point me in the right direction to start with this? Is there a way to do this without udev, and if not, is there a good udev starter guide that I could use? I really don't need much functionality, just a way to notify my application when a disk is inserted (and enough information for my application to mount the disk).

thanks

Marlon

+4
source share
1 answer

The "libudev - Monitoring Interface" section of this document http://www.signal11.us/oss/udev/ you need to start.
Instead of some time (1) of the cycle and sleep, just create a function with this stuff, and then set up a periodic Qt timer to call it every half second or something else.

+3
source

All Articles