[git commit] libbb: consolidate NOMMU fix of restoring high bit in argv[0][0]

Denys Vlasenko vda.linux at googlemail.com
Thu Apr 6 19:20:28 UTC 2023


commit: https://git.busybox.net/busybox/commit/?id=a26711a2d1464167be4ebc990fe21a3809a2da34
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
fork_or_rexec                                         46      56     +10
bootchartd_main                                     1087    1079      -8
cpio_main                                            674     661     -13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 10/-21)            Total: -11 bytes

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 archival/cpio.c            |  1 -
 include/libbb.h            |  2 +-
 init/bootchartd.c          |  2 --
 libbb/vfork_daemon_rexec.c | 10 ++++++----
 networking/httpd.c         |  2 +-
 5 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/archival/cpio.c b/archival/cpio.c
index 7149782d7..839a15621 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -504,7 +504,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
 			goto dump;
 		}
 		/* parent */
-		USE_FOR_NOMMU(argv[-optind][0] &= 0x7f); /* undo fork_or_rexec() damage */
 		xchdir(*argv++);
 		close(pp.wr);
 		xmove_fd(pp.rd, STDIN_FILENO);
diff --git a/include/libbb.h b/include/libbb.h
index cca33a177..6191debb1 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1319,7 +1319,7 @@ enum {
 # define bb_daemonize(flags)                bb_daemonize_or_rexec(flags, bogus)
 #else
   extern bool re_execed;
-  /* Note: re_exec() and fork_or_rexec() do argv[0][0] |= 0x80 on NOMMU!
+  /* Note: re_exec() sets argv[0][0] |= 0x80 on NOMMU!
    * _Parent_ needs to undo it if it doesn't want to have argv[0] mangled.
    */
   void re_exec(char **argv) NORETURN FAST_FUNC;
diff --git a/init/bootchartd.c b/init/bootchartd.c
index ae1ee9d9a..0929890a3 100644
--- a/init/bootchartd.c
+++ b/init/bootchartd.c
@@ -435,8 +435,6 @@ int bootchartd_main(int argc UNUSED_PARAM, char **argv)
 
 	/* parent */
 
-	USE_FOR_NOMMU(argv[0][0] &= 0x7f); /* undo fork_or_rexec() damage */
-
 	if (DO_SIGNAL_SYNC) {
 		/* Wait for logger child to set handlers, then unpause it.
 		 * Otherwise with short-lived PROG (e.g. "bootchartd start true")
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c
index 79141936a..a570ddbf2 100644
--- a/libbb/vfork_daemon_rexec.c
+++ b/libbb/vfork_daemon_rexec.c
@@ -268,10 +268,12 @@ pid_t FAST_FUNC fork_or_rexec(char **argv)
 	/* fflush_all(); ? - so far all callers had no buffered output to flush */
 
 	pid = xvfork();
-	if (pid) /* parent */
-		return pid;
-	/* child - re-exec ourself */
-	re_exec(argv);
+	if (pid == 0) /* child - re-exec ourself */
+		re_exec(argv); /* NORETURN */
+
+	/* parent */
+	argv[0][0] &= 0x7f; /* undo re_rexec() damage */
+	return pid;
 }
 #endif
 
diff --git a/networking/httpd.c b/networking/httpd.c
index 252ad6c2d..ddcb03bca 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -2713,8 +2713,8 @@ static void mini_httpd_nommu(int server_socket, int argc, char **argv)
 			/* Run a copy of ourself in inetd mode */
 			re_exec(argv_copy);
 		}
-		argv_copy[0][0] &= 0x7f;
 		/* parent, or vfork failed */
+		argv_copy[0][0] &= 0x7f; /* undo re_rexec() damage */
 		close(n);
 	} /* while (1) */
 	/* never reached */


More information about the busybox-cvs mailing list