From 91d41d1c34297489bd55041b2511d6e818a70d82 Mon Sep 17 00:00:00 2001 From: crueter Date: Mon, 17 Nov 2025 22:42:51 +0100 Subject: [PATCH] [logging] USER null fallback (#3021) If `USER` was unset, logging would crash immediately. `USER` is *not* a guaranteed variable, so to get around this we add a null fallback and also prefer `LOGNAME`, which is "standard" on POSIX systems (yet half the time isn't set because fuck me I guess) Signed-off-by: crueter Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3021 Reviewed-by: CamilleLaVey Reviewed-by: Maufeat --- src/common/logging/backend.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 12cf15f9cf..8d9cf57314 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -112,10 +112,20 @@ public: // This must be a static otherwise it would get checked on EVERY // instance of logging an entry... static std::string username = []() -> std::string { - auto* s = getenv("USER"); - if (s == nullptr) - s = getenv("USERNAME"); - return std::string{s}; + // in order of precedence + // LOGNAME usually works on UNIX, USERNAME on Windows + // Some UNIX systems suck and don't use LOGNAME so we also + // need USER :( + for (auto const var : { + "LOGNAME", + "USERNAME", + "USER", + }) { + if (auto const s = getenv(var); s != nullptr) + return std::string{s}; + } + + return std::string{}; }(); if (!username.empty()) boost::replace_all(message, username, "user");