| 28 | namespace crashpad { |
| 29 | |
| 30 | bool ReadThreadIDs(pid_t pid, std::vector<pid_t>* tids) { |
| 31 | DCHECK(tids->empty()); |
| 32 | |
| 33 | char path[32]; |
| 34 | snprintf(path, std::size(path), "/proc/%d/task", pid); |
| 35 | DirectoryReader reader; |
| 36 | if (!reader.Open(base::FilePath(path))) { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | std::vector<pid_t> local_tids; |
| 41 | base::FilePath tid_str; |
| 42 | DirectoryReader::Result result; |
| 43 | while ((result = reader.NextFile(&tid_str)) == |
| 44 | DirectoryReader::Result::kSuccess) { |
| 45 | pid_t tid; |
| 46 | if (!base::StringToInt(tid_str.value(), &tid)) { |
| 47 | LOG(ERROR) << "format error"; |
| 48 | continue; |
| 49 | } |
| 50 | |
| 51 | local_tids.push_back(tid); |
| 52 | } |
| 53 | DCHECK_EQ(AsUnderlyingType(result), |
| 54 | AsUnderlyingType(DirectoryReader::Result::kNoMoreFiles)); |
| 55 | DCHECK(!local_tids.empty()); |
| 56 | |
| 57 | tids->swap(local_tids); |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | } // namespace crashpad |