GetUsername from the environment.
This works with musl on NSS-managed hosts, and avoids network access for getting the username with glibc.
This logic is copied from getpass.getuser() in Python.
#include "user.h"
#include "platform.h"
#include "defaults.h"
+#include "env.h"
#include <util/generic/yexception.h>
#endif
TString GetUsername() {
+ for (const auto& var : {"LOGNAME", "USER", "LNAME", "USERNAME"}) {
+ TString val = GetEnv(var);
+ if (val)
+ return val;
+ }
+
TTempBuf nameBuf;
for (;;) {
#if defined(_win_)
