]>
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"
44 int main(int argc
, char *argv
[])
50 pid
= lxc_raw_clone(CLONE_PARENT_SETTID
);
51 if (pid
>= 0 || pid
!= -EINVAL
) {
52 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_PARENT_SETTID) "
53 "should not be possible");
57 pid
= lxc_raw_clone(CLONE_CHILD_SETTID
);
58 if (pid
>= 0 || pid
!= -EINVAL
) {
59 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_CHILD_SETTID) "
60 "should not be possible");
64 pid
= lxc_raw_clone(CLONE_CHILD_CLEARTID
);
65 if (pid
>= 0 || pid
!= -EINVAL
) {
66 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_CHILD_CLEARTID) "
67 "should not be possible");
71 pid
= lxc_raw_clone(CLONE_SETTLS
);
72 if (pid
>= 0 || pid
!= -EINVAL
) {
73 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_SETTLS) should "
78 pid
= lxc_raw_clone(CLONE_VM
);
79 if (pid
>= 0 || pid
!= -EINVAL
) {
80 lxc_error("%s\n", "Calling lxc_raw_clone(CLONE_VM) should "
85 pid
= lxc_raw_clone(0);
87 lxc_error("%s\n", "Failed to call lxc_raw_clone(0)");
92 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
96 status
= wait_for_pid(pid
);
98 lxc_error("%s\n", "Failed to retrieve correct exit status");
102 pid
= lxc_raw_clone(0);
104 lxc_error("%s\n", "Failed to call lxc_raw_clone(0)");
109 lxc_error("%s\n", "Child will exit(EXIT_FAILURE)");
113 status
= wait_for_pid(pid
);
115 lxc_error("%s\n", "Failed to retrieve correct exit status");
119 pid
= lxc_raw_clone(CLONE_NEWUSER
| CLONE_NEWCGROUP
| CLONE_NEWNS
|
120 CLONE_NEWIPC
| CLONE_NEWNET
| CLONE_NEWIPC
|
121 CLONE_NEWPID
| CLONE_NEWUTS
);
123 lxc_error("%s\n", "Failed to call lxc_raw_clone(CLONE_NEWUSER "
124 "| CLONE_NEWCGROUP | CLONE_NEWNS | "
125 "CLONE_NEWIPC | CLONE_NEWNET | CLONE_NEWIPC "
126 "| CLONE_NEWPID | CLONE_NEWUTS);");
131 lxc_error("%s\n", "Child will exit(EXIT_SUCCESS)");
135 status
= wait_for_pid(pid
);
137 lxc_error("%s\n", "Failed to retrieve correct exit status");
141 flags
|= CLONE_NEWUSER
;
142 if (cgns_supported())
143 flags
|= CLONE_NEWCGROUP
;
144 flags
|= CLONE_NEWNS
;
145 flags
|= CLONE_NEWIPC
;
146 flags
|= CLONE_NEWNET
;
147 flags
|= CLONE_NEWIPC
;
148 flags
|= CLONE_NEWPID
;
149 flags
|= CLONE_NEWUTS
;
150 pid
= lxc_raw_clone(flags
);
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 lxc_debug("%s\n", "All lxc_raw_clone() tests successful");