successive chroots thanks to continuations?

  • Thread starter Bauduin Raphael
  • Start date
B

Bauduin Raphael

Hi again,

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)

for f in "/mnt/test-chroot/" "/mnt/test-chroot/"; do chroot $f ls -a
/mnt; done

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).

Is what I am trying to do possible?

Thanks.

Raph


#!/usr/bin/ruby1.8
["/mnt/test-chroot","/mnt/test-chroot"].each do |dir|
callcc{|cc|
p "will chroot to "+dir
Dir.chroot(dir)

p "will list files in /mnt for chroot " + dir
Dir.foreach("/mnt") {|f| p f}

p "*"*80
cc.call
}
end
 
E

Eric Hodel

--apg+fY3UKMMABzWO
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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 - (e-mail address removed) - 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--
 
T

ts

B> for f in "/mnt/test-chroot/" "/mnt/test-chroot/"; do chroot $f ls -a
B> /mnt; done

chroot(1) is an user command

B> Having just read that continuations saved the whole context when it is
B> created, I thought to use it, but it doesn't work (script below chroots
B> correctly the first time, but not the second).

What do you call a context ?

I hope that you don't expect that this work

svg% cat b.rb
#!/usr/bin/ruby
["b.rb", "b.rb"].each do |file|
callcc {|cc|
File.unlink(file)
cc.call
}
end

svg%

:)

B> Is what I am trying to do possible?

use Kernel#fork, with Process::wait and Dir::chdir, Dir::chroot


Guy Decoux
 
B

Bauduin Raphael

ts said:
B> for f in "/mnt/test-chroot/" "/mnt/test-chroot/"; do chroot $f ls -a
B> /mnt; done

chroot(1) is an user command

yes. Take this as what I want to duplicate in "pure" Ruby.
B> Having just read that continuations saved the whole context when it is
B> created, I thought to use it, but it doesn't work (script below chroots
B> correctly the first time, but not the second).

What do you call a context ?

I hope that you don't expect that this work

svg% cat b.rb
#!/usr/bin/ruby
["b.rb", "b.rb"].each do |file|
callcc {|cc|
File.unlink(file)
cc.call
}
end

svg%

:)

hehe, no, I wasn't hoping this would work :)

B> Is what I am trying to do possible?

use Kernel#fork, with Process::wait and Dir::chdir, Dir::chroot

I'll take a look to those, thanks.

Raph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top