Skip to content

Commit

Permalink
fix ineffective 'output' config
Browse files Browse the repository at this point in the history
  • Loading branch information
six-ddc committed Oct 26, 2017
1 parent e4fad4d commit 7f1dcfe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion command/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ config_set(int argc, const char **argv) {
if (pconfig->output_file) {
string_free(pconfig->output_file);
}
pconfig->output_file = argc < 3 ? NULL : new_string(argv[2]);
if (argc < 3 || strcmp(argv[2], "-") == 0) {
pconfig->output_file = NULL;
} else {
pconfig->output_file = new_string(argv[2]);
}
} else if (strcmp(argv[1], "common-options") == 0) {
if (argc < 3) {
pconfig->common_options_argc = 0;
Expand Down
14 changes: 13 additions & 1 deletion executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,15 @@ exec_command_foreach(struct slot *pslot_list, void (*fn_fork)(struct slot *, int

memset(&no_timeout, 0, sizeof(struct timeval));

output = stdout;
if (pconfig->output_file) {
output = fopen(pconfig->output_file, "a");
if (!output) {
eprintf("can not open file %s (%s)\n", pconfig->output_file, strerror(errno));
return -1;
}
} else {
output = stdout;
}

alive_children = 0;

Expand All @@ -354,6 +362,10 @@ exec_command_foreach(struct slot *pslot_list, void (*fn_fork)(struct slot *, int

read_dead_slots(pslot_head, pslot, output);

if (output != stdout) {
fclose(output);
}

return 0;
}

Expand Down

0 comments on commit 7f1dcfe

Please sign in to comment.