diff options
author | Pascal Bellard <pascal.bellard@ads-lu.com> | 2010-07-04 15:32:38 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-07-04 15:32:38 +0200 |
commit | 926031b7640bf5aad2ffcd54b096911743a47d97 (patch) | |
tree | 093e0e1bab2c905a97c5880e4942e2000ada7e72 /include | |
parent | 243d1757d798a0cd43f51eb1db75cc1e81c65732 (diff) | |
download | busybox-926031b7640bf5aad2ffcd54b096911743a47d97.tar.gz |
*: introduce and use xfork() and xvfork()
function old new delta
launch_helper 170 169 -1
setup_heredoc 312 302 -10
handle_dir_common 367 354 -13
expand_vars_to_list 2456 2443 -13
open_transformer 89 74 -15
data_extract_to_command 439 423 -16
do_ipaddr 1406 1389 -17
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-85) Total: -85 bytes
Signed-off-by: Pascal Bellard <pascal.bellard@ads-lu.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/include/libbb.h b/include/libbb.h index 4b6699f2f..e2a8322b8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -841,6 +841,19 @@ int bb_execvp(const char *file, char *const argv[]) FAST_FUNC; #endif int BB_EXECVP_or_die(char **argv) NORETURN FAST_FUNC; +/* xvfork() can't be a _function_, return after vfork mangles stack + * in the parent. It must be a macro. */ +#define xvfork() \ +({ \ + pid_t bb__xvfork_pid = vfork(); \ + if (bb__xvfork_pid < 0) \ + bb_perror_msg_and_die("vfork"); \ + bb__xvfork_pid; \ +}) +#if BB_MMU +pid_t xfork(void) FAST_FUNC; +#endif + /* NOMMU friendy fork+exec: */ pid_t spawn(char **argv) FAST_FUNC; pid_t xspawn(char **argv) FAST_FUNC; @@ -886,7 +899,7 @@ int run_nofork_applet_prime(struct nofork_save_area *old, int applet_no, char ** * Both of the above will redirect fd 0,1,2 to /dev/null and drop ctty * (will do setsid()). * - * fork_or_rexec(argv) = bare-bones "fork" on MMU, + * fork_or_rexec(argv) = bare-bones fork on MMU, * "vfork + re-exec ourself" on NOMMU. No fd redirection, no setsid(). * On MMU ignores argv. * @@ -902,19 +915,19 @@ enum { DAEMON_ONLY_SANITIZE = 8, /* internal use */ }; #if BB_MMU - pid_t fork_or_rexec(void) FAST_FUNC; enum { re_execed = 0 }; -# define fork_or_rexec(argv) fork_or_rexec() +# define fork_or_rexec(argv) xfork() # define bb_daemonize_or_rexec(flags, argv) bb_daemonize_or_rexec(flags) # define bb_daemonize(flags) bb_daemonize_or_rexec(flags, bogus) #else + extern bool re_execed; void re_exec(char **argv) NORETURN FAST_FUNC; pid_t fork_or_rexec(char **argv) FAST_FUNC; - extern bool re_execed; int BUG_fork_is_unavailable_on_nommu(void) FAST_FUNC; int BUG_daemon_is_unavailable_on_nommu(void) FAST_FUNC; void BUG_bb_daemonize_is_unavailable_on_nommu(void) FAST_FUNC; # define fork() BUG_fork_is_unavailable_on_nommu() +# define xfork() BUG_fork_is_unavailable_on_nommu() # define daemon(a,b) BUG_daemon_is_unavailable_on_nommu() # define bb_daemonize(a) BUG_bb_daemonize_is_unavailable_on_nommu() #endif |