Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way to run a program in a chroot while still having access to stdin/stdout?

My first attempt was a shell script:

/usr/local/bin/real-app:
--------
#!/bin/bash

chroot /var/lib/app-root /usr/bin/app $*

Then symlinked it where things expect to see it:

ln -s /usr/local/bin/real-app /usr/local/bin/app

But two issues here. First, the program requires root to run. I can deal with that. But second, there no longer seems to be a connection to STDIN/STDOUT which is how the parent process expects to control this application.

Is there a way to make this work? Do I need to have the app modified so it performs the chroot syscall itself?

share|improve this question
1  
There may be some other problem actually, because, come to think of it "chroot /var/lib/chroot /bin/bash" does exactly this, right? Interactive shell started by the caller with stdin/stdout.... hmm. –  Mark Renouf Oct 20 '09 at 14:30

1 Answer 1

chroot should not affect stdin, stdout or any other file descriptors which are open at exec time. I don't know what your shell chroot command does, but provided it doesn't close them, then it should all work fine.

That is, provided the program doesn't do something really silly like rely on opening /dev/stdout or anything.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.