Debian Codegraph @

testsuite/systemtap.syscall/setns.c

raw
1 /* COVERAGE: setns */
2
3 #define _GNU_SOURCE
4 #include <sys/types.h>
5 #include <unistd.h>
6 #include <sys/syscall.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <fcntl.h>
10
11 #ifndef CLONE_NEWIPC
12 #define CLONE_NEWIPC 0x08000000
13 #endif
14
15 int main()
16 {
17 // This testcase can crash the s390x kernel. Please, refer to rhbz1219586.
18 // Skipping it on that platform.
19 #ifndef __s390__
20 char *fn;
21 int fd;
22
23 fn = malloc(1000);
24 sprintf(fn, "/proc/%d/ns/pid\0", getpid());
25 fd = open(fn, O_RDONLY);
26
27 #ifdef __NR_setns
28 // using syscall() to avoid link time issues on rhel6
29 syscall(__NR_setns, fd, 0);
30 //staptest// setns (NNNN, 0x0) = NNNN
31
32 syscall(__NR_setns, fd, CLONE_NEWIPC);
33 //staptest// setns (NNNN, CLONE_NEWIPC) = NNNN
34
35 // Limit testing
36
37 syscall(__NR_setns, -1, CLONE_NEWIPC);
38 //staptest// setns (-1, CLONE_NEWIPC) = -NNNN
39
40 syscall(__NR_setns, fd, -1);
41 //staptest// setns (NNNN, CLONE_VM|CLONE_FS|CLONE_FILES[^\)]+) = -NNNN
42 #endif
43
44 close(fd);
45 free(fn);
46 #endif
47
48 return 0;
49 }