Why does 'chroot' interfere with 'system'?

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?

Sy Ali wrote:

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

On 13-Oct-06, at 10:22 AM, Sy Ali wrote:

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 S. [email protected]
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.

On 13-Oct-06, at 10:22 AM, Sy Ali wrote:

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 S. [email protected]
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.

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

On 10/13/06, Martin C. [email protected] wrote:

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” == Martin C. [email protected] writes:

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

On 13-Oct-06, at 10:40 AM, Martin C. wrote:

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 S. [email protected]
http://www.stok.ca/~mike/

The “`Stok’ disclaimers” apply.

On Fri, 13 Oct 2006, Martin C. wrote:

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)

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

Martin C. wrote:

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.

Yes, it’s tree, "echo " is built into most shells, but after changing
roots,
the program can’t find the shell itself. Remember that “system” either
finds an external command or it finds a shell to run the shell’s
internal
commands. but if it can’t find either, you will always get an error.

But it doesn’t, not on a random debian box I just tried. I don’t
understand that.

Ask yourself how “system” functions at all. It must always find a shell,
a
command processor, to execute.

Ask yourself how “system” functions at all. It must always find a shell, a
command processor, to execute.

That makes sense.

Thanks.

Martin

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs