From: Sam Bishop <[EMAIL PROTECTED]>
A little more detail on how and when to poll() /proc/bus/usb/devices.
Signed-off-by: Sam Bishop <[EMAIL PROTECTED]>
---
I recently had the need to poll() /proc/bus/usb/devices, and it took me
a little bit to figure out how to do it. (I'd never even used poll()
before.) Just in case someone else comes along behind me in the same
situation, I thought I'd help flesh out the documentation a little.
I also removed the reference to "scanning the filesystem" as a way to
detect hotplug events. I can't think of any reason why someone would
want to do it that way.
--- linux-2.6.17.9/Documentation/DocBook/usb.tmpl.orig 2006-08-24
13:32:07.602622546 -0600
+++ linux-2.6.17.9/Documentation/DocBook/usb.tmpl 2006-08-24
13:45:40.335618197 -0600
@@ -463,14 +463,28 @@
file in your Linux kernel sources.
</para>
- <para>Otherwise the main use for this file from programs
- is to poll() it to get notifications of usb devices
- as they're plugged or unplugged.
- To see what changed, you'd need to read the file and
- compare "before" and "after" contents, scan the filesystem,
- or see its hotplug event.
+ <para>This file, in combination with the poll() system call, can
+ also be used to detect when devices are added or removed:
+<programlisting>int fd;
+struct pollfd pfd;
+
+fd = open("/proc/bus/usb/devices", O_RDONLY);
+pfd = { fd, POLLIN, 0 };
+for (;;) {
+ poll(&pfd, 1, -1);
+
+ /* Compare the file's previous and current contents to determine what's
+ changed. */
+
+ /* Handle any interesting hotplug events. */
+
+ /* Record the file's previous state. */
+}</programlisting>
+ Note that this behavior is intended to be used for informational
+ and debug purposes. It would be more appropriate to use programs
+ such as udev or HAL to initialize a device or start a user-mode
+ helper program, for instance.
</para>
-
</sect1>
<sect1>
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel