aboutsummaryrefslogtreecommitdiffstats
path: root/ports/unix/guts/system.c
blob: 99b27c0fa9d3e63caafb336717eb87ec50ffbbc1 (plain)
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
/*
 * Copyright (c) 2011 Wind River Systems; see
 * guts/COPYRIGHT for information.
 *
 * int system(const char *command)
 *	int rc = -1;
 */
 	/* We want to ensure that the child process implicitly
	 * spawned has the right environment.  So...
	 */
	int pid;

	if (!command)
		return 1;

	pid = wrap_fork();

	if (pid) {
		int status;
		waitpid(pid, &status, 0);
		if (WIFEXITED(status)) {
			rc = WEXITSTATUS(status);
		} else {
			/* we naively assume that either it exited or
			 * got killed by a signal...
			 */
			rc = WTERMSIG(status) + 128;
		}
	} else {
		/* this involves ANOTHER fork, but it's much, much,
		 * simpler than trying to get all the details right.
		 */
		rc = real_system(command);
		exit(rc);
	}

/*	return rc;
 * }
 */