diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-02-05 15:34:58 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-02-07 19:02:52 -0500 |
commit | f0ccbf6b2c6f8727d878ef5e01d2ced3b9066e76 (patch) | |
tree | 1d77bf94ea6b735748b8f05b29da1c9e23458897 | |
parent | ceac55f8e4185820fe04ad9d9cc188cbde2cc709 (diff) | |
download | conf-f0ccbf6b2c6f8727d878ef5e01d2ced3b9066e76.tar.gz conf-f0ccbf6b2c6f8727d878ef5e01d2ced3b9066e76.zip |
improve mbsyncloop error handling
-rwxr-xr-x | bin/mbsyncloop | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/bin/mbsyncloop b/bin/mbsyncloop index fe8862c..967053c 100755 --- a/bin/mbsyncloop +++ b/bin/mbsyncloop @@ -5,6 +5,13 @@ use warnings; use POSIX 'mkfifo'; +my $pw = `rbw get mail.tozt.net doy\@tozt.net`; +if ($?) { + die "failed to fetch password: command returned $?"; +} + +open my $goimapnotify, '-|', "sh", "-c", "while true; do goimapnotify --conf ~/.config/imapnotify/tozt.conf 2>&1; done" or die "couldn't run goimapnotify: $!"; + my ($pw_pipe, $pid); sub cleanup { @@ -16,12 +23,10 @@ $SIG{INT} = $SIG{TERM} = sub { cleanup; exit }; END { cleanup } $pw_pipe = "/run/user/$>/mbsyncloop"; -mkfifo($pw_pipe, 0700) or die "couldn't create $pw_pipe"; - -my $pw = `rbw get mail.tozt.net doy\@tozt.net`; +mkfifo($pw_pipe, 0700) or die "couldn't create $pw_pipe: $!"; $pid = fork; -die unless defined $pid; +die "fork failed: $!" unless defined $pid; if (!$pid) { $SIG{PIPE} = sub {}; while (1) { @@ -32,8 +37,6 @@ if (!$pid) { exit; } -open my $goimapnotify, '-|', "sh", "-c", "goimapnotify --conf ~/.config/imapnotify/tozt.conf 2>&1" or die; - my $last_all = 0; while (1) { my $now = time; @@ -63,9 +66,11 @@ sub idle { my $rin = ''; vec($rin, fileno($goimapnotify), 1) = 1; my $ready = select(my $rout = $rin, undef, undef, $max_delay); + die "failed to read goimapnotify output: $!" if $ready == -1; if ($ready) { while (1) { my $ready = select(my $rout = $rin, undef, undef, 0.01); + die "failed to read goimapnotify output: $!" if $ready == -1; last unless $ready; sysread $goimapnotify, my $data, 4096; } |