aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Riehs <tristan.riehs@bordeaux-inp.fr>2023-11-11 20:49:39 +0100
committerTristan Riehs <tristan.riehs@bordeaux-inp.fr>2023-11-11 20:49:39 +0100
commitdec3392af2c5eff92c9dd702bd324feafc979d3f (patch)
tree4e25ec6e26f5abbbefd6b399af3716c69880767a
parent1f9d41f0066b21aab14518dc4cbc7d8980efd9c4 (diff)
stdin copied only if it contains data
-rw-r--r--rpt.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/rpt.c b/rpt.c
index 327b8b8..c72aeab 100644
--- a/rpt.c
+++ b/rpt.c
@@ -3,6 +3,7 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
+#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
@@ -225,7 +226,18 @@ main(int argc, char* argv[])
return 3;
}
- copy_stdin();
+ struct pollfd pollfd = {.fd=STDIN_FILENO, .events=POLLIN, .revents=0};
+
+ if (poll(&pollfd, 1, 0) < 0)
+ {
+ fclose(stdin_clone);
+ perror("poll");
+ return 4;
+ }
+
+ if (pollfd.revents & POLLIN)
+ copy_stdin();
+
repeat_cmd(argv + optind, count, handle_error_f);
fclose(stdin_clone);