7 #include "pthread_impl.h"
10 extern char **__environ;
12 int system(const char *cmd)
16 struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit;
18 posix_spawnattr_t attr;
24 sigaction(SIGINT, &sa, &oldint);
25 sigaction(SIGQUIT, &sa, &oldquit);
26 sigaddset(&sa.sa_mask, SIGCHLD);
27 sigprocmask(SIG_BLOCK, &sa.sa_mask, &old);
30 if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT);
31 if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT);
32 posix_spawnattr_init(&attr);
33 posix_spawnattr_setsigmask(&attr, &old);
34 posix_spawnattr_setsigdefault(&attr, &reset);
35 posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
36 ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
37 (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
38 posix_spawnattr_destroy(&attr);
40 if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR);
41 sigaction(SIGINT, &oldint, NULL);
42 sigaction(SIGQUIT, &oldquit, NULL);
43 sigprocmask(SIG_SETMASK, &old, NULL);