@@ -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"},
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(-) -- 2.17.1