From dec3392af2c5eff92c9dd702bd324feafc979d3f Mon Sep 17 00:00:00 2001 From: Tristan Riehs Date: Sat, 11 Nov 2023 20:49:39 +0100 Subject: stdin copied only if it contains data --- rpt.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/rpt.c b/rpt.c index 327b8b8..c72aeab 100644 --- a/rpt.c +++ b/rpt.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -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); -- cgit v1.2.3