13#include "llvm/ADT/SmallString.h"
14#include "llvm/ADT/Twine.h"
15#include "llvm/Support/Path.h"
16#include "llvm/Support/raw_ostream.h"
25#include <sys/utsname.h>
34 hostname[
sizeof(hostname) - 1] =
'\0';
35 if (::gethostname(hostname,
sizeof(hostname) - 1) == 0) {
47 return std::string(un.version);
51#include <android/api-level.h>
53#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
60 std::optional<std::string> DoGetUserName(id_t uid)
override;
61 std::optional<std::string> DoGetGroupName(id_t gid)
override;
76 if (
auto *user_info_ptr = ::getpwuid(uid))
77 return PasswdEntry{user_info_ptr->pw_name, user_info_ptr->pw_shell};
79 struct passwd user_info;
80 struct passwd *user_info_ptr = &user_info;
82 size_t user_buffer_size =
sizeof(user_buffer);
83 if (::getpwuid_r(uid, &user_info, user_buffer, user_buffer_size,
84 &user_info_ptr) == 0 &&
86 return PasswdEntry{user_info_ptr->pw_name, user_info_ptr->pw_shell};
92std::optional<std::string> PosixUserIDResolver::DoGetUserName(id_t uid) {
93 if (std::optional<PasswdEntry> password =
GetPassword(uid))
98std::optional<std::string> PosixUserIDResolver::DoGetGroupName(id_t gid) {
101 size_t group_buffer_size =
sizeof(group_buffer);
102 struct group group_info;
103 struct group *group_info_ptr = &group_info;
105 if (::getgrgid_r(gid, &group_info, group_buffer, group_buffer_size,
106 &group_info_ptr) == 0) {
108 return std::string(group_info_ptr->gr_name);
112 group_info_ptr = ::getgrgid(gid);
114 return std::string(group_info_ptr->gr_name);
135 if (
const char *v = ::getenv(
"SHELL"))
137 if (std::optional<PasswdEntry> password =
GetPassword(::geteuid()))
147 FileSpec temp_file(
"/opt/local/include/lldb");
154 if (
const char *pvar = ::getenv(var_name.c_str())) {
155 var = std::string(pvar);
static llvm::ManagedStatic< PosixUserIDResolver > g_user_id_resolver
static std::optional< PasswdEntry > GetPassword(id_t uid)
void SetDirectory(ConstString directory)
Directory string set accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static bool ComputePathRelativeToLibrary(FileSpec &file_spec, llvm::StringRef dir)
static uint32_t GetUserID()
static bool ComputeSupportExeDirectory(FileSpec &file_spec)
static bool GetHostname(std::string &s)
static std::optional< std::string > GetOSKernelDescription()
static FileSpec GetDefaultShell()
static uint32_t GetEffectiveUserID()
static bool GetEnvironmentVar(const std::string &var_name, std::string &var)
static size_t GetPageSize()
static uint32_t GetGroupID()
static uint32_t GetEffectiveGroupID()
static UserIDResolver & GetUserIDResolver()
static bool ComputeHeaderDirectory(FileSpec &file_spec)
An abstract interface for things that know how to map numeric user/group IDs into names.
A class that represents a running process on the host machine.