[macOS M1] Backports from upstream to fix cpu.Info() crashes #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since #40, we can build projects containing this
gopsutil
fork on macOS M1.However, using
cpu.Info()
causes a crash:sysctl hw.cpufrequency
doesn't return anything on M1, which makes the following snippet crash:with an index out-of-range error.
This PR:
golang.org/x/sys/unix.Sysctl
instead of manual calls to thesysctl
binary, preventing the crashcpu.Info()
return an error when the CPU frequency cannot be found, to prevent the method from erroring on M1.The drawback of this approach is that the CPU frequency won't be available on M1, but according to the discussions in shirou#1000 and giampaolo/psutil#1892, no definitive solution to this issue has been found yet.