From 9e8399f716836b595976d44cb2c375c227f92f57 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 1 Dec 2016 00:26:30 +0000 Subject: [PATCH] =?utf8?q?regress:=20fuzz:=20Send=20rc=3D=3F=20msg=20to=20?= =?utf8?q?stdout?= We need a copy, because the test program may close it Signed-off-by: Ian Jackson --- regress/hfuzz.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/regress/hfuzz.c b/regress/hfuzz.c index 467f025..4b50066 100644 --- a/regress/hfuzz.c +++ b/regress/hfuzz.c @@ -45,7 +45,7 @@ FILE *Hfopen(const char *path, const char *mode) { static int t_argc; static char **t_argv; -static FILE *t_stdin; +static FILE *t_stdin, *stdoutcopy; static int t_sys_fd; static int bail(const char *msg) { @@ -85,7 +85,8 @@ int Ttestinputfd(void) { } void Texit(int rv) { - fprintf(stderr,"**Texit(%d)**\n",rv); + fprintf(stdoutcopy,"rc=%d\n",rv); + if (ferror(stdoutcopy) || fclose(stdoutcopy)) baile("flush rc msg"); Tcommonshutdown(); exit(0); } @@ -96,6 +97,11 @@ int main(int argc, char **argv) { if (argc!=1) bail("usage: *_fuzz (no arguments)"); + int stdoutcopyfd= dup(1); + if (stdoutcopyfd<0) baile("dup 1 again"); + stdoutcopy= fdopen(stdoutcopyfd,"w"); + if (!stdoutcopy) baile("fdopen 1 again"); + t_argc = getint(50); t_argv = calloc(t_argc+1, sizeof(*t_argv)); for (i=0; i