unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] t/lei-import: skip strace for restricted systems
Date: Fri, 10 Nov 2023 22:26:33 +0000	[thread overview]
Message-ID: <20231110222633.1647654-1-e@80x24.org> (raw)

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 +++++++++++++++---
 t/lei-import.t                |  7 +++----
 2 files changed, 18 insertions(+), 7 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']);
diff --git a/t/lei-import.t b/t/lei-import.t
index 6ad4c97b..1edd607d 100644
--- a/t/lei-import.t
+++ b/t/lei-import.t
@@ -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)),

                 reply	other threads:[~2023-11-10 22:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231110222633.1647654-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).