*: introduce and use xfork()
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 1 Jul 2008 11:11:24 +0000 (11:11 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 1 Jul 2008 11:11:24 +0000 (11:11 -0000)
function                                             old     new   delta
xfork                                                  -      20     +20
msh_main                                            1377    1380      +3
mod_process                                          455     446      -9
forkexit_or_rexec                                     30      17     -13
expand_variables                                    1434    1421     -13
open_transformer                                      91      76     -15
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/4 up/down: 23/-50)            Total: -27 bytes

archival/libunarchive/open_transformer.c
include/libbb.h
libbb/vfork_daemon_rexec.c
libbb/xvfork.c
networking/inetd.c
shell/hush.c
util-linux/mount.c

index 16ca6a59c2a5092cf2d7afa41ed350da42bcabc8..0738e3db18b5c167142441b612419320b7a0ecbf 100644 (file)
@@ -20,14 +20,7 @@ int FAST_FUNC open_transformer(int src_fd,
 
        xpiped_pair(fd_pipe);
 
-#if BB_MMU
-       pid = fork();
-       if (pid == -1)
-               bb_perror_msg_and_die("can't fork");
-#else
-       pid = xvfork();
-#endif
-
+       pid = BB_MMU ? xfork() : xvfork();
        if (pid == 0) {
                /* child process */
                close(fd_pipe.rd); /* We don't want to read from the parent */
index 33e465cf4d53b5b7ede05cd068d2f7f90ad378cf..67eef6dbb61b3c44cd444b1e46977197dc86a043 100644 (file)
@@ -719,6 +719,9 @@ int bb_execvp(const char *file, char *const argv[]) FAST_FUNC;
 #define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__)
 #endif
 
+#if BB_MMU
+pid_t xfork(void) FAST_FUNC;
+#endif
 pid_t xvfork(void) FAST_FUNC;
 
 /* NOMMU friendy fork+exec */
index 9baa813a118a2293d9b2a8e03110346168f67bf8..989e9b8415729dfebec9531aa9ed67494703d9c8 100644 (file)
@@ -238,9 +238,7 @@ void FAST_FUNC forkexit_or_rexec(char **argv)
 void FAST_FUNC forkexit_or_rexec(void)
 {
        pid_t pid;
-       pid = fork();
-       if (pid < 0) /* wtf? */
-               bb_perror_msg_and_die("fork");
+       pid = xfork();
        if (pid) /* parent */
                exit(EXIT_SUCCESS);
        /* child */
index a74b49f48a70cdb6b7d91025626ce3bcc463524c..3fbd0c1ed0de52820b772005f03d8a964776742d 100644 (file)
@@ -16,3 +16,13 @@ pid_t FAST_FUNC xvfork(void)
                bb_perror_msg_and_die("vfork");
        return pid;
 }
+
+#if BB_MMU
+pid_t FAST_FUNC xfork(void)
+{
+       pid_t pid = fork();
+       if (pid < 0)
+               bb_perror_msg_and_die("vfork" + 1);
+       return pid;
+}
+#endif
index 08c09953bd39da3ff4f4f34230d2c748c81c3331..0028078db7f2636cd488c338fa672a0b86a8fe5d 100644 (file)
@@ -1303,7 +1303,7 @@ int inetd_main(int argc ATTRIBUTE_UNUSED, char **argv)
                                        pid = vfork();
 
                                if (pid < 0) { /* fork error */
-                                       bb_perror_msg("fork");
+                                       bb_perror_msg(BB_MMU ? "vfork" + 1 : "vfork");
                                        sleep(1);
                                        restore_sigmask(&omask);
                                        maybe_close(accepted_fd);
index 59d8f3f990135745c1fd11529a76276cae1c65ac..27fab0d1b04a3b6dbb3813fe28a658634fe3bdb8 100644 (file)
@@ -1902,7 +1902,7 @@ static int run_pipe(struct pipe *pi)
 #endif
                if (child->pid < 0) { /* [v]fork failed */
                        /* Clearly indicate, was it fork or vfork */
-                       bb_perror_msg(BB_MMU ? "fork" : "vfork");
+                       bb_perror_msg(BB_MMU ? "vfork" + 1 : "vfork");
                } else {
                        pi->alive_progs++;
 #if ENABLE_HUSH_JOB
@@ -3096,11 +3096,7 @@ static FILE *generate_stream_from_list(struct pipe *head)
  * huge=`cat TESTFILE` # will block here forever
  * echo OK
  */
-       pid = BB_MMU ? fork() : xvfork();
-#if BB_MMU
-       if (pid < 0)
-               bb_perror_msg_and_die("fork");
-#endif
+       pid = BB_MMU ? xfork() : xvfork();
        if (pid == 0) { /* child */
                if (ENABLE_HUSH_JOB)
                        die_sleep = 0; /* let nofork's xfuncs die */
index 3b77af728ec6b6983ab9d8f9af445693d3f7a93f..664d24fd8c334eab40a88dce12325ea5c0bad9ff 100644 (file)
@@ -890,6 +890,7 @@ get_mountport(struct pmap *pm_mnt,
 }
 
 #if BB_MMU
+/* Unlike bb_daemonize(), parent does NOT exit here, but returns 0 */
 static int daemonize(void)
 {
        int fd;