From a25819c43a65b5abd44f42f502718e47fffc6923 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 11 May 2019 07:22:34 +0200 Subject: 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. --- sys/src/9/ip/netdevmedium.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'sys/src/9/ip/netdevmedium.c') 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); -- cgit v1.2.3