Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libcurses/director tests/libcurses: fix pipe handl...



details:   https://anonhg.NetBSD.org/src/rev/c363f100a970
branches:  trunk
changeset: 959405:c363f100a970
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 13 07:08:45 2021 +0000

description:
tests/libcurses: fix pipe handling in the parent process

The parent process, like the child process, needs only 2 of the 4 pipe
ends.

In verbose mode (now at testlang_parse.y:1151 and :1154), both ends of the
pipe_from_slave were examined.  This looked like a typo and has been fixed
to those pipe ends that are relevant to the parent process.

diffstat:

 tests/lib/libcurses/director/director.c       |  24 +++++++++++++--------
 tests/lib/libcurses/director/director.h       |   7 ++++-
 tests/lib/libcurses/director/testlang_parse.y |  29 +++++++++++---------------
 3 files changed, 32 insertions(+), 28 deletions(-)

diffs (214 lines):

diff -r 1999cdc52f9e -r c363f100a970 tests/lib/libcurses/director/director.c
--- a/tests/lib/libcurses/director/director.c   Sat Feb 13 06:45:42 2021 +0000
+++ b/tests/lib/libcurses/director/director.c   Sat Feb 13 07:08:45 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: director.c,v 1.20 2021/02/13 06:45:42 rillig Exp $     */
+/*     $NetBSD: director.c,v 1.21 2021/02/13 07:08:45 rillig Exp $     */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -55,8 +55,8 @@
 
 extern size_t nvars;   /* In testlang_conf.y */
 saved_data_t  saved_output;    /* In testlang_conf.y */
-int cmdpipe[2];                /* command pipe between director and slave */
-int slvpipe[2];                /* reply pipe back from slave */
+int to_slave;
+int from_slave;
 int master;            /* pty to the slave */
 int verbose;           /* control verbosity of tests */
 int check_file_flag;           /* control checkfile generation */
@@ -136,6 +136,7 @@
        char *arg1, *arg2;
        struct termios term_attr;
        struct stat st;
+       int pipe_to_slave[2], pipe_from_slave[2];
 
        termpath = term = slave = NULL;
        verbose = 0;
@@ -238,11 +239,13 @@
                munmap(tinfo, (size_t)st.st_size);
        }
 
-       if (pipe(cmdpipe) < 0)
+       if (pipe(pipe_to_slave) < 0)
                err(1, "Command pipe creation failed");
+       to_slave = pipe_to_slave[1];
 
-       if (pipe(slvpipe) < 0)
+       if (pipe(pipe_from_slave) < 0)
                err(1, "Slave pipe creation failed");
+       from_slave = pipe_from_slave[0];
 
        /*
         * Create default termios settings for later use
@@ -261,12 +264,12 @@
 
        if (slave_pid == 0) {
                /* slave side, just exec the slave process */
-               if (asprintf(&arg1, "%d", cmdpipe[0]) < 0)
+               if (asprintf(&arg1, "%d", pipe_to_slave[0]) < 0)
                        err(1, "arg1 conversion failed");
-               close(cmdpipe[1]);
+               close(pipe_to_slave[1]);
 
-               close(slvpipe[0]);
-               if (asprintf(&arg2, "%d", slvpipe[1]) < 0)
+               close(pipe_from_slave[0]);
+               if (asprintf(&arg2, "%d", pipe_from_slave[1]) < 0)
                        err(1, "arg2 conversion failed");
 
                if (execl(slave, slave, arg1, arg2, (char *)0) < 0)
@@ -275,6 +278,9 @@
                /* NOT REACHED */
        }
 
+       (void)close(pipe_to_slave[0]);
+       (void)close(pipe_from_slave[1]);
+
        fcntl(master, F_SETFL, O_NONBLOCK);
 
        if ((yyin = fopen(argv[0], "r")) == NULL)
diff -r 1999cdc52f9e -r c363f100a970 tests/lib/libcurses/director/director.h
--- a/tests/lib/libcurses/director/director.h   Sat Feb 13 06:45:42 2021 +0000
+++ b/tests/lib/libcurses/director/director.h   Sat Feb 13 07:08:45 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: director.h,v 1.2 2021/02/08 19:15:20 rillig Exp $      */
+/*     $NetBSD: director.h,v 1.3 2021/02/13 07:08:45 rillig Exp $      */
 
 /*-
  * Copyright 2020 Naman Jain <jnaman806%gmail.com@localhost>, this code was
@@ -30,9 +30,12 @@
  *
  */
 #ifndef DIRECTOR_H
-#define DIRECTOR_H 1
+#define DIRECTOR_H
 
 #define GEN_CHECK_FILE 1
 #define FORCE_GEN 2
 
+extern int to_slave;
+extern int from_slave;
+
 #endif /* DIRECTOR_H */
diff -r 1999cdc52f9e -r c363f100a970 tests/lib/libcurses/director/testlang_parse.y
--- a/tests/lib/libcurses/director/testlang_parse.y     Sat Feb 13 06:45:42 2021 +0000
+++ b/tests/lib/libcurses/director/testlang_parse.y     Sat Feb 13 07:08:45 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: testlang_parse.y,v 1.44 2021/02/09 20:42:31 rillig Exp $       */
+/*     $NetBSD: testlang_parse.y,v 1.45 2021/02/13 07:08:45 rillig Exp $       */
 
 /*-
  * Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -51,8 +51,6 @@
 
 extern int verbose;
 extern int check_file_flag;
-extern int cmdpipe[2];
-extern int slvpipe[2];
 extern int master;
 extern struct pollfd readfd;
 extern char *check_path;
@@ -84,9 +82,6 @@
 static wchar_t *vals = NULL;   /* wchars to attach to a cchar type */
 static unsigned nvals;         /* number of wchars */
 
-#define READ_PIPE  0
-#define WRITE_PIPE 1
-
 const char *enum_names[] = {
        "unused", "static", "numeric", "string", "byte", "cchar", "wchar", "ERR",
        "OK", "NULL", "not NULL", "variable", "reference", "returns count",
@@ -1110,7 +1105,7 @@
                        errx(2, "%s:%zu: Call to input function "
                            "but no input defined", cur_file, line);
 
-               fds[0].fd = slvpipe[READ_PIPE];
+               fds[0].fd = from_slave;
                fds[0].events = POLLIN;
                fds[1].fd = master;
                fds[1].events = POLLOUT;
@@ -1153,10 +1148,10 @@
        }
 
        if (verbose) {
-               fds[0].fd = slvpipe[READ_PIPE];
+               fds[0].fd = to_slave;
                fds[0].events = POLLIN;
 
-               fds[1].fd = slvpipe[WRITE_PIPE];
+               fds[1].fd = from_slave;
                fds[1].events = POLLOUT;
 
                fds[2].fd = master;
@@ -1973,7 +1968,7 @@
                    enum_names[send_type]);
        }
 
-       if (write(cmdpipe[WRITE_PIPE], &send_type, sizeof(int)) < 0)
+       if (write(to_slave, &send_type, sizeof(int)) < 0)
                err(1, "command pipe write for type failed");
 
        if (verbose) {
@@ -1988,7 +1983,7 @@
                            "Writing length %d to command pipe\n", len);
        }
 
-       if (write(cmdpipe[WRITE_PIPE], &len, sizeof(int)) < 0)
+       if (write(to_slave, &len, sizeof(int)) < 0)
                err(1, "command pipe write for length failed");
 
        if (len > 0) {
@@ -1996,7 +1991,7 @@
                        fprintf(stderr, "Writing data >%s< to command pipe\n",
                            (const char *)cmd);
                }
-               if (write(cmdpipe[WRITE_PIPE], cmd, len) < 0)
+               if (write(to_slave, cmd, len) < 0)
                        err(1, "command pipe write of data failed");
        }
 }
@@ -2018,7 +2013,7 @@
         * output from the slave because the slave may be blocked waiting
         * for a flush on its stdout.
         */
-       rfd[0].fd = slvpipe[READ_PIPE];
+       rfd[0].fd = from_slave;
        rfd[0].events = POLLIN;
        rfd[1].fd = master;
        rfd[1].events = POLLIN;
@@ -2038,12 +2033,12 @@
        }
        while ((rfd[1].revents & POLLIN) == POLLIN);
 
-       if (read(slvpipe[READ_PIPE], &type, sizeof(int)) < 0)
+       if (read(from_slave, &type, sizeof(int)) < 0)
                err(1, "command pipe read for type failed");
        response->data_type = type;
 
        if ((type != data_ok) && (type != data_err) && (type != data_count)) {
-               if (read(slvpipe[READ_PIPE], &len, sizeof(int)) < 0)
+               if (read(from_slave, &len, sizeof(int)) < 0)
                        err(1, "command pipe read for length failed");
                response->data_len = len;
 
@@ -2055,7 +2050,7 @@
                if ((response->data_value = malloc(len + 1)) == NULL)
                        err(1, "Failed to alloc memory for cmd pipe read");
 
-               if (read(slvpipe[READ_PIPE], response->data_value, len) < 0)
+               if (read(from_slave, response->data_value, len) < 0)
                        err(1, "command pipe read of data failed");
 
                if (response->data_type != data_byte) {
@@ -2070,7 +2065,7 @@
        } else {
                response->data_value = NULL;
                if (type == data_count) {
-                       if (read(slvpipe[READ_PIPE], &len, sizeof(int)) < 0)
+                       if (read(from_slave, &len, sizeof(int)) < 0)
                                err(1, "command pipe read for number of "
                                       "returns failed");
                        response->data_len = len;



Home | Main Index | Thread Index | Old Index