2 # vim:ts=4:sw=4:expandtab
4 # Verifies that i3 does not leak any file descriptors in 'exec'.
8 use File::Temp qw(:POSIX tempfile);
10 my $i3 = i3(get_socket_path());
13 mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
14 my ($outfh, $outname) = tempfile('/tmp/i3-ls-output.XXXXXX', UNLINK => 1);
16 cmd qq|exec ls -l /proc/self/fd >$outname && echo done >$tmp|;
18 open(my $fh, '<', $tmp);
19 # Block on the FIFO, this will return exactly when the command is done.
24 # Get the ls /proc/self/fd output
32 # Split lines, keep only those which are symlinks.
33 my @lines = grep { /->/ } split("\n", $output);
35 my %fds = map { /([0-9]+) -> (.+)$/; ($1, $2) } @lines;
37 # Filter out 0, 1, 2 (stdin, stdout, stderr).
42 # Filter out the fd which is caused by ls calling readdir().
43 for my $fd (keys %fds) {
44 delete $fds{$fd} if $fds{$fd} =~ m,^/proc/\d+/fd$,;
47 is(scalar keys %fds, 0, 'No file descriptors leaked');