mailing list of musl libc
 help / color / mirror / code / Atom feed
6946b350dd66293b5a5f78ddf260aece7282176e blob 1380 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
 
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/wait.h>
#include <spawn.h>
#include <errno.h>
#include "pthread_impl.h"
#include "libc.h"

WEAK_PROVIDE_VOID;
weak_alias(__weak_dummy_void, __acquire_ptc);
weak_alias(__weak_dummy_void, __release_ptc);

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;
}
debug log:

solving 6946b35 ...
found 6946b35 in https://inbox.vuxu.org/musl/fef8bbf759787cabc4ffd61c4e3357bc11112f8b.1360968989.git.Jens.Gustedt@inria.fr/
found 4232bef in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 4232bef0f4633fb0193ea231527665a8197a0acc	src/process/system.c

applying [1/1] https://inbox.vuxu.org/musl/fef8bbf759787cabc4ffd61c4e3357bc11112f8b.1360968989.git.Jens.Gustedt@inria.fr/
diff --git a/src/process/system.c b/src/process/system.c
index 4232bef..6946b35 100644

Checking patch src/process/system.c...
Applied patch src/process/system.c cleanly.

index at:
100644 6946b350dd66293b5a5f78ddf260aece7282176e	src/process/system.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).