]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
t/lei-import: skip strace for restricted systems
authorEric Wong <e@80x24.org>
Fri, 10 Nov 2023 22:26:33 +0000 (22:26 +0000)
committerEric Wong <e@80x24.org>
Sat, 11 Nov 2023 03:00:15 +0000 (03:00 +0000)
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
t/lei-import.t

index 46e6a538602a85b2311de427a407b6567180eac6..b84886a02827e73893fb0863e3285263681d5c19 100644 (file)
@@ -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']);
index 6ad4c97b904819efc08650341ddcf47ad8540943..1edd607d103e7d3cfde736f4e4cd2896448e281f 100644 (file)
@@ -155,19 +155,18 @@ do {
 like($lei_out, qr/\bbin\b/, 'commit-delay eventually commits');
 
 SKIP: {
-       my $strace = strace_inject; # skips if strace is old or non-Linux
+       my $strace = strace_inject(1); # skips if strace is old or non-Linux
        my $tmpdir = tmpdir;
        my $tr = "$tmpdir/tr";
-       my $cmd = [ $strace, "-o$tr", '-f',
+       my $cmd = [ $strace, '-q', "-o$tr", '-f',
                "-P", File::Spec->rel2abs('t/plack-qp.eml'),
                '-e', 'inject=readv,read:error=EIO'];
        lei_ok qw(daemon-pid);
        chomp(my $daemon_pid = $lei_out);
        push @$cmd, '-p', $daemon_pid;
-       my $strace_opt = { 1 => \my $out, 2 => \my $err };
        require PublicInbox::Spawn;
        require PublicInbox::AutoReap;
-       my $pid = PublicInbox::Spawn::spawn($cmd, \%ENV, $strace_opt);
+       my $pid = PublicInbox::Spawn::spawn($cmd, \%ENV);
        my $ar = PublicInbox::AutoReap->new($pid);
        tick; # wait for strace to attach
        ok(!lei(qw(import -F eml t/plack-qp.eml)),