chiark / gitweb /
sanitise "opened"
authorian <ian>
Mon, 16 Jun 2008 01:24:42 +0000 (01:24 +0000)
committerian <ian>
Mon, 16 Jun 2008 01:24:42 +0000 (01:24 +0000)
hostside/evdev-manip.c

index c4d46f3965290d3674d10702068fce3075e7f1f3..023bbde31a4a180214b4daa4e3af52894b07d8cf 100644 (file)
@@ -90,6 +90,7 @@ struct ModeInfo {
   void (*evdev_synch)(Device *d, struct timeval tv);
   void (*hiddev_event)(Device *d, const struct hiddev_usage_ref *ur);
   int (*hiddev_xflags)(void);
+  void (*opened)(Device *d);
   void (*redacted)(Device *d, int nstrs, const char *strs[nstrs], int value);
   void (*died)(Device *d, int revents, int readr, int readc, int e)
        __attribute__((noreturn));
@@ -315,8 +316,9 @@ static void evdev_prepare(Device *d) {
 
   r= ioctl(d->fd, EVIOCGID, &iid);
   if (r) diee("%s: failed to get id",d->path);
-  
-  printf("device %s bustype ", d->path);
+
+  mode->opened(d);
+  printf(" bustype ");
   PR_TABLE_STR(bus, iid.bustype);
   DUMP_VPV(iid);
   putchar('\n');
@@ -484,7 +486,8 @@ static void hiddev_prepare(Device *d) {
   r= ioctl(d->fd, HIDIOCGDEVINFO, &di);
   if (r) diee("hiddev %s: ioctl HIDIOCGDEVINFO", d->path);
 
-  printf("device %s bustype ", d->path);
+  mode->opened(d);
+  printf(" bustype ");
   PR_TABLE_STR(bus, di.bustype);
   printf(" bus %d dev %d if %d", di.busnum, di.devnum, di.ifnum);
   DUMP_VPV(di);
@@ -512,6 +515,10 @@ static void dump_died(Device *d, int revents, int readr, int readc, int e) {
   exit(0);
 }
 
+static void dump_opened(Device *d) {
+  printf("device %s", d->path);
+}
+
 static void mainloop(void) {
   struct pollfd *polls;
   int i, r, npolls;
@@ -567,7 +574,7 @@ static void mainloop(void) {
 static const ModeInfo mode_dump= {
   evdev_dump, evdev_readable_dump, evdev_synch_dump,
   hiddev_dump, hiddev_xflags_dump,
-  0, dump_died, mainloop
+  dump_opened, 0, dump_died, mainloop
 };
 
 /*---------- mode redact ----------*/
@@ -613,10 +620,14 @@ static void redact_redacted(Device *d, int nstrs, const char *strs[nstrs],
   putchar('\n');
 }
 
+static void redact_opened(Device *d) {
+  printf("%s opened", d->label);
+}
+
 static const ModeInfo mode_redact= {
   evdev_redact, 0, 0,
   hiddev_redact, 0,
-  redact_redacted, dump_died, mainloop
+  redact_opened, redact_redacted, dump_died, mainloop
 };
 
 static void redaction(const char ***argv) {