]> git.lizzy.rs Git - plan9front.git/commit
ape: fix thread race with close() and select()
authorcinap_lenrek <cinap_lenrek@gmx.de>
Mon, 11 Mar 2013 00:16:34 +0000 (01:16 +0100)
committercinap_lenrek <cinap_lenrek@gmx.de>
Mon, 11 Mar 2013 00:16:34 +0000 (01:16 +0100)
commit631aef280d0363ea853b0ab878005e48153b5eea
treec2fa3af95277b317c9dc87a345317fe99b6b1445
parentd526ee0750815820ac70e030ff87775ac56785e3
ape: fix thread race with close() and select()

in ape close(), do the real filedescriptor _CLOSE() *after* we cleared
the _fdinfo[] slot because once closed, we dont own the slot anymore and
another process doing open() can trash the slot. make sure open() retuns
fd < OPEN_MAX.

double check in _startbuf() holding mux->lock if the fd is already buffered
preveting running double copyprocs on a fd.

dont zero the mux->rwant/ewant bitmaps at the end of select() as we do not
hold the mix->lock.

in _closebuf() kill copyproc while holding the mux->lock to make sure the
copyproc isnt holding it at the time it is killed. run kill() multiple times
to make sure the proc is gone.
sys/src/ape/lib/ap/plan9/_buf.c
sys/src/ape/lib/ap/plan9/close.c
sys/src/ape/lib/ap/plan9/open.c
sys/src/ape/lib/ap/plan9/read.c