Skip to content

Commit 3f16891

Browse files
committed
Also resolve user
1 parent ab0aa46 commit 3f16891

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ProcessRoster.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <cstdlib>
1414
#include <dirent.h>
1515
#include <iostream>
16+
#include <pwd.h>
1617

1718

1819
static bool
@@ -57,7 +58,15 @@ RunningProcessesList::_ReadProcessInfo(process_info& info, std::string pid)
5758
info.pid = strtol(pid.c_str(), NULL, 10);
5859
info.cmdline = ProcReader(("/proc/" + pid + std::string("/cmdline")).c_str()).ReadLine();
5960

60-
// TODO: Refactor, too much duplicated code
61+
std::string loginUid = ProcReader(("/proc/" + pid + std::string("/loginuid")).c_str()).ReadLine();
62+
struct passwd* passwdStruct = getpwuid(strtoull(loginUid.c_str(), NULL, 10));
63+
if (passwdStruct != NULL)
64+
info.user = passwdStruct->pw_name;
65+
else {
66+
// TODO: Not nice. What to do in this case ?
67+
info.user = "root";
68+
}
69+
// TODO: Refactor, too much duplicated code
6170
ProcReader status(("/proc/" + pid + std::string("/status")).c_str());
6271

6372
std::istream stream(&status);

0 commit comments

Comments
 (0)