From d4f3a42ec74e8596fb88c1c56db57a86cc6470bb Mon Sep 17 00:00:00 2001 From: John Barboza Date: Wed, 31 May 2017 06:08:44 -0400 Subject: [PATCH] unix,benchmark: use fd instead of FILE* after fork The FILE* object is not guaranteed to be in the same state after a fork. Instead store the file descriptor instead and use that in the child process. PR-URL: https://github.com/libuv/libuv/pull/1369 Reviewed-By: Ben Noordhuis Reviewed-By: Santiago Gimeno --- test/runner-unix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/runner-unix.c b/test/runner-unix.c index 2ff18ce7..3167ed44 100644 --- a/test/runner-unix.c +++ b/test/runner-unix.c @@ -61,12 +61,14 @@ int platform_init(int argc, char **argv) { /* Make sure that all stdio output of the processes is buffered up. */ int process_start(char* name, char* part, process_info_t* p, int is_helper) { FILE* stdout_file; + int stdout_fd; const char* arg; char* args[16]; int n; pid_t pid; stdout_file = tmpfile(); + stdout_fd = fileno(stdout_file); if (!stdout_file) { perror("tmpfile"); return -1; @@ -103,8 +105,8 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { args[n++] = part; args[n++] = NULL; - dup2(fileno(stdout_file), STDOUT_FILENO); - dup2(fileno(stdout_file), STDERR_FILENO); + dup2(stdout_fd, STDOUT_FILENO); + dup2(stdout_fd, STDERR_FILENO); execvp(args[0], args); perror("execvp()"); _exit(127);