mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 03:38:31 +00:00
Fix ZipOS deadlock/segfault (#1011)
This change adds a new stress test for ZipOS which helped us improve the locking semantics in open() and close().
This commit is contained in:
parent
897fa6ac00
commit
8a10ccf9c4
4 changed files with 76 additions and 6 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/calls/struct/fd.internal.h"
|
||||
#include "libc/calls/struct/sigset.internal.h"
|
||||
#include "libc/calls/syscall-nt.internal.h"
|
||||
#include "libc/calls/syscall-sysv.internal.h"
|
||||
#include "libc/dce.h"
|
||||
|
@ -91,8 +92,18 @@ static int close_impl(int fd) {
|
|||
* @vforksafe
|
||||
*/
|
||||
int close(int fd) {
|
||||
int rc = close_impl(fd);
|
||||
if (!__vforked) __releasefd(fd);
|
||||
int rc;
|
||||
if (__isfdkind(fd, kFdZip)) { // XXX IsWindows()?
|
||||
BLOCK_SIGNALS;
|
||||
__fds_lock();
|
||||
rc = close_impl(fd);
|
||||
if (!__vforked) __releasefd(fd);
|
||||
__fds_unlock();
|
||||
ALLOW_SIGNALS;
|
||||
} else {
|
||||
rc = close_impl(fd);
|
||||
if (!__vforked) __releasefd(fd);
|
||||
}
|
||||
STRACE("close(%d) → %d% m", fd, rc);
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue