Fix test case 180-fd-leaks when running on Fedora (#3911)

This commit is contained in:
Joseph 2020-02-22 09:09:11 +00:00 committed by GitHub
parent a376d1e52f
commit 967ec2e0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 13 deletions

View File

@ -29,6 +29,10 @@ my $tmp = tmpnam();
mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
my ($outfh, $outname) = tempfile('/tmp/i3-ls-output.XXXXXX', UNLINK => 1);
# Get fds from a clean shell
my $shoutput = `sh -c "ls -l /proc/self/fd"`;
# Get fds from i3
cmd qq|exec ls -l /proc/self/fd >$outname && echo done >$tmp|;
open(my $fh, '<', $tmp);
@ -38,13 +42,16 @@ close($fh);
unlink($tmp);
# Get the ls /proc/self/fd output
my $output;
my $i3output;
{
local $/;
$output = <$outfh>;
$i3output = <$outfh>;
}
close($outfh);
sub extract_fds {
my $output = @_;
# Split lines, keep only those which are symlinks.
my @lines = grep { /->/ } split("\n", $output);
@ -55,12 +62,19 @@ delete $fds{0};
delete $fds{1};
delete $fds{2};
# Filter out the fd which is caused by ls calling readdir().
# filter out the fd which is caused by ls calling readdir().
for my $fd (keys %fds) {
delete $fds{$fd} if $fds{$fd} =~ m,^/proc/\d+/fd$,;
}
is(scalar keys %fds, 0, 'No file descriptors leaked');
return %fds;
}
my %i3fds = extract_fds($i3output);
my %shfds = extract_fds($shoutput);
# Diff the fds to account for services that keep fds open, such as the System Security Services Daemon (sssd)
is(scalar keys %i3fds, scalar keys %shfds, 'No file descriptors leaked');
}