Debian Codegraph @

testsuite/systemtap.syscall/chmod.c

raw
1 /* COVERAGE: chmod fchmod fchmodat chown fchown fchownat lchown */
2 /* COVERAGE: chown16 fchown16 lchown16 */
3 #define _GNU_SOURCE
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <sys/syscall.h>
9 #include <sys/mman.h>
10
11 // To test for glibc support for fchmodat(), fchownat():
12 //
13 // Since glibc 2.10:
14 // _XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L
15 // Before glibc 2.10:
16 // _ATFILE_SOURCE
17
18 #define GLIBC_SUPPORT \
19 (_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L \
20 || defined(_ATFILE_SOURCE))
21
22 int main()
23 {
24 int fd;
25
26 mlockall(MCL_CURRENT);
27
28 fd = open("foobar",O_WRONLY|O_CREAT, 0666);
29 //staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar", O_WRONLY|O_CREAT[[[[.O_LARGEFILE]]]]?, 0666) = NNNN
30
31 chmod("foobar", 0644);
32 //staptest// [[[[chmod (!!!!fchmodat (AT_FDCWD, ]]]]"foobar", 0644) = 0
33
34 fchmod(fd, 0444);
35 //staptest// fchmod (NNNN, 0444) = 0
36
37 #if GLIBC_SUPPORT
38 fchmodat(AT_FDCWD, "foobar", 0644, 0);
39 //staptest// fchmodat (AT_FDCWD, "foobar", 0644) = 0
40 #endif
41
42 chmod((char *)-1, 0644);
43 #ifdef __s390__
44 //staptest// chmod (0x[7]?[f]+, 0644) = -NNNN (EFAULT)
45 #else
46 //staptest// [[[[chmod (!!!!fchmodat (AT_FDCWD, ]]]]0x[f]+, 0644[[[[, 0x0]]]]?) = -NNNN (EFAULT)
47 #endif
48
49 fchmod(-1, 0644);
50 //staptest// [[[[fchmod (!!!!fchmodat (AT_FDCWD, ]]]]-1, 0644[[[[, 0x0]]]]?) = -NNNN (EBADF)
51
52 #if GLIBC_SUPPORT
53 fchmodat(AT_FDCWD, (char *)-1, 0644, 0);
54 #ifdef __s390__
55 //staptest// fchmodat (AT_FDCWD, 0x[7]?[f]+, 0644) = -NNNN (EFAULT)
56 #else
57 //staptest// fchmodat (AT_FDCWD, 0x[f]+, 0644) = -NNNN (EFAULT)
58 #endif
59 #endif
60
61 chmod("foobar", -1);
62 //staptest// [[[[chmod (!!!!fchmodat (AT_FDCWD, ]]]]"foobar", 037777777777) = NNNN
63
64 fchmod(fd, -1);
65 //staptest// fchmod (NNNN, 037777777777) = NNNN
66
67 #if GLIBC_SUPPORT
68 fchmodat(AT_FDCWD, "foobar", -1, 0);
69 //staptest// fchmodat (AT_FDCWD, "foobar", 037777777777) = NNNN
70
71 fchmodat(-1, "foobar", 0644, 0);
72 //staptest// fchmodat (-1, "foobar", 0644) = -NNNN (EBADF)
73 #endif
74
75
76 chown((char *)-1, 5000, 5001);
77 #ifdef __s390__
78 //staptest// chown (0x[7]?[f]+, 5000, 5001) = -NNNN (EFAULT)
79 #else
80 //staptest// [[[[chown (!!!!fchownat (AT_FDCWD, ]]]]0x[f]+, 5000, 5001[[[[, 0x0]]]]?) = -NNNN (EFAULT)
81 #endif
82
83 chown("foobar", 5000, -1);
84 //staptest// [[[[chown (!!!!fchownat (AT_FDCWD, ]]]]"foobar", 5000, -1[[[[, 0x0]]]]?) = NNNN
85
86 chown("foobar", -1, 5001);
87 //staptest// [[[[chown (!!!!fchownat (AT_FDCWD, ]]]]"foobar", -1, 5001[[[[, 0x0]]]]?) = NNNN
88
89 fchown(-1, 5002, 5003);
90 //staptest// [[[[fchown (!!!!fchownat (AT_FDCWD, ]]]]-1, 5002, 5003[[[[, 0x0]]]]?) = -NNNN (EBADF)
91
92 fchown(fd, 5002, -1);
93 //staptest// fchown (NNNN, 5002, -1) = NNNN
94
95 #if GLIBC_SUPPORT
96 fchownat(-1, "foobar", 5002, -1, 0);
97 //staptest// fchownat (-1, "foobar", 5002, -1, 0x0) = -NNNN (EBADF)
98
99 fchownat(AT_FDCWD, (char *)-1, 5002, -1, 0);
100 #ifdef __s390__
101 //staptest// fchownat (AT_FDCWD, 0x[7]?[f]+, 5002, -1, 0x0) = -NNNN (EFAULT)
102 #else
103 //staptest// fchownat (AT_FDCWD, 0x[f]+, 5002, -1, 0x0) = -NNNN (EFAULT)
104 #endif
105
106 fchownat(AT_FDCWD, "foobar", -1, 5000, 0);
107 //staptest// fchownat (AT_FDCWD, "foobar", -1, 5000, 0x0) = NNNN
108
109 fchownat(AT_FDCWD, "foobar", 5002, -1, 0);
110 //staptest// fchownat (AT_FDCWD, "foobar", 5002, -1, 0x0) = NNNN
111 #endif
112
113 fchown(fd, -1, 5003);
114 //staptest// fchown (NNNN, -1, 5003) = NNNN
115
116 lchown("foobar", 5004, -1);
117 //staptest// [[[[lchown (!!!!fchownat (AT_FDCWD, ]]]]"foobar", 5004, -1[[[[, AT_SYMLINK_NOFOLLOW]]]]?) = NNNN
118
119 lchown("foobar", -1, 5005);
120 //staptest// [[[[lchown (!!!!fchownat (AT_FDCWD, ]]]]"foobar", -1, 5005[[[[, AT_SYMLINK_NOFOLLOW]]]]?) = NNNN
121
122 lchown((char *)-1, 5005, 5006);
123 #ifdef __s390__
124 //staptest// lchown (0x[7]?[f]+, 5005, 5006) = -NNNN (EFAULT)
125 #else
126 //staptest// [[[[lchown (!!!!fchownat (AT_FDCWD, ]]]]0x[f]+, 5005, 5006[[[[, AT_SYMLINK_NOFOLLOW]]]]?) = -NNNN (EFAULT)
127 #endif
128
129 #if __WORDSIZE != 64
130 #ifdef SYS_chown
131 syscall(SYS_chown, "foobar", 5000, -1);
132 //staptest// chown[[[[16]]]]? ("foobar", 5000, -1) = NNNN
133 syscall(SYS_chown, "foobar", -1, 5001);
134 //staptest// chown[[[[16]]]]? ("foobar", -1, 5001) = NNNN
135 #endif
136
137 #ifdef SYS_fchown
138 syscall(SYS_fchown, fd, 5002, -1);
139 //staptest// fchown[[[[16]]]]? (NNNN, 5002, -1) = NNNN
140 syscall(SYS_fchown, fd, -1, 5003);
141 //staptest// fchown[[[[16]]]]? (NNNN, -1, 5003) = NNNN
142 #endif
143
144 #ifdef SYS_lchown
145 syscall(SYS_lchown, "foobar", 5004, -1);
146 //staptest// lchown[[[[16]]]]? ("foobar", 5004, -1) = NNNN
147 syscall(SYS_lchown, "foobar", -1, 5005);
148 //staptest// lchown[[[[16]]]]? ("foobar", -1, 5005) = NNNN
149 #endif
150 #endif
151
152 close(fd);
153 return 0;
154 }