This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <errno.h>
18 #include <sched.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <sys/mount.h>
25 #include <unistd.h>
26
27 int main(void)
28 {
29 if (unshare(CLONE_NEWNS) == -1) {
30 if (errno == ENOSYS || errno == EPERM) {
31 fprintf(stderr, "error: unshare, errno %d\n", errno);
32 return 4;
33 }
34 fprintf(stderr, "error: unshare, errno %d\n", errno);
35 return 1;
36 }
37 if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
38 fprintf(stderr, "error: mount '/', errno %d\n", errno);
39 return 1;
40 }
41
42 if (mount(NULL, "/tmp", "ramfs", 0, NULL) == -1) {
43 fprintf(stderr, "error: mount ramfs, errno %d\n", errno);
44 return 1;
45 }
46
47 #define FILENAME "/tmp/1"
48
49 int fd = creat(FILENAME, 0700);
50 if (fd == -1) {
51 fprintf(stderr, "error: creat, errno %d\n", errno);
52 return 1;
53 }
54 #define S "#!" FILENAME "\n"
55 if (write(fd, S, strlen(S)) != strlen(S)) {
56 fprintf(stderr, "error: write, errno %d\n", errno);
57 return 1;
58 }
59 close(fd);
60
61 int rv = execve(FILENAME, NULL, NULL);
62 if (rv == -1 && errno == ELOOP) {
63 return 0;
64 }
65 fprintf(stderr, "error: execve, rv %d, errno %d\n", rv, errno);
66 return 1;
67 }