From ed30f5e285adc4b15875f2b8147571cf3d88f823 Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Sat, 11 Nov 2023 20:53:53 +0100 Subject: empty stdin behaviour fixed --- rpt.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/rpt.c b/rpt.c index b6d65be..6642491 100644 --- a/rpt.c +++ b/rpt.c @@ -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; } -- cgit v1.2.3