Mercurial > libanimone
comparison src/fd/proc.cc @ 6:f26b08274dcf
dep/animone: filter open files by access mode
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Fri, 12 Apr 2024 19:13:50 -0400 |
| parents | a76fa32bdc92 |
| children | 27b988a1048c |
comparison
equal
deleted
inserted
replaced
| 5:6d6d2b51517b | 6:f26b08274dcf |
|---|---|
| 34 int flags = 0; | 34 int flags = 0; |
| 35 for (std::string line; std::getline(file, line);) | 35 for (std::string line; std::getline(file, line);) |
| 36 if (line.find("flags:", 0) == 0) | 36 if (line.find("flags:", 0) == 0) |
| 37 flags = util::StringToInt(line.substr(line.find_last_not_of("0123456789") + 1)); | 37 flags = util::StringToInt(line.substr(line.find_last_not_of("0123456789") + 1)); |
| 38 | 38 |
| 39 if (flags & O_WRONLY || flags & O_RDWR) | 39 /* check if the file was opened in a write mode */ |
| 40 int accflags = flags & O_ACCMODE; | |
| 41 if (accflags == O_WRONLY || accflags == O_RDWR) | |
| 40 return false; | 42 return false; |
| 41 | 43 |
| 42 return true; | 44 return true; |
| 43 } | 45 } |
| 44 | 46 |
| 63 | 65 |
| 64 static bool IsSystemFile(const std::string& path) { | 66 static bool IsSystemFile(const std::string& path) { |
| 65 static constexpr std::array<std::string_view, 9> invalid_paths = {"/boot", "/dev", "/bin", "/usr", "/opt", | 67 static constexpr std::array<std::string_view, 9> invalid_paths = {"/boot", "/dev", "/bin", "/usr", "/opt", |
| 66 "/proc", "/var", "/etc", "/dev"}; | 68 "/proc", "/var", "/etc", "/dev"}; |
| 67 | 69 |
| 68 for (const auto& invalid_path : invalid_paths) { | 70 for (const auto& invalid_path : invalid_paths) |
| 69 if (!path.rfind(invalid_path, 0)) { | 71 if (!path.rfind(invalid_path, 0)) |
| 70 return true; | 72 return true; |
| 71 } | |
| 72 } | |
| 73 | 73 |
| 74 return false; | 74 return false; |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool GetProcessName(pid_t pid, std::string& result) { | 77 bool GetProcessName(pid_t pid, std::string& result) { |
