Why does 'chroot' interfere with 'system'?

S

Sy Ali

This always fails.

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')
Kernel.system('rm -f bar')
Kernel.system('mv -f foo bar')
if File.exists?("bar") == true then puts "PASS" else puts "FAIL" end

It's the chroot which is causing the problem. What's the problem?
 
M

Mike Stok

This always fails.

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')
Kernel.system('rm -f bar')
Kernel.system('mv -f foo bar')
if File.exists?("bar") == true then puts "PASS" else puts "FAIL" end

It's the chroot which is causing the problem. What's the problem?

Once you have chrooted where do you expect to get the external
programs rm and mv from?

Mike

--

Mike Stok <[email protected]>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
 
A

Andrew Libby

Sy said:
This always fails.

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')
Kernel.system('rm -f bar')
Kernel.system('mv -f foo bar')
if File.exists?("bar") == true then puts "PASS" else puts "FAIL" end

It's the chroot which is causing the problem. What's the problem?

Hi Sy,

When you chroot to an area on the file system, that area/
directory becomes the root for the remainder of the process
life. If rm and mv are not available in the PATH relative
to the new root, then you'd have problems (i.e. the system
commands you're executing are not available).

Could this be it? You could check by verifying the return
value of the various calls to Kernel.system, no?

Good luck.


Andy
 
M

Mike Stok

This always fails.

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')
Kernel.system('rm -f bar')
Kernel.system('mv -f foo bar')
if File.exists?("bar") == true then puts "PASS" else puts "FAIL" end

It's the chroot which is causing the problem. What's the problem?

If you don't use external utilities would you be happier e.g.
File::unlink, File::rename and normal file io.

Michael

--

Mike Stok <[email protected]>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
 
M

Martin Coxall

Could this be it? You could check by verifying the return
value of the various calls to Kernel.system, no?

The odd thing is, that seems like the obvious answer. However, if you
take only the first two lines:

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')

I'd expect that to work, because 'echo' is a builtin on most shells.
But it doesn't, not on a random debian box I just tried. I don't
understand that.

Martin
 
T

ts

M> Dir.chroot(Dir.pwd)
M> Kernel.system('echo "new file" > foo')

ruby will try to exec /bin/sh, but it can't find it.



Guy Decoux
 
J

Jan Svitok

The odd thing is, that seems like the obvious answer. However, if you
take only the first two lines:

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')

I'd expect that to work, because 'echo' is a builtin on most shells.
But it doesn't, not on a random debian box I just tried. I don't
understand that.

As the previous posters said: do you have your shell in the chrooted dir?
 
M

Mike Stok

The odd thing is, that seems like the obvious answer. However, if you
take only the first two lines:

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')

I'd expect that to work, because 'echo' is a builtin on most shells.
But it doesn't, not on a random debian box I just tried. I don't
understand that.

Martin

Where do you get the shell from?

--

Mike Stok <[email protected]>
http://www.stok.ca/~mike/

The "`Stok' disclaimers" apply.
 
B

Benedikt Heinen

However, if you take only the first two lines:

Dir.chroot(Dir.pwd)
Kernel.system('echo "new file" > foo')

I'd expect that to work, because 'echo' is a builtin on most shells.
But it doesn't, not on a random debian box I just tried. I don't
understand that.

Well, it's true and it's not...

Yes, echo is a builtin in pretty much every shell...

However, if you do Kernel.system, this won't tell your shell to use its
builtin function - but it will try to run an executable call echo, which
normally is /bin/echo... Your shell is not involved in calls to
system(); the built-in will only be used while actually IN the shell.



Benedikt

ALLIANCE, n. In international politics, the union of two thieves who
have their hands so deeply inserted in each other's pockets that
they cannot separately plunder a third.
(Ambrose Bierce, The Devil's Dictionary)
 
M

Martin Coxall

As the previous posters said: do you have your shell in the chrooted dir?
No, but that doesn't normally matter as you're running chrooted in a
shell that has echo as a builtin. Clearly ruby attemps to re-exec
/bin/sh for every command, so it doesn't work.

If you manually chroot from a shell, and then a ruby script with only
the second line, that does work, because echo is a builtin. But only
then.

Martin
 
S

Sy Ali

Thanks everyone. I wanted to restrict activity to a certain branch on
the disk.. but it seems that chrooting wouldn't be a good answer for
my project.

In this example, I could use FileUtils.mv source, dest if I wanted
to.. but in my project I require external utilities.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top