diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2022-01-09 04:46:43 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2022-01-10 22:38:32 -0500 |
commit | 93bc7f269521b368806d0f0e09f9bf25fbf8a236 (patch) | |
tree | 31e6482a5f5968a7b195cc0ec5907887aa303811 /tests/LightyTest.pm | |
parent | 1e335b3724ae3f839170286d572b3056d6814b54 (diff) | |
download | lighttpd-git-93bc7f269521b368806d0f0e09f9bf25fbf8a236.tar.gz |
[core] allow tests/tmp/bind.conf override (#3137)
optional bind spec override for tests/*.conf,
e.g. for use on platforms w/o socket activation
x-ref:
"TRACEME environment option in tests broken with LISTEN_PID"
https://redmine.lighttpd.net/issues/3137
Diffstat (limited to 'tests/LightyTest.pm')
-rw-r--r-- | tests/LightyTest.pm | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/tests/LightyTest.pm b/tests/LightyTest.pm index e71fd2e6..6415413f 100644 --- a/tests/LightyTest.pm +++ b/tests/LightyTest.pm @@ -195,7 +195,7 @@ sub start_proc { } elsif (defined $ENV{"TRACEME"} && $ENV{"TRACEME"} eq 'valgrind') { @cmdline = (qw(valgrind --tool=memcheck --track-origins=yes --show-reachable=yes --leak-check=yes --log-file=valgrind.%p), @cmdline); } - # diag("\nstarting lighttpd at :".$self->{PORT}.", cmdline: ".@cmdline ); + # diag("\nstarting lighttpd at :".$self->{PORT}.", cmdline: @cmdline"); my $child = fork(); if (not defined $child) { diag("\nFork failed"); @@ -203,21 +203,38 @@ sub start_proc { return -1; } if ($child == 0) { - # set up systemd socket activation env vars - $ENV{LISTEN_FDS} = "1"; - $ENV{LISTEN_PID} = $$; - if (defined($ENV{"TRACEME"}) && $ENV{"TRACEME"} ne "valgrind") { - $ENV{LISTEN_PID} = "parent:$$"; # lighttpd extension - } - listen($SOCK, 1024) || die "listen: $!"; - if (fileno($SOCK) != 3) { # SD_LISTEN_FDS_START 3 - require POSIX; - POSIX::dup2(fileno($SOCK), 3) || die "dup2: $!"; + if ($^O eq "MSWin32") { + # On platforms where systemd socket activation is not supported + # or inconvenient for testing (i.e. cygwin <-> native Windows exe), + # there is a race condition with close() before server start, + # but port specific port is unlikely to be reused so quickly, + # and the point is to avoid a port which is already in use. close($SOCK); + my $CONF; + open($CONF,'>',"$ENV{'SRCDIR'}/tmp/bind.conf") || die "open: $!"; + print $CONF <<BIND_OVERRIDE; +server.systemd-socket-activation := "disable" +server.bind = "127.0.0.1" +server.port = $ENV{'PORT'} +BIND_OVERRIDE } else { - require Fcntl; - fcntl($SOCK, Fcntl::F_SETFD(), 0); # clr FD_CLOEXEC + # set up systemd socket activation env vars + $ENV{LISTEN_FDS} = "1"; + $ENV{LISTEN_PID} = $$; + if (defined($ENV{"TRACEME"}) && $ENV{"TRACEME"} ne "valgrind") { + $ENV{LISTEN_PID} = "parent:$$"; # lighttpd extension + } + listen($SOCK, 1024) || die "listen: $!"; + if (fileno($SOCK) != 3) { # SD_LISTEN_FDS_START 3 + require POSIX; + POSIX::dup2(fileno($SOCK), 3) || die "dup2: $!"; + close($SOCK); + } + else { + require Fcntl; + fcntl($SOCK, Fcntl::F_SETFD(), 0); # clr FD_CLOEXEC + } } exec @cmdline or die($?); } |