From 21eeb1671e56271e96a38d997dd72339fd14e566 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 15 Sep 2024 21:59:24 +0100 Subject: [PATCH] print diagnostic when eof on stderr --- pkgs/logshipper/logtee.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/logshipper/logtee.c b/pkgs/logshipper/logtee.c index 8b54a9f..651cbfa 100644 --- a/pkgs/logshipper/logtee.c +++ b/pkgs/logshipper/logtee.c @@ -70,7 +70,8 @@ int main(int argc, char * argv[]) { int flags = fcntl(STDOUT_FILENO, F_GETFL); fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK); - while(1) { + int quitting = 0; + while(! quitting) { int nfds = poll(fds, 3, 2000); if(nfds > 0) { if((fds[0].revents & (POLLIN|POLLHUP)) && @@ -78,7 +79,9 @@ int main(int argc, char * argv[]) { (tee_bytes == 0)) { out_bytes = read(fds[0].fd, buf, 8192); if(out_bytes == 0) { - exit(0); + quitting = 1; + buf = "logtee detected eof of file on stdin, exiting\n"; + out_bytes = strlen(buf); }; if(is_connected()) tee_bytes = out_bytes; };