[PATCH] root-hopping for pre-2.3.41-3

H. Peter Anvin hpa en transmeta.com
Mar Ene 25 22:39:54 CST 2000


Followup to:  <20000126011602.A1070 en win.tue.nl>
By author:    Guest section DW <dwguest en win.tue.nl>
In newsgroup: linux.dev.kernel
> 
> and Peter answered
> 
> > > Right... everyone on the old / move to the new /, although I guess
> > > that's technically not 100% necessary.
> 
> but I wonder.
> Usually in such a situation not many processes will be around, but still..
> It would be strange if the interpretation of paths suddenly changed for
> processes other than the one doing this pivot_root.
> So, I would prefer these old processes all to remain where they are,
> with the same root inode (that just got a new name, namely /old_root).
> 
> Thus, the only process that would get the new / as root would be the
> process doing this pivot_root() (and perhaps init?).
> 

I think this really is the right solution... usually the process doing
this will *be* init.  There are other things that need to be done,
too, like replacing the console fd's after the remount (otherwise you
will hold initrd busy by virtue of having /dev/console open.)

I therefore conclude that doing automatic stuff is pointless and
probably harmful.  The recommended sequence for root-switching will
then look something like (error checking omitted):

	chdir("/oldroot");
	pivot_root("/newroot", "/oldroot");
	chroot(".");
	new_console = open("/dev/console", O_RDWR);
	dup2(new_console, 0);
	dup2(new_console, 1);
	dup2(new_console, 2);
	close(new_console);

	execl("/sbin/init", "init", 0);
-- 
<hpa en transmeta.com> at work, <hpa en zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo en vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



Más información sobre la lista de distribución Ayuda