-
Notifications
You must be signed in to change notification settings - Fork 25
/
ct_pause.c
80 lines (66 loc) · 1.44 KB
/
ct_pause.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
/*
* Test empty "container" creation
*/
#include <unistd.h>
#include <libct.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include "test.h"
static int set_ct_alive(void *a)
{
int *pfd = (int *)a;
char buf;
close(pfd[1]);
if (read(pfd[0], &buf, sizeof(buf)) < 0)
return 1;
close(pfd[0]);
return 0;
}
int main(int argc, char **argv)
{
int pfd[2], status;
libct_session_t s;
ct_handler_t ct;
ct_process_desc_t p;
ct_process_t pr;
test_init();
if (pipe(pfd) < 0)
return 1;
s = libct_session_open_local();
if (libct_handle_is_err(s))
return fail("Unable to create a new session");
ct = libct_container_create(s, "test");
if (libct_handle_is_err(ct))
return fail("Unable to create a container object");
libct_controller_add(ct, CTL_FREEZER);
p = libct_process_desc_create(s);
if (libct_handle_is_err(p))
return fail("Unable to create a process descriptor");
pr = libct_container_spawn_cb(ct, p, set_ct_alive, pfd);
close(pfd[0]);
if (libct_handle_is_err(pr))
return fail("Unable to start CT");
if (libct_container_pause(ct)) {
fail("Unable to pause");
return 1;
}
if (libct_container_resume(ct)) {
fail("Unable to resume");
return 1;
}
close(pfd[1]);
if (wait(&status) < 0)
return 1;
libct_container_wait(ct);
libct_container_destroy(ct);
libct_session_close(s);
if (status == 0)
pass("Container is alive");
else {
fail("%x", status);
return 1;
}
return 0;
}