From: Ian Jackson Date: Thu, 25 Jul 2019 18:30:51 +0000 (+0100) Subject: http[s] tests: Fix stdout handling in ftpmaster test server X-Git-Tag: archive/debian/9.7~19 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=bde94a50484e5c4e49b16e048117878853c889b4;p=dgit.git http[s] tests: Fix stdout handling in ftpmaster test server Signed-off-by: Ian Jackson --- diff --git a/tests/ftpmasterapi-static-server b/tests/ftpmasterapi-static-server index cedc6f7c..f218cff9 100755 --- a/tests/ftpmasterapi-static-server +++ b/tests/ftpmasterapi-static-server @@ -30,17 +30,24 @@ use IO::Handle; our ($webroot) = @ARGV; our $port = ''; +# HTTP::Server::Simple handles requests in the main process so it +# must redirect and close STDOUT. So transplant STDOUT to CHECK. +open CHECK, ">& STDOUT" or die $!; +open STDOUT, ">/dev/null" or die $!; + sub stat_type_check () { die "[$port, $webroot] stdout not ta plain file" unless -f _; } -stat STDOUT or die $!; +stat CHECK or die $!; stat_type_check(); sub start_polling_fstat () { + our $polling_pid = $$; $SIG{ALRM} = sub { - stat STDOUT or die $!; + return unless $$ = $polling_pid; + stat CHECK or die $!; my $nlink = (stat _)[3]; exit 0 unless $nlink; stat_type_check(); # doesn't seem possible to fail but check anyway @@ -76,8 +83,8 @@ sub port () { return 0; } sub after_setup_listener () { my $sn = getsockname HTTP::Server::Simple::HTTPDaemon or die $!; ($main::port,) = unpack_sockaddr_in $sn; - print main::STDOUT $port, "\n" or die $!; - flush main::STDOUT or die $!; + print main::CHECK $port, "\n" or die $!; + flush main::CHECK or die $!; my $c = fork // die $!; exit 0 if $c; ::main::start_polling_fstat();