diff options
author | Rob Landley <rob@landley.net> | 2006-05-25 23:02:40 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-05-25 23:02:40 +0000 |
commit | 399d2b5c24aaa059104a89058c7d4c8b97f41629 (patch) | |
tree | 1c6aed143c5dd2ff927190caf83b683c013028cb /libbb | |
parent | 69d863b6c609ac0523c546e408cc5d2063073425 (diff) | |
download | busybox-w32-399d2b5c24aaa059104a89058c7d4c8b97f41629.tar.gz busybox-w32-399d2b5c24aaa059104a89058c7d4c8b97f41629.tar.bz2 busybox-w32-399d2b5c24aaa059104a89058c7d4c8b97f41629.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...)
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/xfuncs.c | 34 |
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(). | ||
188 | pid_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 | ||
212 | pid_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 | ||