diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2019-07-25 19:30:51 +0100 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2019-08-11 00:09:27 +0100 |
commit | bde94a50484e5c4e49b16e048117878853c889b4 (patch) | |
tree | f691ef8f67b3bc2a056b6e20bedd1ff82210139e /tests | |
parent | 8ab2d39e45255429ddef54407c7b74a0b1eda65b (diff) |
http[s] tests: Fix stdout handling in ftpmaster test server
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/ftpmasterapi-static-server | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/ftpmasterapi-static-server b/tests/ftpmasterapi-static-server index cedc6f7..f218cff 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(); |