diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-11-22 03:17:15 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2015-11-22 03:17:15 +0100 |
commit | 7e3b2cdb557b49e0862079f38f14c777b9240e0f (patch) | |
tree | 11c45d322e720853cd4171b93d48c87a5e4521d4 /sys/src/cmd | |
parent | 98363cb27276b29ff3795d1ef93e4ea2e82e106f (diff) |
usbd: intoruce /env/usbbusy
to solve the usb device enumeration race on boot, usbd creates /env/usbbusy
on startup and once all devices have been enumerated and readers have consumed
all the events, we remove the file so nusbrc/bootrc can continue. this makes
sure all the usb devices that where plugged in on boot are made available.
Diffstat (limited to 'sys/src/cmd')
-rw-r--r-- | sys/src/cmd/nusb/usbd/fns.h | 1 | ||||
-rw-r--r-- | sys/src/cmd/nusb/usbd/hub.c | 1 | ||||
-rw-r--r-- | sys/src/cmd/nusb/usbd/usbd.c | 26 |
3 files changed, 25 insertions, 3 deletions
diff --git a/sys/src/cmd/nusb/usbd/fns.h b/sys/src/cmd/nusb/usbd/fns.h index 981ff0ceb..cec17cc21 100644 --- a/sys/src/cmd/nusb/usbd/fns.h +++ b/sys/src/cmd/nusb/usbd/fns.h @@ -3,3 +3,4 @@ void detachdev(Port*); void work(void); Hub* newhub(char *, Dev *); void hname(char *); +void checkidle(void); diff --git a/sys/src/cmd/nusb/usbd/hub.c b/sys/src/cmd/nusb/usbd/hub.c index 760f160aa..2ca713e5c 100644 --- a/sys/src/cmd/nusb/usbd/hub.c +++ b/sys/src/cmd/nusb/usbd/hub.c @@ -692,6 +692,7 @@ Again: goto Again; } qunlock(&hublock); + checkidle(); sleep(pollms); if(mustdump) dump(); diff --git a/sys/src/cmd/nusb/usbd/usbd.c b/sys/src/cmd/nusb/usbd/usbd.c index 7b7f998b7..38acf310b 100644 --- a/sys/src/cmd/nusb/usbd/usbd.c +++ b/sys/src/cmd/nusb/usbd/usbd.c @@ -146,15 +146,17 @@ dirgen(int n, Dir *d, void *) return -1; d->qid.path = n + 1; d->qid.vers = 0; - if(n >= 0) + if(n >= 0){ d->qid.type = 0; - else + d->mode = 0444; + }else{ d->qid.type = QTDIR; + d->mode = 0555 | DMDIR; + } d->uid = estrdup9p(getuser()); d->gid = estrdup9p(d->uid); d->muid = estrdup9p(d->uid); d->name = estrdup9p(names[n+1]); - d->mode = 0555 | (d->qid.type << 24); d->atime = d->mtime = time(0); d->length = 0; return 0; @@ -413,6 +415,23 @@ detachdev(Port *p) pushevent(d, formatdev(d, 1)); } +/* + * we create /env/usbbusy on startup and once all devices have been + * enumerated and readers have consumed all the events, we remove the + * file so nusbrc can continue. + */ +static int busyfd = -1; + +void +checkidle(void) +{ + if(busyfd < 0 || reqlast == nil || evlast == nil || evlast->prev > 0) + return; + + close(busyfd); + busyfd = -1; +} + void main(int argc, char **argv) { @@ -428,6 +447,7 @@ main(int argc, char **argv) break; } ARGEND; + busyfd = create("/env/usbbusy", ORCLOSE, 0600); quotefmtinstall(); initevent(); rfork(RFNOTEG); |