aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r--libbb/xfuncs.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index d3c9e41e1..2cfafb01a 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -182,3 +182,37 @@ void bb_xfflush_stdout(void)
}
}
#endif
+
+#ifdef L_spawn
+// This does a fork/exec in one call, using vfork().
+pid_t bb_spawn(char **argv)
+{
+ static int failed;
+ pid_t pid;
+
+ // Be nice to nommu machines.
+ failed = 0;
+ pid = vfork();
+ if (pid < 0) return pid;
+ if (!pid) {
+ execvp(*argv, argv);
+
+ // We're sharing a stack with blocked parent, let parent know we failed
+ // and then exit to unblock parent (but don't run atexit() stuff, which
+ // would screw up parent.)
+
+ failed = -1;
+ _exit(0);
+ }
+ return failed ? failed : pid;
+}
+#endif
+
+#ifdef L_xspawn
+pid_t bb_xspawn(char **argv)
+{
+ pid_t pid = bb_spawn(argv);
+ if (pid < 0) bb_perror_msg_and_die("%s", *argv);
+ return pid;
+}
+#endif