[PATCH 3/4] fanotify.7: Fix fanotify_fid.c example

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- 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@xxxxxxxxx>
Reviewed-by: Matthew Bobrowski <mbobrowski@xxxxxxxxxxxxxx>
Reviewed-by: Jan Kara <jack@xxxxxxx>
---
 man7/fanotify.7 | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/man7/fanotify.7 b/man7/fanotify.7
index eaf2acf25..72e7e4fb9 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",
-- 
2.17.1




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux