aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-05-25 23:02:40 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-05-25 23:02:40 +0000
commit0cfff9dcd4a6942c27318a9d113d36d10f82ddbd (patch)
tree1c6aed143c5dd2ff927190caf83b683c013028cb /libbb
parent671d226813a9d1653505485466084f0f6b1126e6 (diff)
downloadbusybox-w32-0cfff9dcd4a6942c27318a9d113d36d10f82ddbd.tar.gz
busybox-w32-0cfff9dcd4a6942c27318a9d113d36d10f82ddbd.tar.bz2
busybox-w32-0cfff9dcd4a6942c27318a9d113d36d10f82ddbd.zip
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...) git-svn-id: svn://busybox.net/trunk/busybox@15172 69ca8d6d-28ef-0310-b511-8ec308f3f277
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 d3c9e41e1..2cfafb01a 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -182,3 +182,37 @@ void bb_xfflush_stdout(void)
182 } 182 }
183} 183}
184#endif 184#endif
185
186#ifdef L_spawn
187// This does a fork/exec in one call, using vfork().
188pid_t bb_spawn(char **argv)
189{
190 static int failed;
191 pid_t pid;
192
193 // Be nice to nommu machines.
194 failed = 0;
195 pid = vfork();
196 if (pid < 0) return pid;
197 if (!pid) {
198 execvp(*argv, argv);
199
200 // We're sharing a stack with blocked parent, let parent know we failed
201 // and then exit to unblock parent (but don't run atexit() stuff, which
202 // would screw up parent.)
203
204 failed = -1;
205 _exit(0);
206 }
207 return failed ? failed : pid;
208}
209#endif
210
211#ifdef L_xspawn
212pid_t bb_xspawn(char **argv)
213{
214 pid_t pid = bb_spawn(argv);
215 if (pid < 0) bb_perror_msg_and_die("%s", *argv);
216 return pid;
217}
218#endif