Make system() and popen() thread safe

This commit is contained in:
Justine Tunney 2022-10-13 15:38:31 -07:00
parent 997ce29ddc
commit f52f65b2e3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
19 changed files with 135 additions and 31 deletions

View file

@ -20,9 +20,12 @@
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/errno.h"
#include "libc/intrin/weaken.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/posix_spawn.h"
#include "libc/stdio/posix_spawn.internal.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
static int RunFileActions(struct _posix_faction *a) {
int t;
@ -68,7 +71,7 @@ int posix_spawn(int *pid, const char *path,
int s, child;
sigset_t allsigs;
struct sigaction dfl;
if (!(child = vfork())) {
if (!(child = _weaken(pthread_create) ? fork() : vfork())) {
if (attrp && *attrp) {
if ((*attrp)->flags & POSIX_SPAWN_SETPGROUP) {
if (setpgid(0, (*attrp)->pgroup)) _Exit(127);