From: Michael Stapelberg Date: Wed, 16 Nov 2011 21:41:00 +0000 (+0000) Subject: tests: Bugfix: Fix socket activation (see comment) X-Git-Tag: 4.2~245 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3665f3e7550593b75cdd76f7820de4b5b6aae284;p=i3%2Fi3 tests: Bugfix: Fix socket activation (see comment) --- diff --git a/testcases/lib/SocketActivation.pm b/testcases/lib/SocketActivation.pm index bdcb40e7..f6872fb6 100644 --- a/testcases/lib/SocketActivation.pm +++ b/testcases/lib/SocketActivation.pm @@ -5,7 +5,7 @@ use strict; use warnings; use IO::Socket::UNIX; # core use Cwd qw(abs_path); # core -use POSIX (); # core +use POSIX qw(:fcntl_h); # core use AnyEvent::Handle; # not core use Exporter 'import'; use v5.10; @@ -60,9 +60,12 @@ sub activate_i3 { '..', $ENV{PATH} ); - # Only pass file descriptors 0 (stdin), 1 (stdout), 2 (stderr) and - # 3 (socket) to the child. - $^F = 3; + + # We are about to exec, but we did not modify $^F to include $socket + # when creating the socket (because the file descriptor could have a + # number != 3 which would lead to i3 leaking a file descriptor). + # Therefore, we explicitly have to clear the file descriptor flags now: + POSIX::fcntl($socket, F_SETFD, 0) or die "Could not clear fd flags: $!"; # If the socket does not use file descriptor 3 by chance already, we # close fd 3 and dup2() the socket to 3.