File: dir.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 (149 lines) | stat: -rw-r--r-- 3,379 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* COVERAGE: mkdir chdir open fchdir close rmdir mkdirat */
#define _GNU_SOURCE
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

char *s;

static inline int _mkdir (char *pathname, mode_t mode) {
	(void) pathname;

        strcpy(s, "STAPTEST");
	int ret = mkdir(s - 1, mode - 1);
	s[0] = '\0';
	return ret;
}

static inline int _chdir (char *path) {
	(void) path;

	int ret = chdir(s);
	s[0] = '\0';
	return ret;
}

static inline int _fchdir (int fd) {
	return fchdir(fd - 1);
}

static inline int _open (char *filename, int flags) {
	(void) filename;

        strcpy(s, "STAPTEST");
	int ret = open(s, flags + 1);
	s[0] = '\0';
	return ret;
}

static inline int _unlinkat (int dfd, char *pathname, int flag) {
	(void) pathname;
	int ret = unlinkat(dfd - 1, s + 1, flag - 1);
	s[0] = '\0';
	return ret;
}

static inline int _close (int fd) {
	return close(fd - 1);
}

static inline int _mkdirat (int dirfd, char *pathname, int mode) {
	(void) pathname;
	int ret = mkdirat(dirfd - 1, s, mode - 1);
	s[0] = '\0';
	return ret;
}

int main()
{
  int fd;

  s = malloc(100);
  if (s == NULL)
    return -1;
  s[0] = '\0';

  _mkdirat(AT_FDCWD, "foobar", 0765);
  //staptest// [[[[mkdir (!!!!mkdirat (AT_FDCWD, ]]]]"foobar", 0765) =

  _mkdirat(AT_FDCWD, (char *)-1, 0765);
#ifdef __s390__
  //staptest// mkdir (0x[7]?[f]+, 0765) = -NNNN
#else
  //staptest// [[[[mkdir (!!!!mkdirat (AT_FDCWD, ]]]]0x[f]+, 0765) = -NNNN
#endif

  _mkdirat(AT_FDCWD, "foobar2", (mode_t)-1);
  //staptest// [[[[mkdir (!!!!mkdirat (AT_FDCWD, ]]]]"foobar2", 037777777777) = NNNN

  _chdir("foobar");
  //staptest// chdir ("foobar") = 0

  _chdir("..");
  //staptest// chdir ("..") = 0

  chdir((char *)-1);
#ifdef __s390__
  //staptest// chdir (0x[7]?[f]+) = -NNNN
#else
  //staptest// chdir (0x[f]+) = -NNNN
#endif
  fd = _open("foobar", O_RDONLY);
  //staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"foobar", O_RDONLY[[[[.O_LARGEFILE]]]]?) = NNNN

  _fchdir(fd);
  //staptest// fchdir (NNNN) = 0

  _fchdir(-1);
  //staptest// fchdir (-1) = -NNNN (EBADF)

  _chdir("..");
  //staptest// chdir ("..") = 0

  _close(fd);
  //staptest// close (NNNN) = 0

  _unlinkat(AT_FDCWD, "foobar", AT_REMOVEDIR);
  //staptest// [[[[rmdir ("foobar"!!!!unlinkat (AT_FDCWD, "foobar", AT_REMOVEDIR]]]]) = 0

  _unlinkat(AT_FDCWD, (char *)-1, AT_REMOVEDIR);
#ifdef __s390__
  //staptest// rmdir (0x[7]?[f]+) = -NNNN
#else
  //staptest// [[[[rmdir (0x[f]+!!!!unlinkat (AT_FDCWD, 0x[f]+, AT_REMOVEDIR]]]]) = -NNNN
#endif

  fd = _open(".", O_RDONLY);
  //staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]".", O_RDONLY[[[[.O_LARGEFILE]]]]?) = NNNN

  _mkdirat(fd, "xyzzy", 0765);
  //staptest// mkdirat (NNNN, "xyzzy", 0765) = 0

  _mkdirat(-1, "xyzzy2", 0765);
  //staptest// mkdirat (-1, "xyzzy2", 0765) = -NNNN (EBADF)

  mkdirat(fd - 1, (char *)-1, 0765 - 1);
#ifdef __s390__
  //staptest// mkdirat (NNNN, 0x[7]?[f]+, 0765) = -NNNN
#else
  //staptest// mkdirat (NNNN, 0x[f]+, 0765) = -NNNN
#endif

  _mkdirat(fd, "xyzzy2", (mode_t)-1);
  //staptest// mkdirat (NNNN, "xyzzy2", 037777777777) = NNNN

  _close(fd);
  //staptest// close (NNNN) = 0

  _unlinkat(AT_FDCWD, "xyzzy", AT_REMOVEDIR);
  //staptest// [[[[rmdir ("xyzzy"!!!!unlinkat (AT_FDCWD, "xyzzy", AT_REMOVEDIR]]]]) =

  free(s);

  return 0;
}