summaryrefslogtreecommitdiff
path: root/sys/src/9/ip/netdevmedium.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2019-05-11 07:22:34 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2019-05-11 07:22:34 +0200
commita25819c43a65b5abd44f42f502718e47fffc6923 (patch)
treeb5c2ec7a15a59c0c03c208ccea0b1a8eaf52b1a1 /sys/src/9/ip/netdevmedium.c
parented3a576e8b103032b659febc5d3c62565c9cf7d7 (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/netdevmedium.c')
-rw-r--r--sys/src/9/ip/netdevmedium.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sys/src/9/ip/netdevmedium.c b/sys/src/9/ip/netdevmedium.c
index 25111fd41..f3d9ac1a4 100644
--- a/sys/src/9/ip/netdevmedium.c
+++ b/sys/src/9/ip/netdevmedium.c
@@ -49,6 +49,7 @@ netdevbind(Ipifc *ifc, int argc, char **argv)
mchan = namec(argv[2], Aopen, ORDWR, 0);
er = smalloc(sizeof(*er));
+ er->readp = (void*)-1;
er->mchan = mchan;
er->f = ifc->conv->p->f;
@@ -65,10 +66,14 @@ netdevunbind(Ipifc *ifc)
{
Netdevrock *er = ifc->arg;
+ /* wait for reader to start */
+ while(er->readp == (void*)-1)
+ tsleep(&up->sleep, return0, 0, 300);
+
if(er->readp != nil)
postnote(er->readp, 1, "unbind", 0);
- /* wait for readers to die */
+ /* wait for reader to die */
while(er->readp != nil)
tsleep(&up->sleep, return0, 0, 300);