svn commit: trunk/busybox: archival archival/libunarchive debianuti etc...

vda at busybox.net vda at busybox.net
Tue Jul 1 15:59:43 UTC 2008


Author: vda
Date: 2008-07-01 08:59:42 -0700 (Tue, 01 Jul 2008)
New Revision: 22594

Log:
revert last two commits. vfork cannot be used in subroutine,
it trashes stack on return



Removed:
   trunk/busybox/libbb/xvfork.c

Modified:
   trunk/busybox/archival/libunarchive/open_transformer.c
   trunk/busybox/archival/tar.c
   trunk/busybox/debianutils/start_stop_daemon.c
   trunk/busybox/include/libbb.h
   trunk/busybox/libbb/Kbuild
   trunk/busybox/libbb/vfork_daemon_rexec.c
   trunk/busybox/miscutils/crontab.c
   trunk/busybox/miscutils/time.c
   trunk/busybox/networking/ifupdown.c
   trunk/busybox/networking/inetd.c
   trunk/busybox/networking/sendmail.c
   trunk/busybox/shell/hush.c
   trunk/busybox/util-linux/mount.c
   trunk/busybox/util-linux/script.c


Changeset:
Modified: trunk/busybox/archival/libunarchive/open_transformer.c
===================================================================
--- trunk/busybox/archival/libunarchive/open_transformer.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/archival/libunarchive/open_transformer.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -20,7 +20,16 @@
 
 	xpiped_pair(fd_pipe);
 
-	pid = BB_MMU ? xfork() : xvfork();
+#if BB_MMU
+	pid = fork();
+	if (pid == -1)
+		bb_perror_msg_and_die("can't fork");
+#else
+	pid = vfork();
+	if (pid == -1)
+		bb_perror_msg_and_die("can't vfork");
+#endif
+
 	if (pid == 0) {
 		/* child process */
 		close(fd_pipe.rd); /* We don't want to read from the parent */

Modified: trunk/busybox/archival/tar.c
===================================================================
--- trunk/busybox/archival/tar.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/archival/tar.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -536,7 +536,9 @@
 	(void) &zip_exec;
 #endif
 
-	gzipPid = xvfork();
+	gzipPid = vfork();
+	if (gzipPid < 0)
+		bb_perror_msg_and_die("can't vfork");
 
 	if (gzipPid == 0) {
 		/* child */

Modified: trunk/busybox/debianutils/start_stop_daemon.c
===================================================================
--- trunk/busybox/debianutils/start_stop_daemon.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/debianutils/start_stop_daemon.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -404,7 +404,9 @@
 		/* DAEMON_DEVNULL_STDIO is superfluous -
 		 * it's always done by bb_daemonize() */
 #else
-		pid_t pid = xvfork();
+		pid_t pid = vfork();
+		if (pid < 0) /* error */
+			bb_perror_msg_and_die("vfork");
 		if (pid != 0) {
 			/* parent */
 			/* why _exit? the child may have changed the stack,

Modified: trunk/busybox/include/libbb.h
===================================================================
--- trunk/busybox/include/libbb.h	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/include/libbb.h	2008-07-01 15:59:42 UTC (rev 22594)
@@ -719,11 +719,6 @@
 #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 */
 pid_t spawn(char **argv) FAST_FUNC;
 pid_t xspawn(char **argv) FAST_FUNC;

Modified: trunk/busybox/libbb/Kbuild
===================================================================
--- trunk/busybox/libbb/Kbuild	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/libbb/Kbuild	2008-07-01 15:59:42 UTC (rev 22594)
@@ -109,7 +109,6 @@
 lib-y += xgetcwd.o
 lib-y += xgethostbyname.o
 lib-y += xreadlink.o
-lib-y += xvfork.o
 
 # conditionally compiled objects:
 lib-$(CONFIG_FEATURE_MOUNT_LOOP) += loop.o

Modified: trunk/busybox/libbb/vfork_daemon_rexec.c
===================================================================
--- trunk/busybox/libbb/vfork_daemon_rexec.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/libbb/vfork_daemon_rexec.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -226,7 +226,9 @@
 	if (re_execed)
 		return;
 
-	pid = xvfork();
+	pid = vfork();
+	if (pid < 0) /* wtf? */
+		bb_perror_msg_and_die("vfork");
 	if (pid) /* parent */
 		exit(EXIT_SUCCESS);
 	/* child - re-exec ourself */
@@ -238,7 +240,9 @@
 void FAST_FUNC forkexit_or_rexec(void)
 {
 	pid_t pid;
-	pid = xfork();
+	pid = fork();
+	if (pid < 0) /* wtf? */
+		bb_perror_msg_and_die("fork");
 	if (pid) /* parent */
 		exit(EXIT_SUCCESS);
 	/* child */

Deleted: trunk/busybox/libbb/xvfork.c
===================================================================
--- trunk/busybox/libbb/xvfork.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/libbb/xvfork.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -1,28 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 2007 Denys Vlasenko
- *
- * Licensed under GPL version 2, see file LICENSE in this tarball for details.
- */
-
-#include "libbb.h"
-
-pid_t FAST_FUNC xvfork(void)
-{
-	pid_t pid = vfork();
-	if (pid < 0)
-		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

Modified: trunk/busybox/miscutils/crontab.c
===================================================================
--- trunk/busybox/miscutils/crontab.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/miscutils/crontab.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -38,8 +38,10 @@
 static void edit_file(const struct passwd *pas, const char *file)
 {
 	const char *ptr;
-	int pid = xvfork();
+	int pid = vfork();
 
+	if (pid < 0) /* failure */
+		bb_perror_msg_and_die("vfork");
 	if (pid) { /* parent */
 		wait4pid(pid);
 		return;
@@ -63,7 +65,9 @@
 	pid_t pid;
 	char c;
 
-	pid = xvfork();
+	pid = vfork();
+	if (pid < 0) /* ERROR */
+		bb_perror_msg_and_die("vfork");
 	if (pid) { /* PARENT */
 		if (wait4pid(pid) == 0) {
 			/* exitcode 0: child says it can read */

Modified: trunk/busybox/miscutils/time.c
===================================================================
--- trunk/busybox/miscutils/time.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/miscutils/time.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -372,7 +372,9 @@
 	void (*quit_signal)(int);
 
 	resp->elapsed_ms = monotonic_us() / 1000;
-	pid = xvfork();		/* Run CMD as child process.  */
+	pid = vfork();		/* Run CMD as child process.  */
+	if (pid < 0)
+		bb_error_msg_and_die("cannot fork");
 	if (pid == 0) {	/* If child.  */
 		/* Don't cast execvp arguments; that causes errors on some systems,
 		   versus merely warnings if the cast is left off.  */

Modified: trunk/busybox/networking/ifupdown.c
===================================================================
--- trunk/busybox/networking/ifupdown.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/networking/ifupdown.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -1008,9 +1008,12 @@
 	xpiped_pair(outfd);
 
 	fflush(NULL);
-	pid = xvfork();
+	pid = vfork();
 
-	if (pid == 0) { /* child */
+	switch (pid) {
+	case -1:  /* failure */
+		bb_perror_msg_and_die("vfork");
+	case 0:  /* child */
 		/* NB: close _first_, then move fds! */
 		close(infd.wr);
 		close(outfd.rd);

Modified: trunk/busybox/networking/inetd.c
===================================================================
--- trunk/busybox/networking/inetd.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/networking/inetd.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -1303,7 +1303,7 @@
 					pid = vfork();
 
 				if (pid < 0) { /* fork error */
-					bb_perror_msg(BB_MMU ? "vfork" + 1 : "vfork");
+					bb_perror_msg("fork");
 					sleep(1);
 					restore_sigmask(&omask);
 					maybe_close(accepted_fd);

Modified: trunk/busybox/networking/sendmail.c
===================================================================
--- trunk/busybox/networking/sendmail.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/networking/sendmail.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -120,6 +120,15 @@
 #undef err
 }
 
+/* libbb candidate */
+static pid_t vfork_or_die(void)
+{
+	pid_t pid = vfork();
+	if (pid < 0)
+		bb_perror_msg_and_die("vfork");
+	return pid;
+}
+
 static void launch_helper(const char **argv)
 {
 	// setup vanilla unidirectional pipes interchange
@@ -128,7 +137,7 @@
 
 	xpipe(pipes);
 	xpipe(pipes+2);
-	helper_pid = xvfork();
+	helper_pid = vfork_or_die();
 	idx = (!helper_pid) * 2;
 	xdup2(pipes[idx], STDIN_FILENO);
 	xdup2(pipes[3-idx], STDOUT_FILENO);

Modified: trunk/busybox/shell/hush.c
===================================================================
--- trunk/busybox/shell/hush.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/shell/hush.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -1902,7 +1902,7 @@
 #endif
 		if (child->pid < 0) { /* [v]fork failed */
 			/* Clearly indicate, was it fork or vfork */
-			bb_perror_msg(BB_MMU ? "vfork" + 1 : "vfork");
+			bb_perror_msg(BB_MMU ? "fork" : "vfork");
 		} else {
 			pi->alive_progs++;
 #if ENABLE_HUSH_JOB
@@ -3096,7 +3096,9 @@
  * huge=`cat TESTFILE` # will block here forever
  * echo OK
  */
-	pid = BB_MMU ? xfork() : xvfork();
+	pid = BB_MMU ? fork() : vfork();
+	if (pid < 0)
+		bb_perror_msg_and_die(BB_MMU ? "fork" : "vfork");
 	if (pid == 0) { /* child */
 		if (ENABLE_HUSH_JOB)
 			die_sleep = 0; /* let nofork's xfuncs die */

Modified: trunk/busybox/util-linux/mount.c
===================================================================
--- trunk/busybox/util-linux/mount.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/util-linux/mount.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -890,7 +890,6 @@
 }
 
 #if BB_MMU
-/* Unlike bb_daemonize(), parent does NOT exit here, but returns 0 */
 static int daemonize(void)
 {
 	int fd;

Modified: trunk/busybox/util-linux/script.c
===================================================================
--- trunk/busybox/util-linux/script.c	2008-07-01 14:04:55 UTC (rev 22593)
+++ trunk/busybox/util-linux/script.c	2008-07-01 15:59:42 UTC (rev 22594)
@@ -87,7 +87,10 @@
 
 	/* TODO: SIGWINCH? pass window size changes down to slave? */
 
-	child_pid = xvfork();
+	child_pid = vfork();
+	if (child_pid < 0) {
+		bb_perror_msg_and_die("vfork");
+	}
 
 	if (child_pid) {
 		/* parent */




More information about the busybox-cvs mailing list