[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: init/umount problem persists



Hi.

In <[🔎] 20000205225236.C21819@xmission.com>,
 at Date: Sat, 5 Feb 2000 22:52:36 -0700,
  on Subject: Re: init/umount problem persists,
   Erik Andersen <andersen@xmission.com> writes:

> [-----patch replacing waitfor() with system() snipped-------]
> 
> I don't understand this change.  Have you tested it?
> Does it help?  If so, I do not understand how or why. 

Yes, I have tested it several times, and after this modification,
the mounted /target filesystem seems to be umounted safely.

I checked this by:

1) Boot up using vanilla resc1440 and root1440

2) Go to 2nd console, check a partition in the harddisk, 
   and make sure that it is clean.

2) Mount the checked partition under /target.

3) Do "reboot" command, watching the message.

4) Reboot with the same boot-floppies.

5) Go to 2nd console, check the partition which is mounted
   before doing "reboot" command in previous cycle.

When using "waitfor()", e2fsck always warn that partition is
not cleanly umounted. Using "system" make that partition umounted
cleanly, and e2fsck said that partition is clean.

> Furthermore, running system(3) is invoking /bin/sh and 
> so it has a much higher cost then using init's run() 
> function.

I had checked init.c, and after reading your mail, I did check again
for hours, but using system() is the only solution I found.

I found that the argument for "waitfor" is not the full-path, and then
I thought that was the cause of the problem (because execve() requires
the full-path of executable), but the following diff does not work
the problem of "umount -a".

--- ../../../../../cvs/boot-floppies/utilities/busybox/init.c   Sun Feb  6 19:27:25 2000
+++ ./init.c    Sun Feb  6 20:46:43 2000
@@ -480,9 +480,9 @@
     sleep(5);
 
     message(CONSOLE, "Disabling swap.\r\n");
-       waitfor( "swapoff -a", console, FALSE);
+       waitfor( "/sbin/swapoff -a", console, FALSE);
     message(CONSOLE, "Unmounting filesystems.\r\n");
-       waitfor("umount -a -r", console, FALSE);
+       waitfor("/bin/umount -a -r", console, FALSE);
     sync();
     if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
        /* bdflush, kupdate not needed for kernels >2.2.11 */


Then I tried the possibility of the problem realted "wait()", and
I add waitforsingle() and runsingle() using the following the patch,
and that does not work.

--- ../../../../../cvs/boot-floppies/utilities/busybox/init.c	Sun Feb  6 19:27:25 2000
+++ ./init.c	Sun Feb  6 22:28:22 2000
@@ -435,6 +435,66 @@
     return wpid;
 }
 
+static pid_t runsingle(char* command) 
+{
+    int i;
+    pid_t pid;
+    char* tmpCmd;
+    char* cmd[255];
+    char* environment[] = {
+	"HOME=/",
+	"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
+	"SHELL=/bin/sh",
+	"USER=root",
+	0
+    };
+
+    if ((pid = fork()) == 0) {
+
+
+	signal(SIGINT, SIG_IGN);
+	signal(SIGQUIT, SIG_IGN);
+	signal(SIGTERM, SIG_IGN);
+
+	/* Convert command (char*) into cmd (char**, one word per string) */
+	for (tmpCmd=command, i=0;
+	       (tmpCmd=strsep(&command, " \t")) != NULL; i++) {
+	    if (*tmpCmd != '\0') {
+		  cmd[i] = tmpCmd;
+	    } else {
+		break;
+	    }
+	}
+	cmd[i] = NULL;
+
+	/* Now run it.  The new program will take over this PID, 
+	 * so nothing further in init.c should be run. */
+	execve(cmd[0], cmd, environment);
+
+	exit(-1);
+    }
+    return pid;
+}
+
+static int waitforsingle(char* command) 
+{
+    int status;
+    pid_t pid, wpid;
+
+    signal(SIGCHLD, SIG_IGN);
+    pid = runsingle( command );
+    sleep(1);
+
+    if (pid == -1) {
+	message(CONSOLE, "runsingle() failed!!!\r\n");
+	sleep(5);
+	return(-1);
+    } else {
+        wpid = waitpid(pid, &status, 0);
+        return status;
+    }
+}
+
 /* Make sure there is enough memory to do something useful. *
  * Calls swapon if needed so be sure /proc is mounted. */
 static void check_memory()
@@ -480,9 +540,27 @@
     sleep(5);
 
     message(CONSOLE, "Disabling swap.\r\n");
-	waitfor( "swapoff -a", console, FALSE);
+/*    waitfor("/sbin/swapoff -a", console, FALSE); */
+/*    system("/sbin/swapoff -a"); */
+    if (waitforsingle("/sbin/swapoff -a") == -1) {
+	message(CONSOLE, "waitforsingle() failed!!!\r\n");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..\r\n");
+    }
     message(CONSOLE, "Unmounting filesystems.\r\n");
-	waitfor("umount -a -r", console, FALSE);
+/*    waitfor("/bin/umount -a -r", console, FALSE); */
+/*    system("/bin/umount -a -r"); */
+    if (waitforsingle("/bin/umount -a -r") == -1) {
+	message(CONSOLE, "waitforsingle() failed!!!\r\n");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..");
+        message(CONSOLE, "..\r\n");
+    }
     sync();
     if (kernelVersion > 0 && kernelVersion <= 2 * 65536 + 2 * 256 + 11) {
 	/* bdflush, kupdate not needed for kernels >2.2.11 */
@@ -513,12 +591,22 @@
 
 static void reboot_signal(int sig)
 {
+    int left_t;
     shutdown_system();
     message(CONSOLE, "Please stand by while rebooting the system.\r\n");
     sync();
 
     /* allow time for last message to reach serial console */
-    sleep(2);
+    left_t = sleep(30);
+    message(CONSOLE, "Left time on previous sleep %d.\r\n", left_t);
+    message(CONSOLE, "..");
+    message(CONSOLE, "..");
+    message(CONSOLE, "..");
+    message(CONSOLE, "..");
+    message(CONSOLE, "..");
+    message(CONSOLE, "..");
+    message(CONSOLE, "..");
+    message(CONSOLE, "..\r\n");
 
     reboot(RB_AUTOBOOT);
     exit(0);


Again, I have not found any other solution, and using "system()"
do work for me. 

Please check it by yourself, and please find more smart solution.
I can't do that anymore, being worn out.

P.S.
You'd better check the usage of "waitfor()" in check_memory() in init.c
The swapon command is under /sbin in boot-floppies, and does not accept
"swapon" as an argument. Possibly the failure on "swapon -a" at that
timing does not harm on the boot-floppies, because dbootstrap takes the
care of swap. But that line is confusing...

-- 
  Taketoshi Sano: <sano@debian.org>,<sano@debian.or.jp>,<kgh12351@nifty.ne.jp>


Reply to: