diff mbox series

syscalls/fanotify: Kill the child process before exit

Message ID 20211104121941.32957-1-zhaogongyi@huawei.com
State Changes Requested
Headers show
Series syscalls/fanotify: Kill the child process before exit | expand

Commit Message

Zhao Gongyi Nov. 4, 2021, 12:19 p.m. UTC
Before the main process exit abnormally, we need to kill
the child process.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 .../kernel/syscalls/fanotify/fanotify07.c     | 35 ++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

--
2.17.1

Comments

Petr Vorel Nov. 4, 2021, 6:37 p.m. UTC | #1
Hi all,

> Before the main process exit abnormally, we need to kill
> the child process.

Amir, Matthew, could you please have a look?

Kind regards,
Petr

> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>  .../kernel/syscalls/fanotify/fanotify07.c     | 35 ++++++++++++++++++-
>  1 file changed, 34 insertions(+), 1 deletion(-)

> diff --git a/testcases/kernel/syscalls/fanotify/fanotify07.c b/testcases/kernel/syscalls/fanotify/fanotify07.c
> index cc56d9019..0a0b4f1e4 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify07.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify07.c
> @@ -108,6 +108,39 @@ static int setup_instance(void)
>  	return fd;
>  }

> +static int setup_another_instance(void)
> +{
> +	int rval;
> +	int fd = fanotify_init(FAN_CLASS_CONTENT, O_RDONLY);
> +
> +	if (fd == -1) {
> +		stop_children();
> +		tst_brk(TBROK | TERRNO, "fanotify_init() failed");
> +	}
> +
> +	if (fd < -1) {
> +		stop_children();
> +		tst_brk(TBROK | TERRNO,
> +			"invalid fanotify_init() return %d", fd);
> +	}
> +
> +	rval = fanotify_mark(fd,
> +		FAN_MARK_ADD, FAN_ACCESS_PERM, AT_FDCWD, fname);
> +
> +	if (rval == -1) {
> +		stop_children();
> +		tst_brk(TBROK | TERRNO, "fanotify_mark() failed");
> +	}
> +
> +	if (rval < -1) {
> +		stop_children();
> +		tst_brk(TBROK | TERRNO,
> +			"invalid fanotify_mark() return %d", rval);
> +	}
> +
> +	return fd;
> +}
> +
>  static void loose_fanotify_events(void)
>  {
>  	int not_responded = 0;
> @@ -160,7 +193,7 @@ static void test_fanotify(void)
>  	 * Create and destroy another instance. This may hang if
>  	 * unanswered fanotify events block notification subsystem.
>  	 */
> -	newfd = setup_instance();
> +	newfd = setup_another_instance();

>  	SAFE_CLOSE(newfd);
Matthew Bobrowski Nov. 5, 2021, 1:40 a.m. UTC | #2
On Thu, Nov 04, 2021 at 07:37:35PM +0100, Petr Vorel wrote:
> Hi all,
> 
> > Before the main process exit abnormally, we need to kill
> > the child process.
> 
> Amir, Matthew, could you please have a look?

If anything, I feel as though stop_children() should probably be called
from cleanup() as that callback will be invoked if any of the
SAFE_FANOTIFY_* macros fail anyway, right?

I don't feel like there's a need to introduce another helper here to
explicitly handle the cleanup case, but I could also be wrong.

> > Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> > ---
> >  .../kernel/syscalls/fanotify/fanotify07.c     | 35 ++++++++++++++++++-
> >  1 file changed, 34 insertions(+), 1 deletion(-)
> 
> > diff --git a/testcases/kernel/syscalls/fanotify/fanotify07.c b/testcases/kernel/syscalls/fanotify/fanotify07.c
> > index cc56d9019..0a0b4f1e4 100644
> > --- a/testcases/kernel/syscalls/fanotify/fanotify07.c
> > +++ b/testcases/kernel/syscalls/fanotify/fanotify07.c
> > @@ -108,6 +108,39 @@ static int setup_instance(void)
> >  	return fd;
> >  }
> 
> > +static int setup_another_instance(void)
> > +{
> > +	int rval;
> > +	int fd = fanotify_init(FAN_CLASS_CONTENT, O_RDONLY);
> > +
> > +	if (fd == -1) {
> > +		stop_children();
> > +		tst_brk(TBROK | TERRNO, "fanotify_init() failed");
> > +	}
> > +
> > +	if (fd < -1) {
> > +		stop_children();
> > +		tst_brk(TBROK | TERRNO,
> > +			"invalid fanotify_init() return %d", fd);
> > +	}
> > +
> > +	rval = fanotify_mark(fd,
> > +		FAN_MARK_ADD, FAN_ACCESS_PERM, AT_FDCWD, fname);
> > +
> > +	if (rval == -1) {
> > +		stop_children();
> > +		tst_brk(TBROK | TERRNO, "fanotify_mark() failed");
> > +	}
> > +
> > +	if (rval < -1) {
> > +		stop_children();
> > +		tst_brk(TBROK | TERRNO,
> > +			"invalid fanotify_mark() return %d", rval);
> > +	}
> > +
> > +	return fd;
> > +}
> > +
> >  static void loose_fanotify_events(void)
> >  {
> >  	int not_responded = 0;
> > @@ -160,7 +193,7 @@ static void test_fanotify(void)
> >  	 * Create and destroy another instance. This may hang if
> >  	 * unanswered fanotify events block notification subsystem.
> >  	 */
> > -	newfd = setup_instance();
> > +	newfd = setup_another_instance();
> 
> >  	SAFE_CLOSE(newfd);

/M
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/fanotify/fanotify07.c b/testcases/kernel/syscalls/fanotify/fanotify07.c
index cc56d9019..0a0b4f1e4 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify07.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify07.c
@@ -108,6 +108,39 @@  static int setup_instance(void)
 	return fd;
 }

+static int setup_another_instance(void)
+{
+	int rval;
+	int fd = fanotify_init(FAN_CLASS_CONTENT, O_RDONLY);
+
+	if (fd == -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO, "fanotify_init() failed");
+	}
+
+	if (fd < -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO,
+			"invalid fanotify_init() return %d", fd);
+	}
+
+	rval = fanotify_mark(fd,
+		FAN_MARK_ADD, FAN_ACCESS_PERM, AT_FDCWD, fname);
+
+	if (rval == -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO, "fanotify_mark() failed");
+	}
+
+	if (rval < -1) {
+		stop_children();
+		tst_brk(TBROK | TERRNO,
+			"invalid fanotify_mark() return %d", rval);
+	}
+
+	return fd;
+}
+
 static void loose_fanotify_events(void)
 {
 	int not_responded = 0;
@@ -160,7 +193,7 @@  static void test_fanotify(void)
 	 * Create and destroy another instance. This may hang if
 	 * unanswered fanotify events block notification subsystem.
 	 */
-	newfd = setup_instance();
+	newfd = setup_another_instance();

 	SAFE_CLOSE(newfd);