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 <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
This commit is contained in:
parent
404ee42706
commit
d4f3a42ec7
@ -61,12 +61,14 @@ int platform_init(int argc, char **argv) {
|
|||||||
/* Make sure that all stdio output of the processes is buffered up. */
|
/* 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) {
|
int process_start(char* name, char* part, process_info_t* p, int is_helper) {
|
||||||
FILE* stdout_file;
|
FILE* stdout_file;
|
||||||
|
int stdout_fd;
|
||||||
const char* arg;
|
const char* arg;
|
||||||
char* args[16];
|
char* args[16];
|
||||||
int n;
|
int n;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
stdout_file = tmpfile();
|
stdout_file = tmpfile();
|
||||||
|
stdout_fd = fileno(stdout_file);
|
||||||
if (!stdout_file) {
|
if (!stdout_file) {
|
||||||
perror("tmpfile");
|
perror("tmpfile");
|
||||||
return -1;
|
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++] = part;
|
||||||
args[n++] = NULL;
|
args[n++] = NULL;
|
||||||
|
|
||||||
dup2(fileno(stdout_file), STDOUT_FILENO);
|
dup2(stdout_fd, STDOUT_FILENO);
|
||||||
dup2(fileno(stdout_file), STDERR_FILENO);
|
dup2(stdout_fd, STDERR_FILENO);
|
||||||
execvp(args[0], args);
|
execvp(args[0], args);
|
||||||
perror("execvp()");
|
perror("execvp()");
|
||||||
_exit(127);
|
_exit(127);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user