Skip to content

Commit 3fac931

Browse files
committed
tests: verify the auxstr of clone3(2) with -e namespace=new option
* tests/gen_tests.in (clone3-report-ns-id): New test. * tests/pure_executables.list: Add clone3-report-ns-id. * tests/clone3-report-ns-id.c: New fle. * tests/.gitignore: Add clone3-report-ns-id. Changes in v3 (Suggested by Dmitry V. Levin <[email protected]>): * Don't wait for the child process exiting in the parent process. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 9ec2eb8 commit 3fac931

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

tests/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ clone3
7272
clone3-Xabbrev
7373
clone3-Xraw
7474
clone3-Xverbose
75+
clone3-report-ns-id
7576
clone3-success
7677
clone3-success-Xabbrev
7778
clone3-success-Xraw

tests/clone3-report-ns-id.c

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Check appending auxstr of clone3(2) when --namespace=switchTo is given
3+
*
4+
* Copyright (c) 2024 The strace developers.
5+
* All rights reserved.
6+
*
7+
* SPDX-License-Identifier: GPL-2.0-or-later
8+
*/
9+
10+
#include "tests.h"
11+
#include "xmalloc.h"
12+
13+
#include <limits.h>
14+
#include <linux/sched.h>
15+
#include <stdio.h>
16+
#include <sys/syscall.h>
17+
#include <unistd.h>
18+
19+
#include "scno.h"
20+
21+
int
22+
main(void)
23+
{
24+
struct clone_args arg = { .flags = CLONE_NEWUSER };
25+
int pid = syscall(__NR_clone3, &arg, sizeof(arg));
26+
if (pid < 0)
27+
perror_msg_and_fail("clone3");
28+
if (pid > 0) {
29+
printf("clone3({flags=CLONE_NEWUSER, exit_signal=0, stack=NULL, stack_size=0}"
30+
", %zu) = %s ", sizeof(arg), sprintrc(pid));
31+
32+
char userns[PATH_MAX + 1];
33+
char *fname = xasprintf("/proc/%d/ns/user", pid);
34+
int rc = readlink(fname, userns, sizeof(userns));
35+
if ((size_t) rc >= sizeof(userns))
36+
perror_msg_and_fail("readlink");
37+
userns[rc] = '\0';
38+
printf("(%s)\n", userns);
39+
puts("+++ exited with 0 +++");
40+
}
41+
return 0;
42+
}

tests/gen_tests.in

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ clone3-success-Xabbrev -einject=clone3:retval=42 -etrace=clone3 -a16 -Xabbrev
6666
clone3-success-Xraw -einject=clone3:retval=42 -etrace=clone3 -a16 -Xraw
6767
clone3-success-Xverbose -einject=clone3:retval=42 -etrace=clone3 -a16 -Xverbose
6868
clone_parent +clone_ptrace.test
69+
clone3-report-ns-id -etrace=clone3 -a35 -e namespace=new
6970
clone_parent--quiet-exit +clone_ptrace.test --quiet=exit,personality
7071
clone_parent-q +clone_ptrace.test -q
7172
clone_parent-qq +clone_ptrace.test -qq

tests/pure_executables.list

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ clone3
4444
clone3-Xabbrev
4545
clone3-Xraw
4646
clone3-Xverbose
47+
clone3-report-ns-id
4748
copy_file_range
4849
creat
4950
delete_module

0 commit comments

Comments
 (0)