Debian Codegraph @

testsuite/systemtap.syscall/fanotify.c

raw
1 /* COVERAGE: fanotify_init fanotify_mark */
2
3 #define _GNU_SOURCE
4 #include <string.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <limits.h>
10 #include <poll.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <sys/syscall.h>
15
16 // glibc added support for fanotify_init() and fanotify_mark() in glibc 2.13.
17 #if __GLIBC_PREREQ(2, 13)
18 #include <sys/fanotify.h>
19
20 #define EVENT_MAX 1024
21 /* size of the event structure, not counting name */
22 #define EVENT_SIZE (sizeof (struct fanotify_event_metadata))
23 /* reasonable guess as to size of 1024 events */
24 #define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE)
25
26 #define BUF_SIZE 256
27 static char fname[BUF_SIZE] = "testfile";
28 static int fd, fd_notify;
29
30 static char event_buf[EVENT_BUF_LEN];
31
32 int main()
33 {
34 fd = creat(fname, S_IREAD|S_IWRITE);
35 close(fd);
36
37 /* Note that the fanotify calls require root access or the
38 * CAP_SYS_ADMIN capability. */
39
40 fd_notify = fanotify_init(FAN_CLASS_NOTIF|FAN_NONBLOCK, O_RDONLY);
41 //staptest// fanotify_init (FAN_CLASS_NOTIF|FAN_NONBLOCK, O_RDONLY) = NNNN
42
43 fanotify_mark(fd_notify, FAN_MARK_ADD,
44 FAN_ACCESS|FAN_MODIFY|FAN_CLOSE|FAN_OPEN, AT_FDCWD, fname);
45 //staptest// fanotify_mark (NNNN, FAN_MARK_ADD, FAN_ACCESS|FAN_MODIFY|FAN_CLOSE_WRITE|FAN_CLOSE_NOWRITE|FAN_OPEN, AT_FDCWD, "testfile") = NNNN
46
47 // Now, modify the test file.
48 fd = open(fname, O_WRONLY);
49 //staptest// [[[[open (!!!!openat (AT_FDCWD, ]]]]"testfile", O_WRONLY) = NNNN
50
51 write(fd, fname, strlen(fname));
52 //staptest// write (NNNN, "testfile", NNNN) = NNNN
53
54 close(fd);
55 //staptest// close (NNNN) = 0
56
57 // Read list of events.
58 read(fd_notify, event_buf, EVENT_BUF_LEN);
59 //staptest// read (NNNN, XXXX, NNNN) = NNNN
60
61 // A real program would process the list of events. We're not
62 // going to bother.
63
64 close(fd_notify);
65 //staptest// close (NNNN) = NNNN
66
67 /* Limit testing. */
68 fanotify_init(-1, O_RDONLY);
69 //staptest// fanotify_init (XXXX|FAN_[^ ]+|XXXX, O_RDONLY) = -NNNN
70
71 // Here's we're passing an invalid flags value (we hope) to make
72 // sure this fails.
73 fanotify_init(0x80000000, -1);
74 //staptest// fanotify_init (FAN_CLASS_NOTIF|0x80000000, O_[^ ]+|XXXX) = -NNNN
75
76 fanotify_mark(-1, FAN_MARK_REMOVE, FAN_ACCESS, AT_FDCWD, fname);
77 //staptest// fanotify_mark (-1, FAN_MARK_REMOVE, FAN_ACCESS, AT_FDCWD, "testfile") = -NNNN
78
79 fanotify_mark(-1, -1, FAN_MODIFY, AT_FDCWD, fname);
80 //staptest// fanotify_mark (-1, FAN_[^ ]+|XXXX, FAN_MODIFY, AT_FDCWD, "testfile") = -NNNN
81
82 fanotify_mark(-1, FAN_MARK_FLUSH, -1, AT_FDCWD, fname);
83 //staptest// fanotify_mark (-1, FAN_MARK_FLUSH, FAN_[^ ]+|XXXX, AT_FDCWD, "testfile") = -NNNN
84
85 fanotify_mark(-1, FAN_MARK_ADD|FAN_MARK_DONT_FOLLOW, FAN_CLOSE_WRITE, -1LL, fname);
86 //staptest// fanotify_mark (-1, FAN_MARK_ADD|FAN_MARK_DONT_FOLLOW, FAN_CLOSE_WRITE, -1, "testfile") = -NNNN
87
88 fanotify_mark(-1, FAN_MARK_ADD|FAN_MARK_MOUNT, FAN_CLOSE_NOWRITE, AT_FDCWD, (char *)-1);
89 #ifdef __s390__
90 //staptest// fanotify_mark (-1, FAN_MARK_ADD|FAN_MARK_MOUNT, FAN_CLOSE_NOWRITE, AT_FDCWD, 0x[7]?[f]+) = -NNNN
91 #else
92 //staptest// fanotify_mark (-1, FAN_MARK_ADD|FAN_MARK_MOUNT, FAN_CLOSE_NOWRITE, AT_FDCWD, 0x[f]+) = -NNNN
93 #endif
94
95 return 0;
96 }
97
98 #else
99 int main()
100 {
101 return 0;
102 }
103 #endif