in providers/linux/arch_linux.go [53:86]
func NativeArchitecture() (string, error) {
// /proc/sys/kernel/arch was introduced in Kernel 6.1
// https://www.kernel.org/doc/html/v6.1/admin-guide/sysctl/kernel.html#arch
// It's the same as uname -m, except that for a process running in emulation
// machine returned from syscall reflects the emulated machine, whilst /proc
// filesystem is read as file so its value is not emulated
data, err := os.ReadFile(procSysKernelArch)
if err != nil {
if os.IsNotExist(err) {
// fallback to checking version string for older kernels
version, err := os.ReadFile(procVersion)
if err != nil && !os.IsNotExist(err) {
return "", fmt.Errorf("failed to read kernel version: %w", err)
}
versionStr := string(version)
if strings.Contains(versionStr, archAmd64) || strings.Contains(versionStr, arch8664) {
return archAmd64, nil
} else if strings.Contains(versionStr, archArm64) || strings.Contains(versionStr, archAarch64) {
// for parity with Architecture() and /proc/sys/kernel/arch
// as aarch64 and arm64 are used interchangeably
return archAarch64, nil
}
return "", nil
}
return "", fmt.Errorf("failed to read kernel arch: %w", err)
}
nativeArch := string(data)
nativeArch = strings.TrimRight(nativeArch, "\n")
return nativeArch, nil
}