From 99eaad164ac2d7565ba61d6ebe9f95b37aa478ca Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 10 Nov 2023 22:26:33 +0000 Subject: t/lei-import: skip strace for restricted systems Systems with Yama can restrict ptrace(2) (the underlying syscall used by strace(1)) and make it difficult to test error handling via error injection. Just skip the tests on such systems since it's probably not worth the effort to start using prctl(2) to enable the test on such systems. --- lib/PublicInbox/TestCommon.pm | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/TestCommon.pm') diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 46e6a538..b84886a0 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -935,13 +935,25 @@ sub cfg_new ($;@) { } our $strace_cmd; -sub strace () { +sub strace (@) { + my ($for_daemon) = @_; skip 'linux only test' if $^O ne 'linux'; + if ($for_daemon) { + my $f = '/proc/sys/kernel/yama/ptrace_scope'; + # TODO: we could fiddle with prctl in the daemon to make + # things work, but I'm not sure it's worth it... + state $ps = do { + my $fh; + CORE::open($fh, '<', $f) ? readline($fh) : 0; + }; + chomp $ps; + skip "strace unusable on daemons\n$f is `$ps' (!= 0)" if $ps; + } require_cmd('strace', 1); } -sub strace_inject () { - my $cmd = strace; +sub strace_inject (;$) { + my $cmd = strace(@_); state $ver = do { require PublicInbox::Spawn; my $v = PublicInbox::Spawn::run_qx([$cmd, '--version']); -- cgit v1.2.3-24-ge0c7