All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] accept02: Add SAFE_FORK to clean CLOSE_WAIT fds
@ 2022-03-23  9:49 Zhao Gongyi via ltp
  2022-03-23 15:06 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Zhao Gongyi via ltp @ 2022-03-23  9:49 UTC (permalink / raw)
  To: ltp

If we run the test with option -i 1000, and the ulimit
of open files little than 1000, the test would fail and
report the error of EMFILE. We can see that the socket
fds are in the status of CLOSE_WAIT.

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 testcases/kernel/syscalls/accept/accept02.c | 25 ++++++++++++++-------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/testcases/kernel/syscalls/accept/accept02.c b/testcases/kernel/syscalls/accept/accept02.c
index 12a1e3ca3..d46293386 100644
--- a/testcases/kernel/syscalls/accept/accept02.c
+++ b/testcases/kernel/syscalls/accept/accept02.c
@@ -23,6 +23,8 @@

 #include <errno.h>
 #include <sys/socket.h>
+#include <sys/wait.h>
+#include <stdlib.h>
 #include "tst_test.h"
 #include "tst_safe_net.h"
 #include "tst_safe_pthread.h"
@@ -92,17 +94,23 @@ static void *client_thread(void *arg)

 static void run(void)
 {
-	pthread_t server_thr, client_thr;
+	pid_t child = SAFE_FORK();
+	if (!child) {
+		pthread_t server_thr, client_thr;

-	server_addr->sin_port = server_port;
-	client_addr->sin_port = htons(0);
+		server_addr->sin_port = server_port;
+		client_addr->sin_port = htons(0);

-	SAFE_PTHREAD_CREATE(&server_thr, NULL, server_thread, NULL);
-	TST_CHECKPOINT_WAIT(0);
-	SAFE_PTHREAD_CREATE(&client_thr, NULL, client_thread, NULL);
+		SAFE_PTHREAD_CREATE(&server_thr, NULL, server_thread, NULL);
+		TST_CHECKPOINT_WAIT(0);
+		SAFE_PTHREAD_CREATE(&client_thr, NULL, client_thread, NULL);

-	SAFE_PTHREAD_JOIN(server_thr, NULL);
-	SAFE_PTHREAD_JOIN(client_thr, NULL);
+		SAFE_PTHREAD_JOIN(server_thr, NULL);
+		SAFE_PTHREAD_JOIN(client_thr, NULL);
+		exit(0);
+	}
+
+	SAFE_WAIT(NULL);
 }

 static void setup(void)
@@ -145,6 +153,7 @@ static struct tst_test test = {
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_checkpoints = 1,
+	.forks_child = 1,
 	.tags = (const struct tst_tag[]) {
 		{"CVE", "2017-8890"},
 		{"linux-git", "657831ff"},
--
2.17.1


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

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

* Re: [LTP] [PATCH] accept02: Add SAFE_FORK to clean CLOSE_WAIT fds
  2022-03-23  9:49 [LTP] [PATCH] accept02: Add SAFE_FORK to clean CLOSE_WAIT fds Zhao Gongyi via ltp
@ 2022-03-23 15:06 ` Cyril Hrubis
  0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2022-03-23 15:06 UTC (permalink / raw)
  To: Zhao Gongyi; +Cc: ltp

Hi!
As far as I can tell we should rather close the fd returned from the
accept() call like this:

diff --git a/testcases/kernel/syscalls/accept/accept02.c b/testcases/kernel/syscalls/accept/accept02.c
index 12a1e3ca3..b2d27a260 100644
--- a/testcases/kernel/syscalls/accept/accept02.c
+++ b/testcases/kernel/syscalls/accept/accept02.c
@@ -68,6 +68,8 @@ static void *server_thread(void *arg)
        TEST(setsockopt(clone_server_sockfd, SOL_IP, MCAST_LEAVE_GROUP,
                        mc_group, mc_group_len));

+       SAFE_CLOSE(clone_server_sockfd);
+
        if (TST_RET != -1)
                tst_res(TFAIL, "Multicast group was copied!");
        else if (TST_ERR == EADDRNOTAVAIL)


-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH] accept02: Add SAFE_FORK to clean CLOSE_WAIT fds
@ 2022-03-24  2:27 zhaogongyi via ltp
  0 siblings, 0 replies; 3+ messages in thread
From: zhaogongyi via ltp @ 2022-03-24  2:27 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hi Cyril,

Thanks for your review! Yes, I cann't the clone_server_sockfd is not closed before, 
and I will resubmit a patch, please see: https://patchwork.ozlabs.org/project/ltp/patch/20220324022455.245300-1-zhaogongyi@huawei.com/

Best regards,

Gongyi

> 
> Hi!
> As far as I can tell we should rather close the fd returned from the
> accept() call like this:
> 
> diff --git a/testcases/kernel/syscalls/accept/accept02.c
> b/testcases/kernel/syscalls/accept/accept02.c
> index 12a1e3ca3..b2d27a260 100644
> --- a/testcases/kernel/syscalls/accept/accept02.c
> +++ b/testcases/kernel/syscalls/accept/accept02.c
> @@ -68,6 +68,8 @@ static void *server_thread(void *arg)
>         TEST(setsockopt(clone_server_sockfd, SOL_IP,
> MCAST_LEAVE_GROUP,
>                         mc_group, mc_group_len));
> 
> +       SAFE_CLOSE(clone_server_sockfd);
> +
>         if (TST_RET != -1)
>                 tst_res(TFAIL, "Multicast group was copied!");
>         else if (TST_ERR == EADDRNOTAVAIL)
> 
> 
> --
> Cyril Hrubis
> chrubis@suse.cz

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

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

end of thread, other threads:[~2022-03-24  2:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23  9:49 [LTP] [PATCH] accept02: Add SAFE_FORK to clean CLOSE_WAIT fds Zhao Gongyi via ltp
2022-03-23 15:06 ` Cyril Hrubis
2022-03-24  2:27 zhaogongyi via ltp

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.