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