logo       

Re: 1.00-pre1 problem: can't umount oldroot after pivot_root&chroot: msg#00223

linux.busybox

Subject: Re: 1.00-pre1 problem: can't umount oldroot after pivot_root&chroot

Yang Xiaopeng wrote:

Old /proc is unmounted when init restart, before executing my scripts,
all user processes are also killed in that step. When my scripts run,
proc filesystem is remounted to /tmp/proc before pivot_root&chroot to /tmp.
after chroot, its real mount point should be /proc in the new root.

Here is the output of `mount` just after pivot_root&chroot to /tmp:

/dev/root on /old_root type cramfs (rw)
none on / type tmpfs (rw)
none on /proc type proc (rw)

and the `ps` output:

PID Uid VmSize Stat Command
1 root 616 S /bin/sh sbin/flash.sh
2 root SW [keventd]
3 root SWN [ksoftirqd_CPU0]
4 root SW [kswapd]
5 root SW [bdflush]
6 root SW [kupdated]
7 root SW [keyd]
8 root RW [ledtimed]
9 root SW [mtdblockd]
10 root Z [khubd]
181 root 676 R ps

I'm sure that no user process use old root now, but when run "umount /old_root", it says:
umount: /old_root: Device or resource busy

I have tried to remount /proc within the new root *after* chroot, but get the same result.


I found the problem, I said that no user process use old root when run my scripts, but
I'm wrong, actually there is a '3' fd open the file "/old_root/dev/console". By adding
debug message in init/init.c, I found the problem: when init restart(in exec_signal()),
before open the new terminal device, there is still a file opened(I don't know which file it is), so the
terminal device(stdin) get fd '1', and the first dup(0)(stdout) return '2', the second(stderr) return '3'.

I attach a simple patch to solve this problem.

diff -urN busybox-1.00-pre1/init/init.c busybox-1.00/init/init.c
--- busybox-1.00-pre1/init/init.c 2003-07-15 05:20:53.000000000 +0800
+++ busybox-1.00/init/init.c 2003-07-29 09:55:07.000000000 +0800
@@ -741,6 +741,11 @@
sigaddset(&unblock_signals, SIGTSTP);
sigprocmask(SIG_UNBLOCK, &unblock_signals, NULL);

+ /* Close whatever files are open. */
+ close(0);
+ close(1);
+ close(2);
+
/* Open the new terminal device */
if ((device_open(a->terminal, O_RDWR)) < 0) {
if (stat(a->terminal, &sb) != 0) {
_______________________________________________
busybox mailing list
busybox@xxxxxxxxxxxxxxxx
http://codepoet.org/mailman/listinfo/busybox
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise