shirou / gopsutil

psutil for golang
Other
10.36k stars 1.57k forks source link

Adopt a hierarchy for getting distro name/version on Linux #1576

Open joshuar opened 7 months ago

joshuar commented 7 months ago

Is your feature request related to a problem? Please describe. On Linux, there are many difference files that can provide distribution details. gopsutil should adopt a hierarchy for checking those files, using the information from the first file found.

Describe the solution you'd like While gopsutil does currently adopt this kind of approach, the order of checks could be improved. My suggestion would be something like:

Above, preference the general standards/guideline files first, then the distro-specific files. /etc/os-release appears to be adopted widely, and often contains much more specific information (regarding distribution variants) than the other sources. While /etc/lsb-release usage appears to be waning and discouraged, it is still an important source for this information. The remaining files such as /etc/redhat-release, /etc/SuSE-release, /etc/debian_version, /etc/arch-release, /etc/gentoo-release, /etc/slackware-version, /etc/frugalware-release, /etc/altlinux-release, /etc/mandriva-release, /etc/meego-release, /etc/angstrom-version, /etc/mageia-release may or may not contain variant-specific information.

For example, I would image a lot of variants based on Debian do not edit /etc/debian_version and so relying on this first will report the wrong information (the debian base version, not the variant version). Likewise, if I was going to build my own distribution based on Fedora, I would likely leave /etc/redhat-release untouched and place my distribution information in the /etc/os-release file.

Describe alternatives you've considered For my own usage, my alternative would be to just write my own code to apply the above order.

Additional context Preferencing /etc/os-release over /etc/debian_release for example should fix #1469 and #224 and likely avoid similar issues in the future.