diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000..7c83bd5 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,100 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "next" + digest = "1:80f75788f4df66bdfb52fe5c7714878b384ec172e9382ae01c809fe25c028e9b" + name = "github.com/StackExchange/wmi" + packages = ["."] + pruneopts = "UT" + revision = "9f32b5905fd6ce7384093f9d048437e79f7b4d85" + +[[projects]] + digest = "1:50e893a85575fa48dc4982a279e50e2fd8b74e4f7c587860c1e25c77083b8125" + name = "github.com/cihub/seelog" + packages = ["."] + pruneopts = "UT" + revision = "d2c6e5aa9fbfdd1c624e140287063c7730654115" + version = "v2.6" + +[[projects]] + digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" + name = "github.com/davecgh/go-spew" + packages = ["spew"] + pruneopts = "UT" + revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" + version = "v1.1.1" + +[[projects]] + digest = "1:1ae488e919756729db69becc130be75a4820dfdd0775e430a85f726a84ce14ab" + name = "github.com/go-ole/go-ole" + packages = [ + ".", + "oleutil", + ] + pruneopts = "UT" + revision = "de8695c8edbf8236f30d6e1376e20b198a028d42" + +[[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + pruneopts = "UT" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + digest = "1:0dc15f8c051646249461ab843ed26b0126c528032ad8f0df2d291917ae502c12" + name = "github.com/shirou/gopsutil" + packages = [ + "cpu", + "host", + "internal/common", + "mem", + "net", + "process", + ] + pruneopts = "UT" + revision = "e8f7a95747d711f34ddfe9dd9b825a84bd059dec" + version = "v2.0.0" + +[[projects]] + branch = "master" + digest = "1:99c6a6dab47067c9b898e8c8b13d130c6ab4ffbcc4b7cc6236c2cd0b1e344f5b" + name = "github.com/shirou/w32" + packages = ["."] + pruneopts = "UT" + revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b" + +[[projects]] + digest = "1:972c2427413d41a1e06ca4897e8528e5a1622894050e2f527b38ddf0f343f759" + name = "github.com/stretchr/testify" + packages = ["assert"] + pruneopts = "UT" + revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" + version = "v1.3.0" + +[[projects]] + branch = "master" + digest = "1:228f27b6ae6aa190a8082e78c76870062506763cae2526543dc8f7ac9bea0947" + name = "golang.org/x/sys" + packages = [ + "unix", + "windows", + "windows/registry", + ] + pruneopts = "UT" + revision = "77cc2087c03b9062d8eb49dd60e665cbd7c1cde2" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/cihub/seelog", + "github.com/shirou/gopsutil/mem", + "github.com/shirou/gopsutil/process", + "github.com/stretchr/testify/assert", + "golang.org/x/sys/windows/registry", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/go.mod b/go.mod index 37138f9..14d821e 100644 --- a/go.mod +++ b/go.mod @@ -10,5 +10,5 @@ require ( github.com/shirou/gopsutil v2.0.0+incompatible github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/stretchr/testify v1.3.0 - golang.org/x/sys v0.0.0-20170329061634-9a7256cb28ed + golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 ) diff --git a/go.sum b/go.sum index 991a636..7d4cced 100644 --- a/go.sum +++ b/go.sum @@ -18,3 +18,5 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/sys v0.0.0-20170329061634-9a7256cb28ed h1:1RoWulWaFGB+t8NExLratqmgydjWzGMhG2wyOqZxifQ= golang.org/x/sys v0.0.0-20170329061634-9a7256cb28ed/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/platform/platform_darwin.go b/platform/platform_darwin.go index 77c61e1..7f092da 100644 --- a/platform/platform_darwin.go +++ b/platform/platform_darwin.go @@ -1,9 +1,27 @@ package platform -import "strings" +import ( + "strings" + + log "github.com/cihub/seelog" + "golang.org/x/sys/unix" +) var unameOptions = []string{"-s", "-n", "-r", "-m", "-p"} +// processIsTranslated detects if the process using gohai is running under the Rosetta 2 translator +func processIsTranslated() (bool, error) { + // https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616845 + ret, err := unix.SysctlUint32("sysctl.proc_translated") + + if err == nil { + return ret == 1, nil + } else if err.(unix.Errno) == unix.ENOENT { + return false, nil + } + return false, err +} + func updateArchInfo(archInfo map[string]interface{}, values []string) { archInfo["kernel_name"] = values[0] archInfo["hostname"] = values[1] @@ -11,4 +29,12 @@ func updateArchInfo(archInfo map[string]interface{}, values []string) { archInfo["machine"] = values[3] archInfo["processor"] = strings.Trim(values[4], "\n") archInfo["os"] = values[0] + + if isTranslated, err := processIsTranslated(); err == nil && isTranslated { + log.Debug("Running under Rosetta translator; overriding architecture values") + archInfo["processor"] = "arm" + archInfo["machine"] = "arm64" + } else if err != nil { + log.Debugf("Error when detecting Rosetta translator: %s", err) + } }