1 --- base/process/process_iterator_freebsd.cc.orig 2022-04-21 18:48:31 UTC 2 +++ base/process/process_iterator_freebsd.cc 3 @@ -20,7 +20,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* 4 : index_of_kinfo_proc_(), 5 filter_(filter) { 6 7 - int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, getuid() }; 8 + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, (int) getuid() }; 9 10 bool done = false; 11 int try_num = 1; 12 @@ -39,7 +39,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* 13 num_of_kinfo_proc += 16; 14 kinfo_procs_.resize(num_of_kinfo_proc); 15 len = num_of_kinfo_proc * sizeof(struct kinfo_proc); 16 - if (sysctl(mib, std::size(mib), &kinfo_procs_[0], &len, NULL, 0) < 0) { 17 + if (sysctl(mib, std::size(mib), kinfo_procs_.data(), &len, NULL, 0) < 0) { 18 // If we get a mem error, it just means we need a bigger buffer, so 19 // loop around again. Anything else is a real error and give up. 20 if (errno != ENOMEM) { 21 @@ -49,7 +49,7 @@ ProcessIterator::ProcessIterator(const ProcessFilter* 22 } 23 } else { 24 // Got the list, just make sure we're sized exactly right 25 - size_t num_of_kinfo_proc = len / sizeof(struct kinfo_proc); 26 + num_of_kinfo_proc = len / sizeof(struct kinfo_proc); 27 kinfo_procs_.resize(num_of_kinfo_proc); 28 done = true; 29 } 30 @@ -71,18 +71,13 @@ bool ProcessIterator::CheckForNextProcess() { 31 for (; index_of_kinfo_proc_ < kinfo_procs_.size(); ++index_of_kinfo_proc_) { 32 size_t length; 33 struct kinfo_proc kinfo = kinfo_procs_[index_of_kinfo_proc_]; 34 - int mib[] = { CTL_KERN, KERN_PROC_ARGS, kinfo.ki_pid }; 35 + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, kinfo.ki_pid }; 36 37 if ((kinfo.ki_pid > 0) && (kinfo.ki_stat == SZOMB)) 38 continue; 39 40 - length = 0; 41 - if (sysctl(mib, std::size(mib), NULL, &length, NULL, 0) < 0) { 42 - LOG(ERROR) << "failed to figure out the buffer size for a command line"; 43 - continue; 44 - } 45 - 46 - data.resize(length); 47 + data.resize(ARG_MAX); 48 + length = ARG_MAX; 49 50 if (sysctl(mib, std::size(mib), &data[0], &length, NULL, 0) < 0) { 51 LOG(ERROR) << "failed to fetch a commandline"; 52