aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2020-04-20 21:42:58 +0300
committerMichael Kerrisk <mtk.manpages@gmail.com>2020-04-20 21:22:02 +0200
commit4e5351855283d068ccc0324c410f7b7466f71f40 (patch)
tree34934167b1843c91efac671237521f3f08c6a7a8
parent1f20a8803255df69a9b53d0bbd9ae4d99483a2a9 (diff)
downloadman-pages-4e5351855283d068ccc0324c410f7b7466f71f40.tar.gz
fanotify.7: Fix fanotify_fid.c example
- The condition for printing "subdirectory created" was always true. - The arguments and error check of open_by_handle_at() were incorrect. - Fix example description inconsistencies. - Nicer indentation of example output. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Matthew Bobrowski <mbobrowski@mbobrowski.org> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r--man7/fanotify.738
1 files changed, 22 insertions, 16 deletions
diff --git a/man7/fanotify.7 b/man7/fanotify.7
index eaf2acf251..72e7e4fb9f 100644
--- a/man7/fanotify.7
+++ b/man7/fanotify.7
@@ -938,21 +938,20 @@ This is followed by the creation of a regular file,
.IR /home/user/testfile.txt .
This results in a
.B FAN_CREATE
-event being created and reported against the file's parent watched
+event being generated and reported against the file's parent watched
directory object.
Program execution ends once all events captured within the buffer have
been processed.
-Program execution ends once all events captured within the buffer are
-processed.
.PP
.in +4n
.EX
# \fB./fanotify_fid /home/user\fP
Listening for events.
-FAN_CREATE (file created): Directory /home/user has been modified.
+FAN_CREATE (file created):
+ Directory /home/user has been modified.
All events processed successfully. Program exiting.
-$ \fBtouch /home/user/testing\fP # In another terminal
+$ \fBtouch /home/user/testfile.txt\fP # In another terminal
.EE
.in
.PP
@@ -960,11 +959,11 @@ The second session shows a mark being placed on
.IR /home/user .
This is followed by the creation of a directory,
.IR /home/user/testdir .
-This specific action results in the program producing a
+This specific action results in a
.B FAN_CREATE
-and
+event being generated and is reported with the
.B FAN_ONDIR
-event.
+flag set.
.PP
.in +4n
.EX
@@ -974,7 +973,7 @@ FAN_CREATE | FAN_ONDIR (subdirectory created):
Directory /home/user has been modified.
All events processed successfully. Program exiting.
-$ \fBmkdir \-p /home/user/testing\fP # In another terminal
+$ \fBmkdir \-p /home/user/testdir\fP # In another terminal
.EE
.in
.SS Program source: fanotify_fid.c
@@ -996,7 +995,7 @@ $ \fBmkdir \-p /home/user/testing\fP # In another terminal
int
main(int argc, char **argv)
{
- int fd, ret, event_fd;
+ int fd, ret, event_fd, mount_fd;
ssize_t len, path_len;
char path[PATH_MAX];
char procfd_path[PATH_MAX];
@@ -1010,6 +1009,13 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ mount_fd = open(argv[1], O_DIRECTORY | O_RDONLY);
+ if (mount_fd == \-1) {
+ perror(argv[1]);
+ exit(EXIT_FAILURE);
+ }
+
+
/* Create an fanotify file descriptor with FAN_REPORT_FID as a flag
so that program can receive fid events. */
@@ -1055,10 +1061,10 @@ main(int argc, char **argv)
}
if (metadata\->mask == FAN_CREATE)
- printf("FAN_CREATE (file created):");
+ printf("FAN_CREATE (file created):\en");
- if (metadata\->mask == FAN_CREATE | FAN_ONDIR)
- printf("FAN_CREATE | FAN_ONDIR (subdirectory created):");
+ if (metadata\->mask == (FAN_CREATE | FAN_ONDIR))
+ printf("FAN_CREATE | FAN_ONDIR (subdirectory created):\en");
/* metadata\->fd is set to FAN_NOFD when FAN_REPORT_FID is enabled.
To obtain a file descriptor for the file object corresponding to
@@ -1068,8 +1074,8 @@ main(int argc, char **argv)
to accommodate for the situation where the file handle for the
object was deleted prior to this system call. */
- event_fd = open_by_handle_at(AT_FDCWD, file_handle, O_RDONLY);
- if (ret == \-1) {
+ event_fd = open_by_handle_at(mount_fd, file_handle, O_RDONLY);
+ if (event_fd == \-1) {
if (errno == ESTALE) {
printf("File handle is no longer valid. "
"File has been deleted\en");
@@ -1077,7 +1083,7 @@ main(int argc, char **argv)
} else {
perror("open_by_handle_at");
exit(EXIT_FAILURE);
- }
+ }
}
snprintf(procfd_path, sizeof(procfd_path), "/proc/self/fd/%d",