Browse Source

[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>
pull/3044/head
crueter 1 month ago
parent
commit
91d41d1c34
No known key found for this signature in database GPG Key ID: 425ACD2D4830EBC6
  1. 18
      src/common/logging/backend.cpp

18
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");

Loading…
Cancel
Save