-
Notifications
You must be signed in to change notification settings - Fork 25
/
ct_switch.c
74 lines (61 loc) · 1.75 KB
/
ct_switch.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Test entering into living container
*/
#include <libct.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sched.h>
#include "test.h"
int main(int argc, char **argv)
{
libct_session_t s;
ct_handler_t ct1, ct2;
ct_process_desc_t pd;
ct_process_t pr;
char root1[] = "libct_root1";
char root2[] = "libct_root2";
char buf[1024];
test_init();
mkdir(root1, 0700);
mkdir(root2, 0700);
snprintf(buf, sizeof(buf), "%s/%s", root1, "test1");
mkdir(buf, 0700);
snprintf(buf, sizeof(buf), "%s/%s", root2, "test2");
mkdir(buf, 0700);
s = libct_session_open_local();
ct1 = libct_container_create(s, "test1");
ct2 = libct_container_create(s, "test2");
libct_container_set_nsmask(ct1, CLONE_NEWNS);
libct_container_set_nsmask(ct2, CLONE_NEWNS);
libct_fs_set_root(ct1, root1);
libct_fs_set_root(ct2, root2);
libct_container_set_option(ct1, LIBCT_OPT_TASKLESS, 0);
libct_container_set_option(ct2, LIBCT_OPT_TASKLESS, 0);
pd = libct_process_desc_create(s);
pr = libct_container_spawn_cb(ct1, pd, NULL, NULL);
if (libct_handle_is_err(pr)) {
return fail("Unable to start CT");
}
pr = libct_container_spawn_cb(ct2, pd, NULL, NULL);
if (libct_handle_is_err(pr)) {
return fail("Unable to start CT");
}
if (libct_container_switch(ct1))
return fail("Unable to switch CT");
if (access("/test1", F_OK))
return fail("Unable to access /test1");
if (libct_container_switch(ct2))
return fail("Unable to switch CT");
if (access("/test2", F_OK))
return fail("Unable to access /test2");
libct_container_kill(ct1);
libct_container_kill(ct2);
libct_container_destroy(ct1);
libct_container_destroy(ct2);
libct_session_close(s);
return pass("CT is created and entered");
}