diff options
author | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2023-11-11 20:53:53 +0100 |
---|---|---|
committer | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2023-11-11 20:54:21 +0100 |
commit | ed30f5e285adc4b15875f2b8147571cf3d88f823 (patch) | |
tree | fdca267b100a1c26b5da2519642b76efc353e408 /rpt.c | |
parent | 523f2de65f9cd04c2d116ef7aa1172af99c1b915 (diff) |
empty stdin behaviour fixed
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; } |