Fixed: Uid -> User fallback to getpwuid() if failure for non static builds

This commit is contained in:
aristocratos 2021-10-06 10:47:24 +02:00
parent 8c0b815bc1
commit 69c5eba1db
2 changed files with 25 additions and 2 deletions

View File

@ -24,7 +24,7 @@ ifeq ($(ARCH),x86_64)
endif
ifeq ($(STATIC),true)
override ADDFLAGS += -static -static-libgcc -static-libstdc++
override ADDFLAGS += -D STATIC_BUILD -static -static-libgcc -static-libstdc++
endif
#? Make sure PLATFORM Darwin is OSX and not Darwin

View File

@ -27,6 +27,10 @@ tab-size = 4
#include <ifaddrs.h>
#include <net/if.h>
#ifndef STATIC_BUILD
#include <pwd.h>
#endif
#include <btop_shared.hpp>
#include <btop_config.hpp>
#include <btop_tools.hpp>
@ -1416,7 +1420,26 @@ namespace Proc {
}
}
pread.close();
new_proc.user = (uid_user.contains(uid)) ? uid_user.at(uid) : uid;
if (uid_user.contains(uid)) {
new_proc.user = uid_user.at(uid);
}
else {
#ifndef STATIC_BUILD
try {
struct passwd* udet;
udet = getpwuid(stoi(uid));
if (udet != NULL and udet->pw_name != NULL) {
new_proc.user = string(udet->pw_name);
}
else {
new_proc.user = uid;
}
}
catch (...) { new_proc.user = uid; }
#else
new_proc.user = uid;
#endif
}
}
//? Parse /proc/[pid]/stat