summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRob Landley2006-05-25 23:02:40 +0000
committerRob Landley2006-05-25 23:02:40 +0000
commit399d2b5c24aaa059104a89058c7d4c8b97f41629 (patch)
tree1c6aed143c5dd2ff927190caf83b683c013028cb /libbb
parent69d863b6c609ac0523c546e408cc5d2063073425 (diff)
downloadbusybox-399d2b5c24aaa059104a89058c7d4c8b97f41629.zip
busybox-399d2b5c24aaa059104a89058c7d4c8b97f41629.tar.gz
Rich Felker suggested removing dprintf() from watch, and one thing led to
another... This adds bb_xspawn() support, which does vfork/exec. (I don't know why using a static instead of a local adds ~40 bytes, but using the local doesn't work...)
Diffstat (limited to 'libbb')
-rw-r--r--libbb/xfuncs.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index d3c9e41..2cfafb0 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