From: Sam Bishop Date: Mon, 28 Aug 2006 22:52:15 +0000 (-0600) Subject: USB doc patch 2 X-Git-Tag: v2.6.19-rc1~899^2~125 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=06afff00bcab0e384afbef70194fd3469532abdf;p=linux-2.6 USB doc patch 2 A little more detail on how and when to poll() /proc/bus/usb/devices. Signed-off-by: Sam Bishop Signed-off-by: Greg Kroah-Hartman --- diff --git a/Documentation/DocBook/usb.tmpl b/Documentation/DocBook/usb.tmpl index 8a28f76b93..3608472d7b 100644 --- a/Documentation/DocBook/usb.tmpl +++ b/Documentation/DocBook/usb.tmpl @@ -453,14 +453,25 @@ file in your Linux kernel sources. - 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. + This file, in combination with the poll() system call, can + also be used to detect when devices are added or removed: +int fd; +struct pollfd pfd; + +fd = open("/proc/bus/usb/devices", O_RDONLY); +pfd = { fd, POLLIN, 0 }; +for (;;) { + /* The first time through, this call will return immediately. */ + poll(&pfd, 1, -1); + + /* To see what's changed, compare the file's previous and current + contents or scan the filesystem. (Scanning is more precise.) */ +} + 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. -