[LTP] [PATCH] inotify11: Fix race condition between fork() and inotify init
Amir Goldstein
amir73il@gmail.com
Thu Sep 8 17:15:07 CEST 2022
On Thu, Sep 8, 2022 at 5:50 PM Martin Doucha <mdoucha@suse.cz> wrote:
>
> When the child process runs a few churn cycles before the parent completes
> inotify initialization, the parent will get stuck reading the inotify
> file descriptor until it eventually times out. Create inotify watch
> befory fork()ing to prevent this race condition.
>
> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
LGTM
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> ---
> testcases/kernel/syscalls/inotify/inotify11.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/inotify/inotify11.c b/testcases/kernel/syscalls/inotify/inotify11.c
> index e426f9e1c..dd32ea7fd 100644
> --- a/testcases/kernel/syscalls/inotify/inotify11.c
> +++ b/testcases/kernel/syscalls/inotify/inotify11.c
> @@ -61,15 +61,16 @@ static void verify_inotify(void)
> struct inotify_event *event;
> int inotify_fd;
>
> + inotify_fd = SAFE_MYINOTIFY_INIT();
> + SAFE_MYINOTIFY_ADD_WATCH(inotify_fd, ".", IN_DELETE);
> +
> pid = SAFE_FORK();
> if (pid == 0) {
> + SAFE_CLOSE(inotify_fd);
> churn();
> return;
> }
>
> - inotify_fd = SAFE_MYINOTIFY_INIT();
> - SAFE_MYINOTIFY_ADD_WATCH(inotify_fd, ".", IN_DELETE);
> -
> while (!opened && nevents < CHURN_FILES) {
> int i, fd, len;
>
> --
> 2.37.2
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
More information about the ltp
mailing list