summaryrefslogtreecommitdiff
path: root/Userland/chroot.cpp
blob: 890d18ac02fee6c46ab4d39fbc75a7a65fc7c0cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <unistd.h>

int main(int argc, char** argv)
{
    if (argc != 2) {
        printf("usage: chroot <path>\n");
        return 0;
    }

    if (chroot(argv[1]) < 0) {
        perror("chroot");
        return 1;
    }

    if (chdir("/") < 0) {
        perror("chdir(/)");
        return 1;
    }

    if (execl("/bin/Shell", "Shell", nullptr) < 0) {
        perror("execl");
        return 1;
    }

    return 0;
}