diff options
| author | crueter <crueter@eden-emu.dev> | 2025-11-17 22:42:51 +0100 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2025-11-17 22:42:51 +0100 |
| commit | 91d41d1c34297489bd55041b2511d6e818a70d82 (patch) | |
| tree | 6e5398cf5fa391550aeb3b3e738be667e2f79a73 /src/common/logging/backend.cpp | |
| parent | 2e4ee8d9a4ac65d7e9dc5d0b98886d1139f615b6 (diff) | |
[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 <crueter@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3021
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Reviewed-by: Maufeat <sahyno1996@gmail.com>
Diffstat (limited to 'src/common/logging/backend.cpp')
| -rw-r--r-- | src/common/logging/backend.cpp | 18 |
1 files 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"); |
