views:

49

answers:

2

I need to run some code on storage device mounting and unmounting.
How can i listen for these events on linux?

  • I was thinking on adding some udev rules to run some script (any know-how in this matter is appreciated).
  • But I would much rather listen for events from the kernel in some netlink socket with my daemon (just like udev does) or something like that.
+3  A: 

You can use libudev or the more convenient, glib based gudev to monitor udev events in C.

lunaryorn
+1  A: 

You have to listen to the "uevent" signal. Attach a callback to this signal and wait for the notification.

Praveen S