]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (test_mkfds::socketpair) add "halfclose" parameter
authorMasatake YAMATO <yamato@redhat.com>
Mon, 2 Oct 2023 12:44:13 +0000 (21:44 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Mon, 9 Oct 2023 06:37:35 +0000 (15:37 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/helpers/test_mkfds.c

index db61727e2c5386e758497b8982e7b88780f4074e..8a1388adff4763b284529876eca430c3b7630c24 100644 (file)
@@ -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
                },
        },