[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Why does 'chroot' interfere with 'system'?

Sy Ali

10/13/2006 2:23:00 PM

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?

12 Answers

Mike Stok

10/13/2006 2:28:00 PM

0


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 Stok <mike@stok.ca>
http://www.stok...

The "`Stok' disclaimers" apply.





Andrew Libby

10/13/2006 2:29:00 PM

0

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


Mike Stok

10/13/2006 2:39:00 PM

0


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 Stok <mike@stok.ca>
http://www.stok...

The "`Stok' disclaimers" apply.





Martin Coxall

10/13/2006 2:40:00 PM

0

> 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

ts

10/13/2006 2:47:00 PM

0

>>>>> "M" == Martin Coxall <pseudo.meta@gmail.com> 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

Jano Svitok

10/13/2006 2:48:00 PM

0

On 10/13/06, Martin Coxall <pseudo.meta@gmail.com> 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.
> 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?

Mike Stok

10/13/2006 2:51:00 PM

0


On 13-Oct-06, at 10:40 AM, Martin Coxall 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.
> 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 <mike@stok.ca>
http://www.stok...

The "`Stok' disclaimers" apply.





Benedikt Heinen

10/13/2006 2:53:00 PM

0

Martin Coxall

10/13/2006 2:57:00 PM

0

> 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

Paul Lutus

10/13/2006 3:23:00 PM

0

Martin Coxall 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.

--
Paul Lutus
http://www.ara...