File: setns.c

package info (click to toggle)
systemtap 4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,000 kB
  • sloc: cpp: 78,785; ansic: 62,419; xml: 49,443; exp: 42,735; sh: 11,254; python: 3,062; perl: 2,252; tcl: 1,305; makefile: 1,072; lisp: 105; awk: 101; asm: 91; java: 56; sed: 16
file content (49 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* COVERAGE: setns */

#define _GNU_SOURCE
#include <sys/types.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>

#ifndef CLONE_NEWIPC
#define CLONE_NEWIPC 0x08000000
#endif

int main()
{
// This testcase can crash the s390x kernel. Please, refer to rhbz1219586.
// Skipping it on that platform.
#ifndef __s390__
    char *fn;
    int fd;

    fn = malloc(1000);
    sprintf(fn, "/proc/%d/ns/pid\0", getpid());
    fd = open(fn, O_RDONLY);

#ifdef __NR_setns
    // using syscall() to avoid link time issues on rhel6
    syscall(__NR_setns, fd, 0);
    //staptest// setns (NNNN, 0x0) = NNNN

    syscall(__NR_setns, fd, CLONE_NEWIPC);
    //staptest// setns (NNNN, CLONE_NEWIPC) = NNNN

    // Limit testing

    syscall(__NR_setns, -1, CLONE_NEWIPC);
    //staptest// setns (-1, CLONE_NEWIPC) = -NNNN

    syscall(__NR_setns, fd, -1);
    //staptest// setns (NNNN, CLONE_VM|CLONE_FS|CLONE_FILES[^\)]+) = -NNNN
#endif

    close(fd);
    free(fn);
#endif

    return 0;
}