Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/lib/libcurses tests/libcurses: fix child process handling
details: https://anonhg.NetBSD.org/src/rev/ad0b86c500c3
branches: trunk
changeset: 952339:ad0b86c500c3
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Feb 13 09:18:12 2021 +0000
description:
tests/libcurses: fix child process handling
The child process needs to be properly controlled by the parent process.
Otherwise it is not possible to get code coverage data from it using
gcov since that requires the child process to exit normally. Previously
the child process had been killed because its parent had exited.
diffstat:
tests/lib/libcurses/director/director.c | 12 ++++++++++--
tests/lib/libcurses/slave/slave.c | 7 +++++--
2 files changed, 15 insertions(+), 4 deletions(-)
diffs (67 lines):
diff -r 7640e3f42c04 -r ad0b86c500c3 tests/lib/libcurses/director/director.c
--- a/tests/lib/libcurses/director/director.c Sat Feb 13 08:43:03 2021 +0000
+++ b/tests/lib/libcurses/director/director.c Sat Feb 13 09:18:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: director.c,v 1.27 2021/02/13 08:26:12 rillig Exp $ */
+/* $NetBSD: director.c,v 1.28 2021/02/13 09:18:12 rillig Exp $ */
/*-
* Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -31,6 +31,7 @@
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/mman.h>
+#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
@@ -72,7 +73,7 @@
* output in verbose mode, truncating the useful part of the error message.
*/
static void
-slave_died(int param)
+slave_died(int signo)
{
char last_words[256];
size_t count;
@@ -276,5 +277,12 @@
yyparse();
fclose(yyin);
+ signal(SIGCHLD, SIG_DFL);
+ (void)close(to_slave);
+ (void)close(from_slave);
+
+ int status;
+ (void)waitpid(slave_pid, &status, 0);
+
exit(0);
}
diff -r 7640e3f42c04 -r ad0b86c500c3 tests/lib/libcurses/slave/slave.c
--- a/tests/lib/libcurses/slave/slave.c Sat Feb 13 08:43:03 2021 +0000
+++ b/tests/lib/libcurses/slave/slave.c Sat Feb 13 09:18:12 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: slave.c,v 1.13 2021/02/13 08:17:15 rillig Exp $ */
+/* $NetBSD: slave.c,v 1.14 2021/02/13 09:18:12 rillig Exp $ */
/*-
* Copyright 2009 Brett Lymn <blymn%NetBSD.org@localhost>
@@ -59,14 +59,17 @@
{
int len, maxlen, argslen, i, ret, type;
char *cmdbuf, *tmpbuf, **args, **tmpargs;
+ ssize_t nread;
len = maxlen = 30;
if ((cmdbuf = malloc(maxlen)) == NULL)
err(1, "slave cmdbuf malloc failed");
for (;;) {
- if (read(from_director, &type, sizeof(int)) < 0)
+ if ((nread = read(from_director, &type, sizeof(int))) < 0)
err(1, "slave command type read failed");
+ if (nread == 0)
+ break;
if (type != data_string)
errx(1, "Unexpected type for command, got %d", type);
Home |
Main Index |
Thread Index |
Old Index