================
@@ -684,34 +685,59 @@ static bool
GetMacOSXProcessUserAndGroup(ProcessInstanceInfo &process_info) {
return false;
}
-uint32_t Host::FindProcessesImpl(const ProcessInstanceInfoMatch &match_info,
- ProcessInstanceInfoList &process_infos) {
- std::vector<struct kinfo_proc> kinfos;
-
+/// Fetches the list of all processes. Returns true on success.
+[[nodiscard]] static bool
+GetProcessList(std::vector<struct kinfo_proc> &kinfos) {
int mib[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
- size_t pid_data_size = 0;
- if (::sysctl(mib, 3, nullptr, &pid_data_size, nullptr, 0) != 0)
- return 0;
+ // This is an inherently racy API. We have to first query the size for our
+ // buffer and then pass back to sysctl. If more processes spawn between the
+ // size query and the actual call to fetch, then sysctl returns ENOMEM.
+ // We keep retrying until we get a passing result.
+ for (int attempt = 1; attempt < 1024; ++attempt) {
----------------
JDevlieghere wrote:
Nit: Make the retry count a global constant
```suggestion
static constexpr g_retry_count = 1024;
for (int attempt = 1; attempt < g_retry_count; ++attempt) {
```
https://github.com/llvm/llvm-project/pull/204109
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits