From: Masatake YAMATO Date: Mon, 2 Oct 2023 12:44:13 +0000 (+0900) Subject: tests: (test_mkfds::socketpair) add "halfclose" parameter X-Git-Tag: v2.40-rc1~210^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef46aa41a12bc34480c305f7d30c8ce2e7fe9781;p=thirdparty%2Futil-linux.git tests: (test_mkfds::socketpair) add "halfclose" parameter Signed-off-by: Masatake YAMATO --- diff --git a/tests/helpers/test_mkfds.c b/tests/helpers/test_mkfds.c index db61727e2c..8a1388adff 100644 --- a/tests/helpers/test_mkfds.c +++ b/tests/helpers/test_mkfds.c @@ -894,6 +894,12 @@ static void *make_socketpair(const struct factory *factory, struct fdesc fdescs[ int sd[2]; struct arg socktype = decode_arg("socktype", factory->params, argc, argv); int isocktype; + struct arg halfclose = decode_arg("halfclose", factory->params, argc, argv); + bool bhalfclose; + + bhalfclose = ARG_BOOLEAN(halfclose); + free_arg(&halfclose); + if (strcmp(ARG_STRING(socktype), "STREAM") == 0) isocktype = SOCK_STREAM; else if (strcmp(ARG_STRING(socktype), "DGRAM") == 0) @@ -909,6 +915,15 @@ static void *make_socketpair(const struct factory *factory, struct fdesc fdescs[ if (socketpair(AF_UNIX, isocktype, 0, sd) < 0) err(EXIT_FAILURE, "failed to make socket pair"); + if (bhalfclose) { + if (shutdown(sd[0], SHUT_RD) < 0) + err(EXIT_FAILURE, + "failed to shutdown the read end of the 1st socket"); + if (shutdown(sd[1], SHUT_WR) < 0) + err(EXIT_FAILURE, + "failed to shutdown the write end of the 2nd socket"); + } + for (int i = 0; i < 2; i++) { if (sd[i] != fdescs[i].fd) { if (dup2(sd[i], fdescs[i].fd) < 0) { @@ -3160,6 +3175,12 @@ static const struct factory factories[] = { .desc = "STREAM, DGRAM, or SEQPACKET", .defv.string = "STREAM", }, + { + .name = "halfclose", + .type = PTYPE_BOOLEAN, + .desc = "Shutdown the read end of the 1st socket, the write end of the 2nd socket", + .defv.boolean = false, + }, PARAM_END }, },