From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: mtk.manpages@gmail.com, Jan Kara <jack@suse.cz>,
Matthew Bobrowski <mbobrowski@mbobrowski.org>,
linux-man@vger.kernel.org
Subject: Re: [PATCH 3/4] fanotify.7: Fix fanotify_fid.c example
Date: Mon, 20 Apr 2020 21:06:08 +0200 [thread overview]
Message-ID: <6ff6c52a-bd6b-754b-2efd-9f63b91b554e@gmail.com> (raw)
In-Reply-To: <20200420184259.29406-4-amir73il@gmail.com>
On 4/20/20 8:42 PM, Amir Goldstein wrote:
> - 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.
Thanks, Amir. Patch applied.
Cheers,
Michael
>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> Reviewed-by: Matthew Bobrowski <mbobrowski@mbobrowski.org>
> Reviewed-by: Jan Kara <jack@suse.cz>
> ---
> 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",
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
next prev parent reply other threads:[~2020-04-20 19:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 18:42 [PATCH 0/4] fanotify updates for v5.7 Amir Goldstein
2020-04-20 18:42 ` [PATCH 1/4] fanotify_mark.2: Clarification about FAN_MARK_MOUNT and FAN_REPORT_FID Amir Goldstein
2020-04-20 19:00 ` Michael Kerrisk (man-pages)
2020-04-20 18:42 ` [PATCH 2/4] fanotify_mark.2: Clarification about FAN_EVENT_ON_CHILD and new events Amir Goldstein
2020-04-20 19:03 ` Michael Kerrisk (man-pages)
2020-04-20 18:42 ` [PATCH 3/4] fanotify.7: Fix fanotify_fid.c example Amir Goldstein
2020-04-20 19:06 ` Michael Kerrisk (man-pages) [this message]
2020-04-20 18:42 ` [PATCH 4/4] fanotify.7, fanotify_mark.2: Document FAN_DIR_MODIFY Amir Goldstein
2020-04-20 19:25 ` Michael Kerrisk (man-pages)
2020-04-20 19:36 ` [PATCH 0/4] fanotify updates for v5.7 Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6ff6c52a-bd6b-754b-2efd-9f63b91b554e@gmail.com \
--to=mtk.manpages@gmail.com \
--cc=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=linux-man@vger.kernel.org \
--cc=mbobrowski@mbobrowski.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).