]>
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
25 #define __STDC_FORMAT_MACROS
36 #include <sys/mount.h>
38 #include <sys/types.h>
41 #include "namespace.h"
42 #include "raw_syscalls.h"
45 int main(int argc
, char *argv
[])
51 pid
= lxc_raw_clone(CLONE_PARENT_SETTID
, NULL
);
52 if (pid
>= 0 || pid
!= -EINVAL
) {
53 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_PARENT_SETTID) "
54 "should not be possible");
58 pid
= lxc_raw_clone(CLONE_CHILD_SETTID
, NULL
);
59 if (pid
>= 0 || pid
!= -EINVAL
) {
60 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_CHILD_SETTID) "
61 "should not be possible");
65 pid
= lxc_raw_clone(CLONE_CHILD_CLEARTID
, NULL
);
66 if (pid
>= 0 || pid
!= -EINVAL
) {
67 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_CHILD_CLEARTID) "
68 "should not be possible");
72 pid
= lxc_raw_clone(CLONE_SETTLS
, NULL
);
73 if (pid
>= 0 || pid
!= -EINVAL
) {
74 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_SETTLS) should "
79 pid
= lxc_raw_clone(CLONE_VM
, NULL
);
80 if (pid
>= 0 || pid
!= -EINVAL
) {
81 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_VM) should "
86 pid
= lxc_raw_clone(0, NULL
);
88 lxc_error("%s\n", "Failed to call lxc_raw_clone(0)");
93 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
97 status
= wait_for_pid(pid
);
99 lxc_error("%s\n", "Failed to retrieve correct exit status");
103 pid
= lxc_raw_clone(0, NULL
);
105 lxc_error("%s\n", "Failed to call lxc_raw_clone(0)");
110 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
114 status
= wait_for_pid(pid
);
116 lxc_error("%s\n", "Failed to retrieve correct exit status");
120 flags
|= CLONE_NEWUSER
;
121 if (cgns_supported())
122 flags
|= CLONE_NEWCGROUP
;
123 flags
|= CLONE_NEWNS
;
124 flags
|= CLONE_NEWIPC
;
125 flags
|= CLONE_NEWNET
;
126 flags
|= CLONE_NEWIPC
;
127 flags
|= CLONE_NEWPID
;
128 flags
|= CLONE_NEWUTS
;
130 pid
= lxc_raw_clone(flags
, NULL
);
132 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_NEWUSER "
133 "| CLONE_NEWCGROUP | CLONE_NEWNS | "
134 "CLONE_NEWIPC | CLONE_NEWNET | CLONE_NEWIPC "
135 "| CLONE_NEWPID | CLONE_NEWUTS);");
140 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
144 status
= wait_for_pid(pid
);
146 lxc_error("%s\n", "Failed to retrieve correct exit status");
150 pid
= lxc_raw_clone(flags
, NULL
);
152 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_NEWUSER "
153 "| CLONE_NEWCGROUP | CLONE_NEWNS | "
154 "CLONE_NEWIPC | CLONE_NEWNET | CLONE_NEWIPC "
155 "| CLONE_NEWPID | CLONE_NEWUTS);");
161 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
165 status
= wait_for_pid(pid
);
167 lxc_error("%s\n", "Failed to retrieve correct exit status");
171 pid
= lxc_raw_clone(CLONE_VFORK
, NULL
);
173 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_VFORK);");
178 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
182 status
= wait_for_pid(pid
);
184 lxc_error("%s\n", "Failed to retrieve correct exit status");
188 pid
= lxc_raw_clone(CLONE_VFORK
, NULL
);
190 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_VFORK);");
195 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
199 status
= wait_for_pid(pid
);
201 lxc_error("%s\n", "Failed to retrieve correct exit status");
205 pid
= lxc_raw_clone(CLONE_FILES
, NULL
);
207 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_FILES);");
212 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
216 status
= wait_for_pid(pid
);
218 lxc_error("%s\n", "Failed to retrieve correct exit status");
222 pid
= lxc_raw_clone(CLONE_FILES
, NULL
);
224 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_FILES);");
229 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
233 status
= wait_for_pid(pid
);
235 lxc_error("%s\n", "Failed to retrieve correct exit status");
239 lxc_debug("%s\n", "All lxc_raw_clone() tests successful");