aboutsummaryrefslogtreecommitdiffstats
path: root/ports
diff options
context:
space:
mode:
authorPeter Seebach <peter.seebach@windriver.com>2011-06-02 01:47:26 -0500
committerPeter Seebach <peter.seebach@windriver.com>2011-06-02 01:47:26 -0500
commit89745dc43ba8779b92c5c8547652bdc923233b41 (patch)
tree1d965d0b2aae2316b72977eda918e56b6c6c5fd9 /ports
parent72f625baa51d5cf41c24d96586535f5720e240e4 (diff)
downloadpseudo-89745dc43ba8779b92c5c8547652bdc923233b41.tar.gz
pseudo-89745dc43ba8779b92c5c8547652bdc923233b41.tar.bz2
pseudo-89745dc43ba8779b92c5c8547652bdc923233b41.zip
Add system() wrapper to force setup of the pseudo environment. Note
that we add an extra fork() so we can do the setup in a child process, but still just pass the command string to the standard system() call.
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);