From d5bf741650db9fcc890c5146c303fb75e2782320 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Mon, 29 Dec 2025 19:05:25 +0100 Subject: [PATCH] Test Fix double SIGTERM --- src/server/main.cpp | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/src/server/main.cpp b/src/server/main.cpp index 948df83..3c3194e 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -4,6 +4,8 @@ #include #include +#include +#include #include #include #include @@ -23,22 +25,7 @@ using namespace ColumnLynx; volatile sig_atomic_t done = 0; -void signalHandler(int signum) { - if (signum == SIGINT || signum == SIGTERM) { - log("Received termination signal. Shutting down server gracefully."); - done = 1; - } -} - int main(int argc, char** argv) { - // Capture SIGINT and SIGTERM for graceful shutdown -#if !defined(_WIN32) - struct sigaction action; - memset(&action, 0, sizeof(struct sigaction)); - action.sa_handler = signalHandler; - sigaction(SIGINT, &action, nullptr); - sigaction(SIGTERM, &action, nullptr); -#endif cxxopts::Options options("columnlynx_server", "ColumnLynx Server Application"); @@ -78,17 +65,6 @@ int main(int argc, char** argv) { std::shared_ptr tun = std::make_shared(optionsObj["interface"].as()); log("Using virtual interface: " + tun->getName()); - // Get network configuration from config file - std::string networkString = config.find("NETWORK") != config.end() ? config.find("NETWORK")->second : "10.10.0.0"; - uint8_t subnetMask = config.find("SUBNET_MASK") != config.end() ? std::stoi(config.find("SUBNET_MASK")->second) : 24; - uint32_t baseIP = VirtualInterface::stringToIpv4(networkString); - uint32_t serverIP = baseIP + 1; // e.g., 10.10.0.1 - - // Configure the server's TUN interface with point-to-point mode - // Server acts as a peer to clients, so use point-to-point configuration - tun->configureIP(serverIP, baseIP, subnetMask, 1420); - log("Configured TUN interface with IP " + VirtualInterface::ipv4ToString(serverIP) + " peer " + VirtualInterface::ipv4ToString(baseIP)); - // Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory) std::shared_ptr sodiumWrapper = std::make_shared(); @@ -141,11 +117,13 @@ int main(int argc, char** argv) { while (!done) { auto packet = tun->readPacket(); if (packet.empty()) { + // Small sleep to avoid busy-waiting and to allow signal processing + std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } const uint8_t* ip = packet.data(); - uint32_t dstIP = ntohl(*(uint32_t*)(ip + 16)); // IPv4 destination address + uint32_t dstIP = ntohl(*(uint32_t*)(ip + 16)); // IPv4 destination address offset in IPv6-mapped header auto session = SessionRegistry::getInstance().getByIP(dstIP); if (!session) {