]> git.lizzy.rs Git - plan9front.git/commitdiff
nusb/usbd: fix /env/usbbusy bug
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sat, 7 Mar 2020 21:26:49 +0000 (22:26 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sat, 7 Mar 2020 21:26:49 +0000 (22:26 +0100)
run the usb hub poll "work()" proc in the same filedescriptor
group as the fileserver by forking the process in Srv.start
callback.

this also prevents the usbbusy filedescriptor from being kept
open by the fileserver process.

sys/src/cmd/nusb/usbd/dat.h
sys/src/cmd/nusb/usbd/hub.c
sys/src/cmd/nusb/usbd/usbd.c

index 821920ce377f9d0a4d0265c74c51a208ae598050..7d1831bb699b40ca151b8f6c5e13942913a7f0de 100644 (file)
@@ -122,3 +122,5 @@ struct DSSHub
        uchar   wHubDelay[2];
        uchar   DeviceRemovable[1];     /* variable length */
 };
+
+extern Hub *hubs;
index 22d10926a7de2c07f57b4216db45995ab6c8d88d..b6d1a915b89494f481f99a78554ab5186a752463 100644 (file)
@@ -670,22 +670,9 @@ dump(void)
 void
 work(void)
 {
-       char *fn;
        Hub *h;
        int i;
 
-       hubs = nil;
-       while((fn = rendezvous(work, nil)) != nil){
-               dprint(2, "%s: %s starting\n", argv0, fn);
-               h = newhub(fn, nil);
-               if(h == nil)
-                       fprint(2, "%s: %s: newhub failed: %r\n", argv0, fn);
-               free(fn);
-       }
-
-       if(hubs == nil)
-               return;
-
        /*
         * Enumerate (and acknowledge after first enumeration).
         * Do NOT perform enumeration concurrently for the same
index 804b69277b196511fd651f5a8d87fc8ba496d35c..fa56f68661b61e064f361cbc9e3b7ed69776f910 100644 (file)
@@ -329,7 +329,17 @@ usbdflush(Req *req)
        respond(req, nil);
 }
 
+static void
+usbdstart(Srv*)
+{
+       switch(rfork(RFPROC|RFMEM|RFNOWAIT)){
+       case -1: sysfatal("rfork: %r");
+       case 0: work(); exits(nil);
+       }
+}
+
 Srv usbdsrv = {
+       .start = usbdstart,
        .attach = usbdattach,
        .walk1 = usbdwalk,
        .read = usbdread,
@@ -447,6 +457,7 @@ void
 main(int argc, char **argv)
 {
        int fd, i, nd;
+       char *fn;
        Dir *d;
 
        ARGBEGIN {
@@ -458,34 +469,33 @@ main(int argc, char **argv)
                break;
        } ARGEND;
 
-       busyfd = create("/env/usbbusy", ORCLOSE, 0600);
        quotefmtinstall();
        fmtinstall('U', Ufmt);
        initevent();
-       rfork(RFNOTEG);
-       switch(rfork(RFPROC|RFMEM|RFNOWAIT)){
-       case -1: sysfatal("rfork: %r");
-       case 0: work(); exits(nil);
-       }
+
+       hubs = nil;
        if(argc == 0){
-               if((fd = open("/dev/usb", OREAD)) < 0){
-                       rendezvous(work, nil);
+               if((fd = open("/dev/usb", OREAD)) < 0)
                        sysfatal("/dev/usb: %r");
-               }
                nd = dirreadall(fd, &d);
                close(fd);
-               if(nd < 2){
-                       rendezvous(work, nil);
-                       sysfatal("/dev/usb: no hubs");
+               for(i = 0; i < nd; i++){
+                       if(strcmp(d[i].name, "ctl") != 0){
+                               fn = smprint("/dev/usb/%s", d[i].name);
+                               newhub(fn, nil);
+                               free(fn);
+                       }
                }
-               for(i = 0; i < nd; i++)
-                       if(strcmp(d[i].name, "ctl") != 0)
-                               rendezvous(work, smprint("/dev/usb/%s", d[i].name));
                free(d);
-       }else
+       }else {
                for(i = 0; i < argc; i++)
-                       rendezvous(work, estrdup9p(argv[i]));
-       rendezvous(work, nil);
+                       newhub(argv[i], nil);
+       }
+
+       if(hubs == nil)
+               sysfatal("no hubs");
+
+       busyfd = create("/env/usbbusy", ORCLOSE, 0600);
        postsharesrv(&usbdsrv, nil, "usb", "usbd");
        exits(nil);
 }