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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/process/system.c
diff --git a/fusl/src/process/system.c b/fusl/src/process/system.c
new file mode 100644
index 0000000000000000000000000000000000000000..8cbdda060d0275c7fd6480b2be676b7c25945d3e
--- /dev/null
+++ b/fusl/src/process/system.c
@@ -0,0 +1,47 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <spawn.h>
+#include <errno.h>
+#include "pthread_impl.h"
+#include "libc.h"
+
+extern char **__environ;
+
+int system(const char *cmd)
+{
+ pid_t pid;
+ sigset_t old, reset;
+ struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit;
+ int status = 0x7f00, ret;
+ posix_spawnattr_t attr;
+
+ pthread_testcancel();
+
+ if (!cmd) return 1;
+
+ sigaction(SIGINT, &sa, &oldint);
+ sigaction(SIGQUIT, &sa, &oldquit);
+ sigaddset(&sa.sa_mask, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &sa.sa_mask, &old);
+
+ sigemptyset(&reset);
+ if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT);
+ if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT);
+ posix_spawnattr_init(&attr);
+ posix_spawnattr_setsigmask(&attr, &old);
+ posix_spawnattr_setsigdefault(&attr, &reset);
+ posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
+ ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
+ (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
+ posix_spawnattr_destroy(&attr);
+
+ if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR);
+ sigaction(SIGINT, &oldint, NULL);
+ sigaction(SIGQUIT, &oldquit, NULL);
+ sigprocmask(SIG_SETMASK, &old, NULL);
+
+ if (ret) errno = ret;
+ return status;
+}
« 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