* ^^^^^^^^^^^^^^^^^^^^
* this part is in /proc/bus/usb/devices
* and can thus be specified by caller
+ * --stdin-monitor
*/
#include "common.h"
static Device *devices;
static Mode mode;
-static int grab;
+static int grab, stdinmonitor;
static const char *expect_sysfs;
static void pr_hex(unsigned long value) { printf("%#lx",value); }
static void mainloop(void) {
struct pollfd *polls;
- int i, r;
+ int i, r, npolls;
- polls= mmalloc(sizeof(*polls)*ndevices);
+ npolls= ndevices + stdinmonitor;
+ polls= mmalloc(sizeof(*polls)*npolls);
for (i=0; i<ndevices; i++) {
polls[i].fd= devices[i].fd;
polls[i].events= POLLIN;
}
+ if (stdinmonitor) {
+ polls[ndevices].fd= 0;
+ polls[ndevices].events= POLLIN;
+ }
for (;;) {
- for (i=0; i<ndevices; i++)
+ for (i=0; i<npolls; i++)
polls[i].revents= 0;
- r= poll(polls,ndevices,-1);
+ r= poll(polls,npolls,-1);
if (r==-1) {
if (errno==EINTR) continue;
diee("poll failed");
}
assert(r>0);
+ if (stdinmonitor) {
+ if (polls[ndevices].revents) {
+ printf("quitting-stdin-polled %#x\n", polls[ndevices].revents);
+ exit(0);
+ }
+ }
+
for (i=0; i<ndevices; i++) {
if (polls[i].revents & ~POLLIN) {
unsigned char dummy;
else if (!strcmp(arg,"--dump")) { mode= &mode_dump; }
else if (!strcmp(arg,"--grab")) { grab= 1; }
else if (!strcmp(arg,"--no-grab")) { grab= 0; }
+ else if (!strcmp(arg,"--stdin-monitor")) { stdinmonitor= 1; }
else badusage("unknown option");
}
mode->mainloop();