Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: fusl/src/process/system.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/process/sh/vfork.s ('k') | fusl/src/process/vfork.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <signal.h>
4 #include <sys/wait.h>
5 #include <spawn.h>
6 #include <errno.h>
7 #include "pthread_impl.h"
8 #include "libc.h"
9
10 extern char **__environ;
11
12 int system(const char *cmd)
13 {
14 pid_t pid;
15 sigset_t old, reset;
16 struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit;
17 int status = 0x7f00, ret;
18 posix_spawnattr_t attr;
19
20 pthread_testcancel();
21
22 if (!cmd) return 1;
23
24 sigaction(SIGINT, &sa, &oldint);
25 sigaction(SIGQUIT, &sa, &oldquit);
26 sigaddset(&sa.sa_mask, SIGCHLD);
27 sigprocmask(SIG_BLOCK, &sa.sa_mask, &old);
28
29 sigemptyset(&reset);
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_SETSIG MASK);
36 ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
37 (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
38 posix_spawnattr_destroy(&attr);
39
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);
44
45 if (ret) errno = ret;
46 return status;
47 }
OLDNEW
« no previous file with comments | « fusl/src/process/sh/vfork.s ('k') | fusl/src/process/vfork.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698