Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06afff00 authored by Sam Bishop's avatar Sam Bishop Committed by Greg Kroah-Hartman
Browse files

USB doc patch 2



A little more detail on how and when to poll() /proc/bus/usb/devices.

Signed-off-by: default avatarSam Bishop <sam@bishop.dhs.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 34132326
Loading
Loading
Loading
Loading
+18 −7
Original line number Original line Diff line number Diff line
@@ -453,14 +453,25 @@
	    file in your Linux kernel sources.
	    file in your Linux kernel sources.
	    </para>
	    </para>


	    <para>Otherwise the main use for this file from programs
	    <para>This file, in combination with the poll() system call, can
	    is to poll() it to get notifications of usb devices
	    also be used to detect when devices are added or removed:
	    as they're plugged or unplugged.
<programlisting>int fd;
	    To see what changed, you'd need to read the file and
struct pollfd pfd;
	    compare "before" and "after" contents, scan the filesystem,

	    or see its hotplug event.
fd = open("/proc/bus/usb/devices", O_RDONLY);
pfd = { fd, POLLIN, 0 };
for (;;) {
	/* The first time through, this call will return immediately. */
	poll(&amp;pfd, 1, -1);

	/* To see what's changed, compare the file's previous and current
	   contents or scan the filesystem.  (Scanning is more precise.) */
}</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>
	    </para>

	</sect1>
	</sect1>


	<sect1>
	<sect1>