aboutsummaryrefslogtreecommitdiffstats
path: root/ports
diff options
context:
space:
mode:
Diffstat (limited to 'ports')
-rw-r--r--ports/unix/guts/system.c39
-rw-r--r--ports/unix/wrapfuncs.in1
2 files changed, 40 insertions, 0 deletions
diff --git a/ports/unix/guts/system.c b/ports/unix/guts/system.c
new file mode 100644
index 0000000..99b27c0
--- /dev/null
+++ b/ports/unix/guts/system.c
@@ -0,0 +1,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;
+ * }
+ */
diff --git a/ports/unix/wrapfuncs.in b/ports/unix/wrapfuncs.in
index b0fdb2c..74bad89 100644
--- a/ports/unix/wrapfuncs.in
+++ b/ports/unix/wrapfuncs.in
@@ -54,3 +54,4 @@ int unlinkat(int dirfd, const char *path, int rflags); /* flags=AT_SYMLINK_NOFOL
# primarily for use with chroot()
ssize_t readlink(const char *path, char *buf, size_t bufsiz); /* flags=AT_SYMLINK_NOFOLLOW */
ssize_t readlinkat(int dirfd, const char *path, char *buf, size_t bufsiz); /* flags=AT_SYMLINK_NOFOLLOW */
+int system(const char *command);