test: fix test runner getenv async-signal-safety

getenv() and atoi() are not safe to call between fork() and execve()
so call them before forking.

PR-URL: https://github.com/libuv/libuv/pull/2056
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
Ben Noordhuis 2018-10-29 11:58:39 +01:00
parent b901e2620c
commit c3cbab991b

View File

@ -67,25 +67,6 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
int n;
pid_t pid;
stdout_file = tmpfile();
stdout_fd = fileno(stdout_file);
if (!stdout_file) {
perror("tmpfile");
return -1;
}
p->terminated = 0;
p->status = 0;
pid = fork();
if (pid < 0) {
perror("fork");
return -1;
}
if (pid == 0) {
/* child */
arg = getenv("UV_USE_VALGRIND");
n = 0;
@ -105,6 +86,25 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
args[n++] = part;
args[n++] = NULL;
stdout_file = tmpfile();
stdout_fd = fileno(stdout_file);
if (!stdout_file) {
perror("tmpfile");
return -1;
}
p->terminated = 0;
p->status = 0;
pid = fork();
if (pid < 0) {
perror("fork");
return -1;
}
if (pid == 0) {
/* child */
dup2(stdout_fd, STDOUT_FILENO);
dup2(stdout_fd, STDERR_FILENO);
execvp(args[0], args);