PDA

View Full Version : how to notify an application when a usb flash drive gets connected..



nass
1st December 2006, 14:29
hello everyone,
i am not sure where to start looking for what i want, which is as stated in the title, a way to notify an application that a usb has been connected. so that then the application can mount the file system and do some IO operations.
Any hints and pointers as to what header file is suitable to do that (in linux) as well as any other pointers you have to offer are very welcome.
thank you for your help
nass

jacek
1st December 2006, 14:59
Sounds like a job for HAL (http://www.freedesktop.org/wiki/Software/hal) and DBUS.

nass
1st December 2006, 15:31
thank you for your fast reply.
hmmm it looks it might be a generally appropriate technique,
however is there some simpler technique of the form

if the kernel (using hotplug or other means) realises that there a usb device has been connected, it should send a singal (SIGUSR1 or some other) which then i can intercept from within the application (and i can do a printf() or smth).

nass

wysota
1st December 2006, 15:51
however is there some simpler technique of the form

if the kernel (using hotplug or other means) realises that there a usb device has been connected,
Currently hotplug uses hal to do its job.


it should send a singal (SIGUSR1 or some other) which then i can intercept from within the application (and i can do a printf() or smth).

A unix signal is sent to a particular application, so you can't simply "attach" to a signal.

As an alternative you could try to monitor the file system (either /etc/fstab or /mnt/something) if you are sure that the device will be automounted in a particular location but this method might fail, so using HAL is a preffered solution.

nass
1st December 2006, 15:55
ok u convinced me:D
i will look into it thoroughly
thank you once again.
nass

sunil.thaha
2nd December 2006, 05:31
As an alternative you could try to monitor the file system (either /etc/fstab or /mnt/something) if you are sure that the device will be automounted in a particular location but this method might fail, so using HAL is a preffered solution.

How about /proc ?

wysota
2nd December 2006, 09:11
How about /proc ?
What about it?

jacek
2nd December 2006, 15:14
How about /proc ?
Yes, but not every system allows normal users to dig inside it. A similar solution is to use libusb and look from time to time for new devices.

Brandybuck
2nd December 2006, 20:41
How about /proc ?
The problem with /proc is that Linux treats it entirely different than do other Unix and Unix-like systems. Basing an application on Linux's procfs behavior means that it won't work under BSD, Solaris, etc. I would look for a better crossplatform approach.

wysota
2nd December 2006, 21:12
Furthermore /proc under Linux starts to be deprecated in favour of /sys so there is a probability that /proc (or at least most of its functionality) will soon vanish from some Linux distros.

sunil.thaha
4th December 2006, 06:38
Waw!!

Didn't know all of those... Cross platform, Deprecated !!!
Thanks for sharing the info, Guys