-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathvz_create_exec.c
52 lines (42 loc) · 1.13 KB
/
vz_create_exec.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
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <libct.h>
#include <unistd.h>
#include <linux/sched.h>
#include "test.h"
#define FS_ROOT "root"
int main(int argc, char *argv[])
{
libct_session_t s;
ct_handler_t ct;
ct_process_desc_t pd;
ct_process_t p;
char *ls_a[2] = { "ls", NULL};
s = libct_session_open_local();
if (libct_handle_is_err(s))
return fail("Unable to create a new session");
ct = libct_container_create(s, "1337");
pd = libct_process_desc_create(s);
if (libct_handle_is_err(ct) ||
libct_handle_is_err(pd))
return fail("Unable to create a handle for process or container");
if (libct_fs_set_root(ct, FS_ROOT))
return fail("Unable to set FS_ROOT");
if (libct_container_set_nsmask(ct,
CLONE_NEWNS |
CLONE_NEWUTS |
CLONE_NEWIPC |
CLONE_NEWNET |
CLONE_NEWPID))
return fail("Unable to set nsmask");
p = libct_container_spawn_execv(ct, pd, "/bin/ls", ls_a);
if (libct_handle_is_err(p))
goto err;
if (libct_container_wait(ct))
return fail("Unable to wait a container");
libct_container_destroy(ct);
libct_session_close(s);
return pass("All is ok");;
err:
return fail("Something wrong");
}