diff options
Diffstat (limited to 'rpt.c')
-rw-r--r-- | rpt.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -17,7 +17,7 @@ /* Clone of stdin. Used to perform lseek(2) calls between each child process. */ -FILE *stdin_clone; +FILE *stdin_clone = NULL; /* File descriptor associated to the clone of stdin. */ int clone_fd; @@ -69,12 +69,15 @@ exec_child(char **argv) { int status; - status = lseek(clone_fd, 0, L_SET); - - if (status < 0) + if (stdin_clone) { - perror("rpt[child process]"); - exit(4); + status = lseek(clone_fd, 0, L_SET); + + if (status < 0) + { + perror("rpt[child process]"); + exit(4); + } } status = dup2(clone_fd, STDIN_FILENO); @@ -240,6 +243,8 @@ main(int argc, char* argv[]) repeat_cmd(argv + optind, count, handle_error_f); - fclose(stdin_clone); + if (stdin_clone) + fclose(stdin_clone); + return 0; } |