From 3665f3e7550593b75cdd76f7820de4b5b6aae284 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 16 Nov 2011 21:41:00 +0000 Subject: [PATCH] tests: Bugfix: Fix socket activation (see comment) --- testcases/lib/SocketActivation.pm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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. -- 2.39.5