user2659088
user2659088

Reputation: 133

how can I call execl( java program) after chroot?

I have a problem calling execlp (java) after chroot.

java program is installed at /usr/lib/jvm/default-java/jre/bin/java.

And I cant execute java program after chroot(".") because I cant reach actual root and

directory where java is installed.

here's my simple code.

    int pid = fork();

    if(pid == 0)
    {
        chroot(".");

        execlp("java","java","test",  NULL);  // cant run "test" java program
    }
    else{
           wait4(..............);
    }

if I remove chroot, it runs well.

the problem is that "java" is in /usr/lib/....... ,

and if I use chroot, I can't reach actual root and java.

isn't there solution using chroot and java together??

Upvotes: 2

Views: 702

Answers (2)

Jayan
Jayan

Reputation: 18458

http://en.wikipedia.org/wiki/Chroot

At startup, programs expect to find scratch space, configuration files, device nodes and shared libraries at certain preset locations. For a chrooted program to successfully start, the chroot directory must be populated with a minimum set of these files. This can make chroot difficult to use as a general sandboxing mechanism.

There will have limited practical use I guess

Upvotes: 0

Stephen C
Stephen C

Reputation: 719289

Is there solution using chroot and java together?

Yes. You need to make sure that you have Java installed in the chrooted file system. In other words, you need copies of all of the files in the installation tree in the appropriate place in the chrooted file system, together with all of the symlinks etc that are required to make the command(s) accessible from the PATH.

(At least, that is the theory. I don't know how easy this is to achieve in practice.)

Upvotes: 1

Related Questions