diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-03-11 01:16:34 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-03-11 01:16:34 +0100 |
commit | 631aef280d0363ea853b0ab878005e48153b5eea (patch) | |
tree | c2fa3af95277b317c9dc87a345317fe99b6b1445 /sys/src/ape/lib/ap/plan9/close.c | |
parent | d526ee0750815820ac70e030ff87775ac56785e3 (diff) |
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.
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/close.c')
-rw-r--r-- | sys/src/ape/lib/ap/plan9/close.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/src/ape/lib/ap/plan9/close.c b/sys/src/ape/lib/ap/plan9/close.c index 258788a39..0b86d2009 100644 --- a/sys/src/ape/lib/ap/plan9/close.c +++ b/sys/src/ape/lib/ap/plan9/close.c @@ -20,15 +20,15 @@ close(int d) _closebuf(d); f->flags &= ~FD_BUFFERED; } - n = _CLOSE(d); - if(n < 0) - _syserrno(); _fdinfo[d].flags = 0; _fdinfo[d].oflags = 0; if(_fdinfo[d].name){ free(_fdinfo[d].name); _fdinfo[d].name = 0; } + n = _CLOSE(d); + if(n < 0) + _syserrno(); } return n; } |