-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
43 lines (37 loc) · 774 Bytes
/
main.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define _GNU_SOURCE
#include <err.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/mount.h>
int main(int argc, char *argv[])
{
if (chroot("./rootfs_alpine") == -1)
err(EXIT_FAILURE, "chroot");
if (chdir("/") == -1)
err(EXIT_FAILURE, "chdir");
if (unshare(CLONE_NEWPID | CLONE_NEWNS) == -1)
err(EXIT_FAILURE, "unshare");
int pid = fork();
if (pid == -1)
err(EXIT_FAILURE, "fork");
if (pid == 0)
{
if (mount("proc", "proc", "proc", 0, NULL) == -1)
{
err(EXIT_FAILURE, "mount");
}
if (execvp(argv[1], &argv[1]) == -1)
{
err(EXIT_FAILURE, "execvp");
}
}
else
{
int status;
wait(&status);
exit(WEXITSTATUS(status));
}
}