summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2022-01-08 23:23:28 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2022-01-10 22:38:32 -0500
commit1e335b3724ae3f839170286d572b3056d6814b54 (patch)
tree7c1b938500505ca0e4d189ec3e0b84199f62f872
parentaeba3144548b17d1fc35db4a6809ba5ebbe50c7e (diff)
downloadlighttpd-git-1e335b3724ae3f839170286d572b3056d6814b54.tar.gz
[core] allow LISTEN_PID to be ppid if TRACEME (fixes #3137)
allow LISTEN_PID to be ppid (parent pid) if TRACEME set in environment (e.g. for strace, gdb on Linux; valgrind starts lighttpd as LISTEN_PID) x-ref: "TRACEME environment option in tests broken with LISTEN_PID" https://redmine.lighttpd.net/issues/3137
-rw-r--r--src/network.c8
-rw-r--r--tests/LightyTest.pm4
2 files changed, 11 insertions, 1 deletions
diff --git a/src/network.c b/src/network.c
index db3f51e9..6af5acf0 100644
--- a/src/network.c
+++ b/src/network.c
@@ -581,7 +581,13 @@ static int network_socket_activation_from_env(server *srv, network_socket_config
char *listen_fds = getenv("LISTEN_FDS");
pid_t lpid = listen_pid ? (pid_t)strtoul(listen_pid,NULL,10) : 0;
int nfds = listen_fds ? atoi(listen_fds) : 0;
- int rc = (lpid == getpid() && nfds > 0 && nfds < 5000)
+ int rc = (nfds > 0 && nfds < 5000
+ && (lpid == getpid()
+ #ifndef _WIN32
+ || (0 == strncmp(listen_pid, "parent:", 7)
+ && getppid() == (pid_t)strtoul(listen_pid+7,NULL,10))
+ #endif
+ ))
? network_socket_activation_nfds(srv, s, nfds)
: 0;
unsetenv("LISTEN_PID");
diff --git a/tests/LightyTest.pm b/tests/LightyTest.pm
index 4416376d..e71fd2e6 100644
--- a/tests/LightyTest.pm
+++ b/tests/LightyTest.pm
@@ -115,6 +115,7 @@ sub stop_proc {
my $pid = $self->{LIGHTTPD_PID};
if (defined $pid && $pid != -1) {
+ kill('USR1', $pid) if (($ENV{"TRACEME"}||'') eq 'strace');
kill('TERM', $pid) or return -1;
return -1 if ($pid != waitpid($pid, 0));
} else {
@@ -205,6 +206,9 @@ sub start_proc {
# 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;