Mercurial > minori
comparison dep/animia/src/fd/linux.cc @ 139:478f3b366199
dep/animia: separate lots of things, use base class for OS stuff
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 12 Nov 2023 16:43:07 -0500 |
| parents | 28842a8d0c6b |
| children | 1e696863b54c |
comparison
equal
deleted
inserted
replaced
| 138:28842a8d0c6b | 139:478f3b366199 |
|---|---|
| 89 } | 89 } |
| 90 | 90 |
| 91 return ret.c_str(); | 91 return ret.c_str(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool GetAllPids(std::set<pid_t>& pids) { | 94 bool LinuxFdTools::GetAllPids(std::set<pid_t>& pids) { |
| 95 for (const auto& dir : get_all_files_in_dir(PROC_LOCATION)) { | 95 for (const auto& dir : get_all_files_in_dir(PROC_LOCATION)) { |
| 96 pid_t pid; | 96 pid_t pid; |
| 97 try { | 97 try { |
| 98 pid = std::stoul(basename(dir)); | 98 pid = std::stoul(basename(dir)); |
| 99 } catch (std::invalid_argument) { | 99 } catch (std::invalid_argument) { |
| 101 } | 101 } |
| 102 pids.push_back(pid); | 102 pids.push_back(pid); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 bool GetProcessName(pid_t pid, std::string& result) { | 106 bool LinuxFdTools::GetProcessName(pid_t pid, std::string& result) { |
| 107 const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/comm"; | 107 const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/comm"; |
| 108 | 108 |
| 109 std::string result = util::ReadFile(path); | 109 std::string result = util::ReadFile(path); |
| 110 result.erase(std::remove(result.begin(), result.end(), '\n'), result.end()); | 110 result.erase(std::remove(result.begin(), result.end(), '\n'), result.end()); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) { | 113 bool LinuxFdTools::EnumerateOpenFiles(const std::set<pid_t>& pids, std::vector<std::tuple<pid_t, std::string>>& files) { |
| 114 for (const auto& pid : pids) { | 114 for (const auto& pid : pids) { |
| 115 const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fd"; | 115 const std::string path = PROC_LOCATION "/" + std::to_string(pid) + "/fd"; |
| 116 | 116 |
| 117 for (const auto& dir : GetAllFilesInDir(path)) { | 117 for (const auto& dir : GetAllFilesInDir(path)) { |
| 118 if (!AreFlagsOk(pid, std::stoi(basename(dir)))) | 118 if (!AreFlagsOk(pid, std::stoi(basename(dir)))) |
