Commit 83a9e292 authored by williangaspar's avatar williangaspar

indentation and mapkey

parent 5f9875a6
......@@ -1112,44 +1112,45 @@ std::string BPFtrace::get_stack(uint64_t stackidpid, bool ustack, int indent)
std::string BPFtrace::resolve_uid(uintptr_t addr)
{
std::string file_name = "/etc/passwd";
std::string uid = std::to_string(addr);
std::string username = "";
std::string file_name = "/etc/passwd";
std::string uid = std::to_string(addr);
std::string username = "";
std::ifstream file(file_name);
if (file.fail())
{
std::cerr << strerror(errno) << ": " << file_name << std::endl;
return username;
}
std::ifstream file(file_name);
if (file.fail())
{
std::cerr << strerror(errno) << ": " << file_name << std::endl;
return username;
}
std::string line;
bool found = false;
std::string line;
bool found = false;
while (std::getline(file, line) && !found)
{
auto fields = split_string(line, ':');
while (std::getline(file, line) && !found)
if (fields[2] == uid)
{
auto fields = split_string(line, ':');
if (fields[2] == uid) {
found = true;
username = fields[0];
}
found = true;
username = fields[0];
}
}
file.close();
file.close();
return username;
return username;
}
std::vector<std::string> BPFtrace::split_string(std::string &str, char split_by)
{
std::vector<std::string> elems;
std::stringstream ss(str);
std::string value;
while(std::getline(ss, value, split_by)) {
elems.push_back(value);
}
return elems;
std::vector<std::string> elems;
std::stringstream ss(str);
std::string value;
while(std::getline(ss, value, split_by)) {
elems.push_back(value);
}
return elems;
}
std::string BPFtrace::resolve_sym(uintptr_t addr, bool show_offset)
......
......@@ -74,6 +74,8 @@ std::string MapKey::argument_value(BPFtrace &bpftrace,
return bpftrace.resolve_sym(*(uint64_t*)data);
case Type::usym:
return bpftrace.resolve_usym(*(uint64_t*)data, *(uint64_t*)(arg_data + 8));
case Type::username:
return bpftrace.resolve_uid(*(uint64_t*)data);
case Type::name:
return bpftrace.name_ids_[*(uint64_t*)data];
case Type::string:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment