about summary refs log tree commit homepage
path: root/lib/PublicInbox/TestCommon.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-10 22:26:33 +0000
committerEric Wong <e@80x24.org>2023-11-11 03:00:15 +0000
commit99eaad164ac2d7565ba61d6ebe9f95b37aa478ca (patch)
treebaee262fbbf9c356f731fa60a1a5bb9171c047c6 /lib/PublicInbox/TestCommon.pm
parent363c043a8a3f379a69802fc566112fcd8f1e750c (diff)
downloadpublic-inbox-99eaad164ac2d7565ba61d6ebe9f95b37aa478ca.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/TestCommon.pm')
-rw-r--r--lib/PublicInbox/TestCommon.pm18
1 files changed, 15 insertions, 3 deletions
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']);