1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // The test models how sandbox2 unshares user namespace after clone:
4 // https://github.com/google/sandboxed-api/blob/c95837a6c131fbdf820db352a97d54fcbcbde6c0/sandboxed_api/sandbox2/forkserver.cc#L249
5 // which works only in sigle-threaded processes.
10 #include <sys/types.h>
13 # include <linux/version.h>
16 #if __PPC64__ && RHEL_MAJOR == 7 && RHEL_MINOR == 9
17 # define PPC64_RHEL7_9 1
21 static int cloned(void *arg
) {
22 // Unshare can fail for other reasons, e.g. no permissions,
23 // so check only the error we are interested in:
24 // if the process is multi-threaded unshare must return EINVAL.
25 if (unshare(CLONE_NEWUSER
) && errno
== EINVAL
) {
26 fprintf(stderr
, "unshare failed: %d\n", errno
);
36 char stack
[64 << 10] __attribute__((aligned(64)));
37 int pid
= clone(cloned
, stack
+ sizeof(stack
), SIGCHLD
, 0);
39 fprintf(stderr
, "failed to clone: %d\n", errno
);
43 while (wait(&status
) != pid
) {
45 if (!WIFEXITED(status
) || WEXITSTATUS(status
) != 0) {
46 fprintf(stderr
, "child failed: %d\n", status
);
50 fprintf(stderr
, "DONE\n");