-
Notifications
You must be signed in to change notification settings - Fork 25
/
ct_enter.c
81 lines (67 loc) · 1.56 KB
/
ct_enter.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
75
76
77
78
79
80
81
/*
* Test entering into living container
*/
#include <libct.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
#include "test.h"
struct ct_arg {
int wait_fd;
int *mark;
};
static int set_ct_alive(void *a)
{
struct ct_arg *cta = a;
char c;
cta->mark[0] = 1;
read(cta->wait_fd, &c, 1);
return 0;
}
static int set_ct_enter(void *a)
{
struct ct_arg *cta = a;
cta->mark[1] = 1;
return 0;
}
int main(int argc, char **argv)
{
struct ct_arg cta;
int p[2], status;
libct_session_t s;
ct_handler_t ct;
ct_process_desc_t pd;
ct_process_t pr;
test_init();
if (pipe(p))
return tst_perr("Unable to create pipe");
cta.mark = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANON, 0, 0);
cta.mark[0] = 0;
cta.mark[1] = 0;
cta.wait_fd = p[0];
s = libct_session_open_local();
ct = libct_container_create(s, "test");
libct_container_set_option(ct, LIBCT_OPT_KILLABLE, NULL);
pd = libct_process_desc_create(s);
pr = libct_container_spawn_cb(ct, pd, set_ct_alive, &cta);
if (libct_handle_is_err(pr)) {
return fail("Unable to start CT");
}
pr = libct_container_enter_cb(ct, pd, set_ct_enter, &cta);
if (libct_handle_is_err(pr))
return fail("Unable to enter into CT");
libct_process_wait(pr, &status);
write(p[1], "a", 1);
libct_container_wait(ct);
libct_container_destroy(ct);
libct_process_desc_destroy(pd);
libct_process_destroy(pr);
libct_session_close(s);
if (!cta.mark[0])
return fail("CT is not alive");
if (!cta.mark[1])
return fail("CT is not enterable");
return pass("CT is created and entered");
}