All BSDs use the same implementation to get BootTime{,WithContext} and
Uptime{,WithContext} based on the kern.boottime sysctl. Move this
implementation to a separate host/host_bsd.go file shared by darwin,
freebsd and openbsd. Also use SysctlTimeval to get
the boot time directly as a type Timeval instead of manually
extracting it using package unsafe. It will also allow for easier reuse
to support package host on e.g. Dragonfly BSD or NetBSD.
This requires updating the golang.org/x/sys/unix dependency to the
latest revision.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
TestHostInfoStat_String has been broken since kernelArch has been
introduced. Fix it.
Also adjust the error message to show the wanted string, aligned with
the gotten string so it's easier to spot differences.
The ReadLines helper function doesn't guarantee that the length of
lines is non-zero or that the lines have contents. Most callers
include a check for length but this was missing for version
fingerprinting on Debian if `/etc/debian_version` was empty, leading
to a panic.
The /System/Library/CoreServices/ServerVersion.plist exists on macOS servers , but not on a workstation such as my laptop. The actual terminoly is mostly borrowed from the windows equivalent as @Lomanic suggested. In theory, this should make interpreting the results from the two platforms a bit more consistent.
Note: The macOS server application can be installed on almost any macOS workstation to make it a server that can manage other apple devices.
gopsutil is a transitive dependency of another project that I am integrating
into an internal build system. We target multiple platforms and as a part
of the build system for the large internal repo, we calculate the build
graph used to determine what targets have changed and need to be build /
tested as a single DAG for all platforms.
gopsutil currently does not form a DAG if linux and any other platform are
considered at the same time. linux is the only platform where the process
package imports the host package.
To remove this cycle, the relevant methods have been moved to internal/common
with the linux build tag and are consumed the host and process packages.
Remains backward compatible.
When encountering non-fatal errors SensorsTemperatures() returns the
temperatures for all the sensor we could read successfully. In that
case the custom error contains a list of all the non-fatal errors
encountered.
Example usage:
_, err := SensorsTemperatures()
if err != nil {
warns, ok := err.(*Warnings)
if ok {
fmt.Printf("%v\n", err)
for i, w := range warns.List {
fmt.Printf("Warning %v: %v\n", i+1, w)
}
} else {
t.Errorf("%v", err)
}
}
On Linux, most golang programs do not run as root (or at least, they should not),
by default, the kernels uses strict permissions, so most userland programs cannot
read `/sys/class/dmi/id/product_uuid`. However, programs such as Consul are relying
on it to get fixed IDs, instead they have a different ID on each boot.
We propose to use `/etc/machine-id` as fallback https://www.freedesktop.org/software/systemd/man/machine-id.html
In order to fix this, this patch does the following:
- if `/sys/class/dmi/id/product_uuid` can be read, use it for HostID
- else if `/etc/machine-id` exists and has 32 chars, use it and add '-' to have the same format as product_uuid
- finally, if notthing works, use the `kernel.random.boot_id`
This will greatly increase the number of programs having correct behaviour when
those rely on having a fixed HostID.
This will fix the following issues:
- https://github.com/shirou/gopsutil/issues/350
- https://github.com/hashicorp/consul/issues/4741