commit 1f6cfc36797c1038ab59ec70a8fae0cf83eff321
parent 8ec00f171016b1cec85bd88710b84970ddcf3292
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 15 Sep 2024 21:40:05 +0100
extract method is_connected
Diffstat:
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/pkgs/logshipper/logtee.c b/pkgs/logshipper/logtee.c
@@ -38,6 +38,10 @@ struct pollfd fds[] = {
{ .fd = -1, .events = POLLERR },
};
+int is_connected(void) {
+ return (fds[2].fd >= 0);
+}
+
int main(int argc, char * argv[]) {
@@ -67,7 +71,7 @@ int main(int argc, char * argv[]) {
if(out_bytes == 0) {
exit(0);
};
- if(fds[2].fd >= 0) tee_bytes = out_bytes;
+ if(is_connected()) tee_bytes = out_bytes;
};
if(out_bytes) {
@@ -76,7 +80,7 @@ int main(int argc, char * argv[]) {
if(fds[1].revents & (POLLERR|POLLHUP)) {
exit(1); // can't even log an error if the logging stream fails
};
- if(fds[2].fd >= 0) {
+ if(is_connected()) {
if(tee_bytes) {
tee_bytes -= write(fds[2].fd, buf, tee_bytes);
};
@@ -87,7 +91,7 @@ int main(int argc, char * argv[]) {
};
};
} else {
- if(fds[2].fd < 0) {
+ if(! is_connected()) {
if(argc>1) fds[2].fd = open_shipper_socket(argv[1]);
}
};