From ad3c31862ef1199f7d38e9b55dc12241e9a3e211 Mon Sep 17 00:00:00 2001 From: zqmfb <267821100+angularbanjo@users.noreply.github.com> Date: Thu, 26 Mar 2026 18:37:24 -0400 Subject: [PATCH] Further clarify systemd socket selection --- src/command_network.cc | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/command_network.cc b/src/command_network.cc index f44390c8..117c62de 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -164,12 +164,26 @@ apply_scgi_systemd() { for (int i = 0; i < n; i++) { int fd = SD_LISTEN_FDS_START + i; - if (selected_fd != -1) // We've already selected an fd + if (selected_fd != -1) { ::close(fd); - else if (sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1) > 0) // Found an appropriate fd - selected_fd = fd; - else // It's some other type of fd, close it. + continue; + } + + auto err = sd_is_socket(fd, AF_UNSPEC, SOCK_STREAM, 1); + + if (err < 0) { + // Safe to ignore errors here - we just skip it and move on. ::close(fd); + continue; + } + + if (err == 0) { + // Not the socket we're looking for. + ::close(fd); + continue; + } + + selected_fd = fd; } if (selected_fd == -1)