aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph <joseph.s.egan+github@gmail.com>2020-02-22 09:09:11 +0000
committerGitHub <noreply@github.com>2020-02-22 10:09:11 +0100
commit967ec2e0eab337df8ca2995fa7235efbbaa82a0c (patch)
tree78d77803a72e4a96313731e5610f0d970a81ccac
parenta376d1e52f4203d43a2a276f292835c531460b7c (diff)
downloadi3-967ec2e0eab337df8ca2995fa7235efbbaa82a0c.tar.gz
i3-967ec2e0eab337df8ca2995fa7235efbbaa82a0c.zip
Fix test case 180-fd-leaks when running on Fedora (#3911)
-rw-r--r--testcases/t/180-fd-leaks.t40
1 files changed, 27 insertions, 13 deletions
diff --git a/testcases/t/180-fd-leaks.t b/testcases/t/180-fd-leaks.t
index 4e3369e9..6ca0dc6f 100644
--- a/testcases/t/180-fd-leaks.t
+++ b/testcases/t/180-fd-leaks.t
@@ -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,29 +42,39 @@ close($fh);
unlink($tmp);
# Get the ls /proc/self/fd output
-my $output;
+my $i3output;
{
local $/;
- $output = <$outfh>;
+ $i3output = <$outfh>;
}
close($outfh);
-# Split lines, keep only those which are symlinks.
-my @lines = grep { /->/ } split("\n", $output);
+sub extract_fds {
+ my $output = @_;
+
+ # Split lines, keep only those which are symlinks.
+ my @lines = grep { /->/ } split("\n", $output);
-my %fds = map { /([0-9]+) -> (.+)$/; ($1, $2) } @lines;
+ my %fds = map { /([0-9]+) -> (.+)$/; ($1, $2) } @lines;
-# Filter out 0, 1, 2 (stdin, stdout, stderr).
-delete $fds{0};
-delete $fds{1};
-delete $fds{2};
+ # Filter out 0, 1, 2 (stdin, stdout, stderr).
+ delete $fds{0};
+ delete $fds{1};
+ delete $fds{2};
-# 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$,;
+ # 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$,;
+ }
+
+ return %fds;
}
-is(scalar keys %fds, 0, 'No file descriptors leaked');
+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');
}