diff --git a/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformMisc.cpp b/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformMisc.cpp index 312faeeb1b9f..a1e9180c028e 100644 --- a/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformMisc.cpp +++ b/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformMisc.cpp @@ -96,7 +96,7 @@ void FLinuxPlatformMisc::NormalizePath(FString& InPath) // if var failed if (!bHaveHome) { - struct passwd * UserInfo = getpwuid(getuid()); + struct passwd * UserInfo = getpwuid(geteuid()); if (NULL != UserInfo && NULL != UserInfo->pw_dir) { FCString::Strcpy(CachedResult, ARRAY_COUNT(CachedResult) - 1, ANSI_TO_TCHAR(UserInfo->pw_dir)); @@ -128,6 +128,7 @@ void FLinuxPlatformMisc::PlatformInit() UE_LOG(LogInit, Log, TEXT(" - this process' id (pid) is %d, parent process' id (ppid) is %d"), static_cast< int32 >(getpid()), static_cast< int32 >(getppid())); UE_LOG(LogInit, Log, TEXT(" - we are %srunning under debugger"), IsDebuggerPresent() ? TEXT("") : TEXT("not ")); UE_LOG(LogInit, Log, TEXT(" - machine network name is '%s'"), FPlatformProcess::ComputerName()); + UE_LOG(LogInit, Log, TEXT(" - user name is '%s' (%s)"), FPlatformProcess::UserName(), FPlatformProcess::UserName(false)); UE_LOG(LogInit, Log, TEXT(" - we're logged in %s"), FPlatformMisc::HasBeenStartedRemotely() ? TEXT("remotely") : TEXT("locally")); UE_LOG(LogInit, Log, TEXT(" - Number of physical cores available for the process: %d"), FPlatformMisc::NumberOfCores()); UE_LOG(LogInit, Log, TEXT(" - Number of logical cores available for the process: %d"), FPlatformMisc::NumberOfCoresIncludingHyperthreads()); diff --git a/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp b/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp index ec33e1506d33..e95069f3c53c 100644 --- a/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp +++ b/Engine/Source/Runtime/Core/Private/Linux/LinuxPlatformProcess.cpp @@ -73,7 +73,8 @@ namespace PlatformProcessLimits { MaxComputerName = 128, MaxBaseDirLength= MAX_PATH + 1, - MaxArgvParameters = 256 + MaxArgvParameters = 256, + MaxUserName = LOGIN_NAME_MAX }; }; @@ -149,6 +150,45 @@ const TCHAR* FLinuxPlatformProcess::BaseDir() return CachedResult; } +const TCHAR* FLinuxPlatformProcess::UserName(bool bOnlyAlphaNumeric) +{ + static TCHAR Name[PlatformProcessLimits::MaxUserName] = { 0 }; + static bool bHaveResult = false; + + if (!bHaveResult) + { + struct passwd * UserInfo = getpwuid(geteuid()); + if (nullptr != UserInfo && nullptr != UserInfo->pw_name) + { + FString TempName(UTF8_TO_TCHAR(UserInfo->pw_name)); + if (bOnlyAlphaNumeric) + { + const TCHAR *Src = *TempName; + TCHAR * Dst = Name; + for (; *Src != 0 && (Dst - Name) < ARRAY_COUNT(Name) - 1; ++Src) + { + if (FChar::IsAlnum(*Src)) + { + *Dst++ = *Src; + } + } + *Dst++ = 0; + } + else + { + FCString::Strncpy(Name, *TempName, ARRAY_COUNT(Name) - 1); + } + } + else + { + FCString::Sprintf(Name, TEXT("euid%d"), geteuid()); + } + bHaveResult = true; + } + + return Name; +} + const TCHAR* FLinuxPlatformProcess::UserDir() { // The UserDir is where user visible files (such as game projects) live. diff --git a/Engine/Source/Runtime/Core/Public/Linux/LinuxPlatformProcess.h b/Engine/Source/Runtime/Core/Public/Linux/LinuxPlatformProcess.h index 34813e842a6b..cf76872acf46 100644 --- a/Engine/Source/Runtime/Core/Public/Linux/LinuxPlatformProcess.h +++ b/Engine/Source/Runtime/Core/Public/Linux/LinuxPlatformProcess.h @@ -247,6 +247,7 @@ struct CORE_API FLinuxPlatformProcess : public FGenericPlatformProcess static const TCHAR* ComputerName(); static void CleanFileCache(); static const TCHAR* BaseDir(); + static const TCHAR* UserName(bool bOnlyAlphaNumeric = true); static const TCHAR* UserDir(); static const TCHAR* UserSettingsDir(); static const TCHAR* ApplicationSettingsDir();