diff options
Diffstat (limited to 'libbb/xfuncs.c')
-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 | ||