From f2c7b911a1c4a7520091ba7224773c30e409c337 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 17 Dec 2020 23:54:04 +0000 Subject: lei: drop $SIG{__DIE__}, add oneshot fallbacks We'll force stdout+stderr to be a pipe the spawning client controls, thus there's no need to lose error reporting by prematurely redirecting stdout+stderr to /dev/null. We can now rely exclusively on OnDestroy to write to syslog() on uncaught die failures. Also support falling back to oneshot mode on socket and cwd failures, since some commands may still be useful if the current working directory goes missing :P --- t/lei.t | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/lei.t b/t/lei.t index bdf6cc1c..cce90fff 100644 --- a/t/lei.t +++ b/t/lei.t @@ -127,7 +127,7 @@ my $test_lei_common = sub { my $test_lei_oneshot = $ENV{TEST_LEI_ONESHOT}; SKIP: { last SKIP if $test_lei_oneshot; - require_mods('IO::FDPass', 16); + require_mods(qw(IO::FDPass Cwd), 41); my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/sock"; ok(run_script([qw(lei daemon-pid)], undef, $opt), 'daemon-pid'); @@ -188,7 +188,34 @@ SKIP: { chomp(my $new_pid = $out); ok(kill(0, $new_pid), 'new pid is running'); ok(-S $sock, 'sock exists again'); - unlink $sock or BAIL_OUT "unlink $!"; + + if ('socket inaccessible') { + chmod 0000, $sock or BAIL_OUT "chmod 0000: $!"; + $out = $err = ''; + ok(run_script([qw(lei help)], undef, $opt), + 'connect fail, one-shot fallback works'); + like($err, qr/\bconnect\(/, 'connect error noted'); + like($out, qr/^usage: /, 'help output works'); + chmod 0700, $sock or BAIL_OUT "chmod 0700: $!"; + } + if ('oneshot on cwd gone') { + my $cwd = Cwd::fastcwd() or BAIL_OUT "fastcwd: $!"; + my $d = "$home/to-be-removed"; + mkdir $d or BAIL_OUT "mkdir($d) $!"; + chdir $d or BAIL_OUT "chdir($d) $!"; + if (rmdir($d)) { + $out = $err = ''; + ok(run_script([qw(lei help)], undef, $opt), + 'cwd fail, one-shot fallback works'); + } else { + $err = "rmdir=$!"; + } + chdir $cwd or BAIL_OUT "chdir($cwd) $!"; + like($err, qr/cwd\(/, 'cwd error noted'); + like($out, qr/^usage: /, 'help output still works'); + } + + unlink $sock or BAIL_OUT "unlink($sock) $!"; for (0..100) { kill('CHLD', $new_pid) or last; tick(); -- cgit v1.2.3-24-ge0c7