For the first run, stderr is the inherited fd
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
open ::STDIN , "<& $call_fds[0]" or fail_log("dup for fd0");
open ::STDOUT, ">& $call_fds[1]" or fail_log("dup for fd1");
open ::STDERR, ">& $call_fds[2]" or fail_log("dup for fd2");
open ::STDIN , "<& $call_fds[0]" or fail_log("dup for fd0");
open ::STDOUT, ">& $call_fds[1]" or fail_log("dup for fd1");
open ::STDERR, ">& $call_fds[2]" or fail_log("dup for fd2");
- POSIX::close($_) foreach @call_fds;
- close CALL;
+sub close_call_fds () {
+ foreach (@call_fds) {
+ next if $_ <= 2;
+ POSIX::close($_);
+ }
+ close CALL;
+}
+
sub protocol_write ($) {
my ($d) = @_;
return if (print CALL $d and flush CALL);
sub protocol_write ($) {
my ($d) = @_;
return if (print CALL $d and flush CALL);
open STDERR, ">&NULL" or fail_log("dup null onto stderr: $!");
close NULL;
open STDERR, ">&NULL" or fail_log("dup null onto stderr: $!");
close NULL;
- POSIX::close($_) foreach @call_fds;
- close CALL;
my $flags = fcntl(LISTEN, F_GETFL, 0)
or fail_log("F_GETFL listen socket: $!");
my $flags = fcntl(LISTEN, F_GETFL, 0)
or fail_log("F_GETFL listen socket: $!");