From c7eee68431f24ee3071150217fe12c00f895ce2b Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Tue, 2 Jun 2020 11:09:36 +0100 Subject: [PATCH] bin/disorder-notify: Improve error handling in the `select' loop. Organization: Straylight/Edgeware From: Mark Wooding Don't crash out on read errors. Report the problem in the `lost connection' message. --- bin/disorder-notify | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/disorder-notify b/bin/disorder-notify index 3c57073..b632ef4 100755 --- a/bin/disorder-notify +++ b/bin/disorder-notify @@ -191,6 +191,7 @@ sub watch_and_notify0 ($) { my $buffer = ""; my @lines = (); my $rdin = ""; vec($rdin, (fileno $sk_log), 1) = 1; + my $loss; WATCH: for (;;) { for my $line (@lines) { @@ -218,13 +219,13 @@ sub watch_and_notify0 ($) { } } - last WATCH unless $sk_log; + if (!$sk_log) { $loss = "EOF from server"; last WATCH; } select my $rdout = $rdin, undef, undef, undef; READ: for (;;) { my ($b, $n); eval { $n = sysread $sk_log, $b, 4096; }; if ($@ && $@->errno == EAGAIN) { last READ; } - elsif ($@) { die $@; } + elsif ($@) { $loss = "error from read: " . $@->errno; last WATCH; } elsif (!$n) { close $sk_log; $sk_log = undef; } else { $buffer .= $b; } } @@ -233,7 +234,7 @@ sub watch_and_notify0 ($) { $buffer = pop @lines; } - notify "$TITLE state", "Lost connection"; + notify "$TITLE state", "Lost connection: $loss"; close $sk; close $sk_log if defined $sk_log; -- [mdw]