aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@bordeaux-inp.fr>2023-11-11 20:53:53 +0100
committerTristan Riehs <tristan.riehs@bordeaux-inp.fr>2023-11-11 20:54:21 +0100
commited30f5e285adc4b15875f2b8147571cf3d88f823 (patch)
treefdca267b100a1c26b5da2519642b76efc353e408
parent523f2de65f9cd04c2d116ef7aa1172af99c1b915 (diff)
empty stdin behaviour fixed
-rw-r--r--rpt.c19
1 files 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;
}