diff options
author | Eric Wong <e@80x24.org> | 2023-12-13 00:50:09 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-12-13 09:01:48 +0000 |
commit | 77ad8a38e589a51cc8204a7c71c7e734db7220d5 (patch) | |
tree | dc242814cb2872a9ae360fe7deb365edfd340ae1 /t/httpd-corner.t | |
parent | 0f833a25eb64607386bc93c9d7b004c84acb54e0 (diff) | |
download | public-inbox-77ad8a38e589a51cc8204a7c71c7e734db7220d5.tar.gz |
BusyBox lsof(1) ignores the `-p PID' argument and shows the open files for every process it knows about. BusyBox lsof also lacks the `NODE' column of the non-BusyBox implementation, so we'll rely on /proc/PID/fd/ in those cases since the deleted file checks are Linux-only and it's common to have procfs is mounted on /proc on Linux.
Diffstat (limited to 't/httpd-corner.t')
-rw-r--r-- | t/httpd-corner.t | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/t/httpd-corner.t b/t/httpd-corner.t index da1c24b9..35c88600 100644 --- a/t/httpd-corner.t +++ b/t/httpd-corner.t @@ -639,30 +639,21 @@ SKIP: { }; SKIP: { - skip 'only testing lsof(8) output on Linux', 1 if $^O ne 'linux'; - my $lsof = require_cmd('lsof', 1) or skip 'no lsof in PATH', 1; - my $null_in = ''; - my $rdr = { 2 => \(my $null_err), 0 => \$null_in }; - my @lsof = xqx([$lsof, '-p', $td->{pid}], undef, $rdr); - my $d = [ grep(/\(deleted\)/, @lsof) ]; - is_deeply($d, [], 'no lingering deleted inputs') or diag explain($d); + skip 'only testing /proc/PID/fd on Linux', 1 if $^O ne 'linux'; + my $fd_dir = "/proc/$td->{pid}/fd"; + -d $fd_dir or skip '/proc/$PID/fd missing', 1; + my @child = grep defined, map readlink, glob "$fd_dir/*"; + my @d = grep /\(deleted\)/, @child; + is_deeply(\@d, [], 'no lingering deleted inputs') or diag explain(\@d); # filter out pipes inherited from the parent - my @this = xqx([$lsof, '-p', $$], undef, $rdr); - my $bad; - my $extract_inodes = sub { - map {; - my @f = split(' ', $_); - my $inode = $f[-2]; - $bad = $_ if $inode !~ /\A[0-9]+\z/; - $inode => 1; - } grep (/\bpipe\b/, @_); - }; - my %child = $extract_inodes->(@lsof); + my @this = grep defined, map readlink, glob "/proc/$$/fd/*"; + my $extract_inodes = sub { map { $_ => 1 } grep /\bpipe\b/, @_ }; + my %child = $extract_inodes->(@child); my %parent = $extract_inodes->(@this); - skip("inode not in expected format: $bad", 1) if defined($bad); delete @child{(keys %parent)}; - is_deeply([], [keys %child], 'no extra pipes with -W0'); + is_deeply([], [keys %child], 'no extra pipes with -W0') or + diag explain([child => \%child, parent => \%parent]); }; # ensure compatibility with other PSGI servers |