diff options
author | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2023-11-11 20:49:39 +0100 |
---|---|---|
committer | Tristan Riehs <tristan.riehs@bordeaux-inp.fr> | 2023-11-11 20:49:39 +0100 |
commit | dec3392af2c5eff92c9dd702bd324feafc979d3f (patch) | |
tree | 4e25ec6e26f5abbbefd6b399af3716c69880767a | |
parent | 1f9d41f0066b21aab14518dc4cbc7d8980efd9c4 (diff) |
stdin copied only if it contains data
-rw-r--r-- | rpt.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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); |