7 #include "pthread_impl.h"
13 weak_alias(dummy_0, __acquire_ptc);
14 weak_alias(dummy_0, __release_ptc);
16 extern char **__environ;
18 int system(const char *cmd)
22 struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit;
23 int status = 0x7f00, ret;
24 posix_spawnattr_t attr;
30 sigaction(SIGINT, &sa, &oldint);
31 sigaction(SIGQUIT, &sa, &oldquit);
32 sigaddset(&sa.sa_mask, SIGCHLD);
33 sigprocmask(SIG_BLOCK, &sa.sa_mask, &old);
36 if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT);
37 if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT);
38 posix_spawnattr_init(&attr);
39 posix_spawnattr_setsigmask(&attr, &old);
40 posix_spawnattr_setsigdefault(&attr, &reset);
41 posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
42 ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
43 (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
44 posix_spawnattr_destroy(&attr);
46 if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR);
47 sigaction(SIGINT, &oldint, NULL);
48 sigaction(SIGQUIT, &oldquit, NULL);
49 sigprocmask(SIG_SETMASK, &old, NULL);