From eb3e4cdd383a3efc25c29df1739170de6fed6431 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Wed, 2 Dec 2026 00:31:00 +0100 Subject: Prevent xz-like attack from being pulled :P --- flake.nix | 2 +- server/CMakeLists.txt | 6 +----- server/src/main.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index c0aeebe..65b29bd 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,7 @@ buildInputs = with pkgs; [ boost pugixml expat icu openssl sqlite ]; nativeBuildInputs = with pkgs; [ llvmPackages.clang-tools boost # not from pkgs - cmake ninja gettext pkgconf systemdLibs + cmake ninja gettext ]; hardeningDisable = [ diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index b071c64..8c7c326 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -112,8 +112,4 @@ gettext_create_translations( ) find_package(expat REQUIRED) -target_link_libraries(routemon_lib expat::expat) - -find_package(PkgConfig QUIET REQUIRED) -pkg_check_modules(systemd REQUIRED IMPORTED_TARGET libsystemd) -target_link_libraries(routemon PkgConfig::systemd) +target_link_libraries(routemon_lib expat::expat) \ No newline at end of file diff --git a/server/src/main.cpp b/server/src/main.cpp index 9d576a2..fa85f78 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -1,7 +1,6 @@ #include #include // for malloc_trim(3) #include -#include import std; import routemon; @@ -125,6 +124,33 @@ auto load_situations( return pub; } +auto sd_notify(std::string_view msg) -> net::awaitable +{ + try + { + auto endpoint_cstr = std::getenv("NOTIFY_SOCKET"); + if (!endpoint_cstr || endpoint_cstr[0] == '\0') + co_return; + if (endpoint_cstr[0] != '/' && endpoint_cstr[0] != '@') + throw std::runtime_error{ + "NOTIFY_SOCKET specifies an unsupported endpoint" + }; + auto endpoint_str = std::string{endpoint_cstr}; + if (endpoint_str[0] == '@') + endpoint_str[0] = '\0'; + auto endpoint = net::local::datagram_protocol::endpoint{endpoint_str}; + auto sock = net::local::datagram_protocol::socket{ + co_await net::this_coro::executor + }; + co_await sock.async_send_to(net::buffer(msg), endpoint); + } + catch (std::exception const& e) + { + throw std::runtime_error{std::format( + "failed to notify service manager: {}", e.what())}; + } +} + auto server_main(routemon::log::logger& l, routemon::config::app config) -> exit_status { @@ -185,7 +211,7 @@ auto server_main(routemon::log::logger& l, routemon::config::app config) ioc, [&]() -> net::awaitable { - sd_notify(0, "READY=1"); + co_await sd_notify("READY=1"); while (true) { @@ -196,8 +222,8 @@ auto server_main(routemon::log::logger& l, routemon::config::app config) std::chrono::duration_cast( std::chrono::steady_clock::now().time_since_epoch()) .count()); - auto const reloading_msg = std::format("RELOADING=1\nMONOTONIC_USEC={}", usec); - sd_notify(0, reloading_msg.c_str()); + co_await sd_notify( + std::format("RELOADING=1\nMONOTONIC_USEC={}", usec)); l.info("Received reload request"); auto mpub = load_situations(l, config.situations.datex2_filename); @@ -211,11 +237,26 @@ auto server_main(routemon::log::logger& l, routemon::config::app config) l.error("Failed to update situation publication"); } - sd_notify(0, "READY=1"); + co_await sd_notify("READY=1"); } } }, - net::detached); + [&](std::exception_ptr e) + { + if (e) + { + try + { + std::rethrow_exception(e); + } + catch (std::exception const& e) + { + l.sub("signal_handler") + .error("Error in signal handler: {}", e.what()); + ioc.stop(); + } + } + }); auto threads = std::vector{nthread}; for (auto& thread : threads) @@ -223,7 +264,7 @@ auto server_main(routemon::log::logger& l, routemon::config::app config) for (auto& thread : threads) thread.join(); - l.error("I/O contexts stopped"); + l.error("I/O context event processing loop stoped"); return exit_status::failure; } -- cgit v1.3.1