diff options
-rw-r--r-- | Documentation/DocBook/usb.tmpl | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/Documentation/DocBook/usb.tmpl b/Documentation/DocBook/usb.tmpl index 8a28f76b9359..3608472d7b74 100644 --- a/Documentation/DocBook/usb.tmpl +++ b/Documentation/DocBook/usb.tmpl | |||
@@ -453,14 +453,25 @@ | |||
453 | file in your Linux kernel sources. | 453 | file in your Linux kernel sources. |
454 | </para> | 454 | </para> |
455 | 455 | ||
456 | <para>Otherwise the main use for this file from programs | 456 | <para>This file, in combination with the poll() system call, can |
457 | is to poll() it to get notifications of usb devices | 457 | also be used to detect when devices are added or removed: |
458 | as they're plugged or unplugged. | 458 | <programlisting>int fd; |
459 | To see what changed, you'd need to read the file and | 459 | struct pollfd pfd; |
460 | compare "before" and "after" contents, scan the filesystem, | 460 | |
461 | or see its hotplug event. | 461 | fd = open("/proc/bus/usb/devices", O_RDONLY); |
462 | pfd = { fd, POLLIN, 0 }; | ||
463 | for (;;) { | ||
464 | /* The first time through, this call will return immediately. */ | ||
465 | poll(&pfd, 1, -1); | ||
466 | |||
467 | /* To see what's changed, compare the file's previous and current | ||
468 | contents or scan the filesystem. (Scanning is more precise.) */ | ||
469 | }</programlisting> | ||
470 | Note that this behavior is intended to be used for informational | ||
471 | and debug purposes. It would be more appropriate to use programs | ||
472 | such as udev or HAL to initialize a device or start a user-mode | ||
473 | helper program, for instance. | ||
462 | </para> | 474 | </para> |
463 | |||
464 | </sect1> | 475 | </sect1> |
465 | 476 | ||
466 | <sect1> | 477 | <sect1> |