diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-05-11 07:22:34 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-05-11 07:22:34 +0200 |
commit | a25819c43a65b5abd44f42f502718e47fffc6923 (patch) | |
tree | b5c2ec7a15a59c0c03c208ccea0b1a8eaf52b1a1 /sys/src/9/ip/loopbackmedium.c | |
parent | ed3a576e8b103032b659febc5d3c62565c9cf7d7 (diff) |
devip: avoid media bind/unbind kproc reader startup race, simplify etherbind
mark reader process pointers with (void*)-1 to mean
not started yet. this avoids the race condition when
media unbind happens before the kproc has set its
Proc* pointer. then we would not post the note and
the reader would continue running after unbind.
etherbind can be simplified by reading the #lX/addr
file to get the mac address, avoiding the temporary
buffer.
Diffstat (limited to 'sys/src/9/ip/loopbackmedium.c')
-rw-r--r-- | sys/src/9/ip/loopbackmedium.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/sys/src/9/ip/loopbackmedium.c b/sys/src/9/ip/loopbackmedium.c index c66c31092..26389f390 100644 --- a/sys/src/9/ip/loopbackmedium.c +++ b/sys/src/9/ip/loopbackmedium.c @@ -28,6 +28,7 @@ loopbackbind(Ipifc *ifc, int, char**) LB *lb; lb = smalloc(sizeof(*lb)); + lb->readp = (void*)-1; lb->f = ifc->conv->p->f; lb->q = qopen(1024*1024, Qmsg, nil, nil); ifc->arg = lb; @@ -41,11 +42,15 @@ loopbackunbind(Ipifc *ifc) { LB *lb = ifc->arg; - if(lb->readp) + /* wat for reader to start */ + while(lb->readp == (void*)-1) + tsleep(&up->sleep, return0, 0, 300); + + if(lb->readp != nil) postnote(lb->readp, 1, "unbind", 0); /* wait for reader to die */ - while(lb->readp != 0) + while(lb->readp != nil) tsleep(&up->sleep, return0, 0, 300); /* clean up */ |