From: Eric Hodel Date: 2004-01-03T22:38:38-08:00 Subject: Re: successive chroots thanks to continuations? --apg+fY3UKMMABzWO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Bauduin Raphael (rb@raphinou.com) wrote: > Hi again, >=20 > I have defined several chrooted environments on my computer. > I'd like to issue the same command(s) in each of them. In a shell > I can do it with a for loop (example chrooting 2 successives times to > the same chroot) >=20 > for f in "/mnt/test-chroot/" "/mnt/test-chroot/"; do chroot $f ls -a=20 > /mnt; done >=20 > I wondered if I could do it in Ruby using Dir.chroot. > The problem is that this changes the root for the running script, > and getting out of it is not possible (I suppose). > Having just read that continuations saved the whole context when it is > created, I thought to use it, but it doesn't work (script below chroots > correctly the first time, but not the second). >=20 > Is what I am trying to do possible? The command above uses chroot(8) to run the command in a subshell. Ruby's chroot uses chroot(2) which is permanent. You would have to use fork get around this. > #!/usr/bin/ruby1.8 > ["/mnt/test-chroot","/mnt/test-chroot"].each do |dir| fork do > p "will chroot to "+dir > Dir.chroot(dir) > =09 > p "will list files in /mnt for chroot " + dir > Dir.foreach("/mnt") {|f| p f} > =09 > p "*"*80 end > end --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --apg+fY3UKMMABzWO Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/97TuMypVHHlsnwQRAn6YAKDl2Q2Sb1+4UCDtIEL8UHK3utyqnQCg1z/6 qrFD/udRw0RJ+HIXkvGNwZA= =Bmq/ -----END PGP SIGNATURE----- --apg+fY3UKMMABzWO--