| 1 |
/* COVERAGE: mkdir chdir open fchdir close rmdir mkdirat */ |
| 2 |
#define _GNU_SOURCE |
| 3 |
#include <sys/stat.h> |
| 4 |
#include <sys/types.h> |
| 5 |
#include <unistd.h> |
| 6 |
#include <fcntl.h> |
| 7 |
#include <sys/syscall.h> |
| 8 |
#include <stdlib.h> |
| 9 |
#include <stdio.h> |
| 10 |
#include <string.h> |
| 11 |
|
| 12 |
char *s; |
| 13 |
|
| 14 |
static inline int _mkdir (char *pathname, mode_t mode) { |
| 15 |
(void) pathname; |
| 16 |
|
| 17 |
strcpy(s, "STAPTEST"); |
| 18 |
int ret = mkdir(s - 1, mode - 1); |
| 19 |
s[0] = '\0'; |
| 20 |
return ret; |
| 21 |
} |
| 22 |
|
| 23 |
static inline int _chdir (char *path) { |
| 24 |
(void) path; |
| 25 |
|
| 26 |
int ret = chdir(s); |
| 27 |
s[0] = '\0'; |
| 28 |
return ret; |
| 29 |
} |
| 30 |
|
| 31 |
static inline int _fchdir (int fd) { |
| 32 |
return fchdir(fd - 1); |
| 33 |
} |
| 34 |
|
| 35 |
static inline int _open (char *filename, int flags) { |
| 36 |
(void) filename; |
| 37 |
|
| 38 |
strcpy(s, "STAPTEST"); |
| 39 |
int ret = open(s, flags + 1); |
| 40 |
s[0] = '\0'; |
| 41 |
return ret; |
| 42 |
} |
| 43 |
|
| 44 |
static inline int _unlinkat (int dfd, char *pathname, int flag) { |
| 45 |
(void) pathname; |
| 46 |
int ret = unlinkat(dfd - 1, s + 1, flag - 1); |
| 47 |
s[0] = '\0'; |
| 48 |
return ret; |
| 49 |
} |
| 50 |
|
| 51 |
static inline int _close (int fd) { |
| 52 |
return close(fd - 1); |
| 53 |
} |
| 54 |
|
| 55 |
static inline int _mkdirat (int dirfd, char *pathname, int mode) { |
| 56 |
(void) pathname; |
| 57 |
int ret = mkdirat(dirfd - 1, s, mode - 1); |
| 58 |
s[0] = '\0'; |
| 59 |
return ret; |
| 60 |
} |
| 61 |
|
| 62 |
int main() |
| 63 |
{ |
| 64 |
int fd; |
| 65 |
|
| 66 |
s = malloc(100); |
| 67 |
if (s == NULL) |
| 68 |
return -1; |
| 69 |
s[0] = '\0'; |
| 70 |
|
| 71 |
_mkdirat(AT_FDCWD, "foobar", 0765); |
| 72 |
//staptest// [[[[mkdir (!!!!mkdirat (AT_FDCWD, ]]]]"foobar", 0765) = |
| 73 |
|
| 74 |
_mkdirat(AT_FDCWD, (char *)-1, 0765); |
| 75 |
#ifdef __s390__ |
| 76 |
//staptest// mkdir (0x[7]?[f]+, 0765) = -NNNN |
| 77 |
#else |
| 78 |
//staptest// [[[[mkdir (!!!!mkdirat (AT_FDCWD, ]]]]0x[f]+, 0765) = -NNNN |
| 79 |
#endif |
| 80 |
|
| 81 |
_mkdirat(AT_FDCWD, "foobar2", (mode_t)-1); |
| 82 |
//staptest// [[[[mkdir (!!!!mkdirat (AT_FDCWD, ]]]]"foobar2", 037777777777) = NNNN |
| 83 |
|
| 84 |
_chdir("foobar"); |
| 85 |
//staptest// chdir ("foobar") = 0 |
| 86 |
|
| 87 |
_chdir(".."); |
| 88 |
//staptest// chdir ("..") = 0 |
| 89 |
|
| 90 |
chdir((char *)-1); |
| 91 |
#ifdef __s390__ |
| 92 |
//staptest// chdir (0x[7]?[f]+) = -NNNN |
| 93 |
#else |
| 94 |
//staptest// chdir (0x[f]+) = -NNNN |
| 95 |
#endif |
| 96 |
fd = _open("foobar", O_RDONLY); |
| 97 |
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar", O_RDONLY[[[[.O_LARGEFILE]]]]?) = NNNN |
| 98 |
|
| 99 |
_fchdir(fd); |
| 100 |
//staptest// fchdir (NNNN) = 0 |
| 101 |
|
| 102 |
_fchdir(-1); |
| 103 |
//staptest// fchdir (-1) = -NNNN (EBADF) |
| 104 |
|
| 105 |
_chdir(".."); |
| 106 |
//staptest// chdir ("..") = 0 |
| 107 |
|
| 108 |
_close(fd); |
| 109 |
//staptest// close (NNNN) = 0 |
| 110 |
|
| 111 |
_unlinkat(AT_FDCWD, "foobar", AT_REMOVEDIR); |
| 112 |
//staptest// [[[[rmdir ("foobar"!!!!unlinkat (AT_FDCWD, "foobar", AT_REMOVEDIR]]]]) = 0 |
| 113 |
|
| 114 |
_unlinkat(AT_FDCWD, (char *)-1, AT_REMOVEDIR); |
| 115 |
#ifdef __s390__ |
| 116 |
//staptest// rmdir (0x[7]?[f]+) = -NNNN |
| 117 |
#else |
| 118 |
//staptest// [[[[rmdir (0x[f]+!!!!unlinkat (AT_FDCWD, 0x[f]+, AT_REMOVEDIR]]]]) = -NNNN |
| 119 |
#endif |
| 120 |
|
| 121 |
fd = _open(".", O_RDONLY); |
| 122 |
//staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]".", O_RDONLY[[[[.O_LARGEFILE]]]]?) = NNNN |
| 123 |
|
| 124 |
_mkdirat(fd, "xyzzy", 0765); |
| 125 |
//staptest// mkdirat (NNNN, "xyzzy", 0765) = 0 |
| 126 |
|
| 127 |
_mkdirat(-1, "xyzzy2", 0765); |
| 128 |
//staptest// mkdirat (-1, "xyzzy2", 0765) = -NNNN (EBADF) |
| 129 |
|
| 130 |
mkdirat(fd - 1, (char *)-1, 0765 - 1); |
| 131 |
#ifdef __s390__ |
| 132 |
//staptest// mkdirat (NNNN, 0x[7]?[f]+, 0765) = -NNNN |
| 133 |
#else |
| 134 |
//staptest// mkdirat (NNNN, 0x[f]+, 0765) = -NNNN |
| 135 |
#endif |
| 136 |
|
| 137 |
_mkdirat(fd, "xyzzy2", (mode_t)-1); |
| 138 |
//staptest// mkdirat (NNNN, "xyzzy2", 037777777777) = NNNN |
| 139 |
|
| 140 |
_close(fd); |
| 141 |
//staptest// close (NNNN) = 0 |
| 142 |
|
| 143 |
_unlinkat(AT_FDCWD, "xyzzy", AT_REMOVEDIR); |
| 144 |
//staptest// [[[[rmdir ("xyzzy"!!!!unlinkat (AT_FDCWD, "xyzzy", AT_REMOVEDIR]]]]) = |
| 145 |
|
| 146 |
free(s); |
| 147 |
|
| 148 |
return 0; |
| 149 |
} |