]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/lxc_raw_clone.c
2 * lxc: linux Container library
4 * Copyright © 2017 Canonical Ltd.
7 * Christian Brauner <christian.brauner@ubuntu.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36 #include <sys/mount.h>
38 #include <sys/types.h>
40 #include "cgroups/cgroup_utils.h"
42 #include "namespace.h"
43 #include "process_utils.h"
46 int main(int argc
, char *argv
[])
52 pid
= lxc_raw_clone(CLONE_PARENT_SETTID
, NULL
);
53 if (pid
>= 0 || pid
!= -EINVAL
) {
54 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_PARENT_SETTID) "
55 "should not be possible");
59 pid
= lxc_raw_clone(CLONE_CHILD_SETTID
, NULL
);
60 if (pid
>= 0 || pid
!= -EINVAL
) {
61 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_CHILD_SETTID) "
62 "should not be possible");
66 pid
= lxc_raw_clone(CLONE_CHILD_CLEARTID
, NULL
);
67 if (pid
>= 0 || pid
!= -EINVAL
) {
68 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_CHILD_CLEARTID) "
69 "should not be possible");
73 pid
= lxc_raw_clone(CLONE_SETTLS
, NULL
);
74 if (pid
>= 0 || pid
!= -EINVAL
) {
75 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_SETTLS) should "
80 pid
= lxc_raw_clone(CLONE_VM
, NULL
);
81 if (pid
>= 0 || pid
!= -EINVAL
) {
82 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_VM) should "
87 pid
= lxc_raw_clone(0, NULL
);
89 lxc_error("%s\n", "Failed to call lxc_raw_clone(0)");
94 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
98 status
= wait_for_pid(pid
);
100 lxc_error("%s\n", "Failed to retrieve correct exit status");
104 pid
= lxc_raw_clone(0, NULL
);
106 lxc_error("%s\n", "Failed to call lxc_raw_clone(0)");
111 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
115 status
= wait_for_pid(pid
);
117 lxc_error("%s\n", "Failed to retrieve correct exit status");
121 flags
|= CLONE_NEWUSER
;
122 if (cgns_supported())
123 flags
|= CLONE_NEWCGROUP
;
124 flags
|= CLONE_NEWNS
;
125 flags
|= CLONE_NEWIPC
;
126 flags
|= CLONE_NEWNET
;
127 flags
|= CLONE_NEWIPC
;
128 flags
|= CLONE_NEWPID
;
129 flags
|= CLONE_NEWUTS
;
131 pid
= lxc_raw_clone(flags
, NULL
);
133 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_NEWUSER "
134 "| CLONE_NEWCGROUP | CLONE_NEWNS | "
135 "CLONE_NEWIPC | CLONE_NEWNET | CLONE_NEWIPC "
136 "| CLONE_NEWPID | CLONE_NEWUTS);");
141 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
145 status
= wait_for_pid(pid
);
147 lxc_error("%s\n", "Failed to retrieve correct exit status");
151 pid
= lxc_raw_clone(flags
, NULL
);
153 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_NEWUSER "
154 "| CLONE_NEWCGROUP | CLONE_NEWNS | "
155 "CLONE_NEWIPC | CLONE_NEWNET | CLONE_NEWIPC "
156 "| CLONE_NEWPID | CLONE_NEWUTS);");
162 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
166 status
= wait_for_pid(pid
);
168 lxc_error("%s\n", "Failed to retrieve correct exit status");
172 pid
= lxc_raw_clone(CLONE_VFORK
, NULL
);
174 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_VFORK);");
179 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
183 status
= wait_for_pid(pid
);
185 lxc_error("%s\n", "Failed to retrieve correct exit status");
189 pid
= lxc_raw_clone(CLONE_VFORK
, NULL
);
191 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_VFORK);");
196 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
200 status
= wait_for_pid(pid
);
202 lxc_error("%s\n", "Failed to retrieve correct exit status");
206 pid
= lxc_raw_clone(CLONE_FILES
, NULL
);
208 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_FILES);");
213 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
217 status
= wait_for_pid(pid
);
219 lxc_error("%s\n", "Failed to retrieve correct exit status");
223 pid
= lxc_raw_clone(CLONE_FILES
, NULL
);
225 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_FILES);");
230 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
234 status
= wait_for_pid(pid
);
236 lxc_error("%s\n", "Failed to retrieve correct exit status");
240 lxc_debug("%s\n", "All lxc_raw_clone() tests successful");