Add support for SCGI systemd socket activation

Add a new command, `network.scgi.open_systemd`, that binds to a file
descriptor passed in via systemd socket activation.
This commit is contained in:
zqmfb
2026-03-24 20:48:32 -04:00
committed by Jari Sundell
parent a82bdf22ac
commit 63ea08bde6
5 changed files with 76 additions and 0 deletions
+15
View File
@@ -2,6 +2,7 @@
#include <algorithm>
#include <cassert>
#include <fcntl.h>
#include <unistd.h>
#include <sys/un.h>
#include <torrent/connection_manager.h>
@@ -80,6 +81,20 @@ SCgi::open_named(const std::string& filename) {
m_path = filename;
}
void
SCgi::open_fd(int fd) {
torrent::runtime::socket_manager()->open_event_or_throw(this, [&]() {
int flags = ::fcntl(fd, F_GETFL, 0);
if (flags == -1 || ::fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1)
throw torrent::resource_error("Could not set non-blocking on systemd fd: " +
std::string(std::strerror(errno)));
set_file_descriptor(fd);
// fd is already bound and listening; no bind()/listen() needed.
});
torrent::connection_manager()->inc_socket_count();
}
void
SCgi::open(sockaddr* sa, unsigned int length) {
try {
+1
View File
@@ -21,6 +21,7 @@ public:
void open_port(sockaddr* sa, unsigned int length, bool dont_route);
void open_named(const std::string& filename);
void open_fd(int fd);
void activate();