All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] inotify11: Fix race condition between fork() and inotify init
@ 2022-09-08 14:50 Martin Doucha
  2022-09-08 15:15 ` Amir Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Doucha @ 2022-09-08 14:50 UTC (permalink / raw)
  To: ltp

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>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] inotify11: Fix race condition between fork() and inotify init
  2022-09-08 14:50 [LTP] [PATCH] inotify11: Fix race condition between fork() and inotify init Martin Doucha
@ 2022-09-08 15:15 ` Amir Goldstein
  2022-09-09  7:44   ` Petr Vorel
  0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2022-09-08 15:15 UTC (permalink / raw)
  To: Martin Doucha; +Cc: LTP List

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] inotify11: Fix race condition between fork() and inotify init
  2022-09-08 15:15 ` Amir Goldstein
@ 2022-09-09  7:44   ` Petr Vorel
  0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2022-09-09  7:44 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: LTP List

Hi all,

thanks, merged!

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-09  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-08 14:50 [LTP] [PATCH] inotify11: Fix race condition between fork() and inotify init Martin Doucha
2022-09-08 15:15 ` Amir Goldstein
2022-09-09  7:44   ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.