From 89828d1f9c42c5fdd4a6102265db9b41c6d59004 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Wed, 27 Mar 2019 15:05:12 -0400 Subject: [PATCH] Update github.com/elastic/go-sysinfo Fixes #11490 (cherry picked from commit 548dbae7da49c69d4180c15249dd9384449e6c6b) --- NOTICE.txt | 2 +- .../go-sysinfo/providers/linux/container.go | 5 +++ .../go-sysinfo/providers/linux/machineid.go | 32 +++++++++++++++++-- .../elastic/go-sysinfo/providers/linux/os.go | 5 +-- vendor/vendor.json | 30 ++++++++--------- 5 files changed, 53 insertions(+), 21 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index dc031a017bb8..2fe3949b3ca9 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -643,7 +643,7 @@ Apache License 2.0 -------------------------------------------------------------------- Dependency: github.com/elastic/go-sysinfo -Revision: 59ef8c0eae46c0929e3b219ac86368d4b5934f91 +Revision: ab4f04edfc3d6b3864f5f06a068ddab9ad79774f License type (autodetected): Apache-2.0 ./vendor/github.com/elastic/go-sysinfo/LICENSE.txt: -------------------------------------------------------------------- diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/container.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/container.go index 45a8e9b6f367..cfacf013d12e 100644 --- a/vendor/github.com/elastic/go-sysinfo/providers/linux/container.go +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/container.go @@ -21,6 +21,7 @@ import ( "bufio" "bytes" "io/ioutil" + "os" "github.com/pkg/errors" ) @@ -31,6 +32,10 @@ const procOneCgroup = "/proc/1/cgroup" func IsContainerized() (bool, error) { data, err := ioutil.ReadFile(procOneCgroup) if err != nil { + if os.IsNotExist(err) { + return false, nil + } + return false, errors.Wrap(err, "failed to read process cgroups") } diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go index b5ff05385640..a84d085c9eab 100644 --- a/vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go @@ -27,11 +27,37 @@ import ( "github.com/elastic/go-sysinfo/types" ) +var ( + // Possible (current and historic) locations of the machine-id file. + // These will be searched in order. + machineIDFiles = []string{"/etc/machine-id", "/var/lib/dbus/machine-id", "/var/db/dbus/machine-id"} +) + func MachineID() (string, error) { - id, err := ioutil.ReadFile("/etc/machine-id") + var contents []byte + var err error + + for _, file := range machineIDFiles { + contents, err = ioutil.ReadFile(file) + if err != nil { + if os.IsNotExist(err) { + // Try next location + continue + } + + // Return with error on any other error + return "", errors.Wrapf(err, "failed to read %v", file) + } + + // Found it + break + } + if os.IsNotExist(err) { + // None of the locations existed return "", types.ErrNotImplemented } - id = bytes.TrimSpace(id) - return string(id), errors.Wrap(err, "failed to read machine-id") + + contents = bytes.TrimSpace(contents) + return string(contents), nil } diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/os.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/os.go index a54c1d3258a5..d4daedd506f8 100644 --- a/vendor/github.com/elastic/go-sysinfo/providers/linux/os.go +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/os.go @@ -47,9 +47,10 @@ var ( versionRegexp = regexp.MustCompile(versionGrok) ) +// familyMap contains a mapping of family -> []platforms. var familyMap = map[string][]string{ - "redhat": {"redhat", "fedora", "centos", "scientific", "oraclelinux", "amazon"}, - "debian": {"debian", "ubuntu"}, + "redhat": {"redhat", "fedora", "centos", "scientific", "oraclelinux", "amzn", "rhel"}, + "debian": {"debian", "ubuntu", "raspbian"}, "suse": {"suse", "sles", "opensuse"}, } diff --git a/vendor/vendor.json b/vendor/vendor.json index d4bcd302afc4..6008af2705c0 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -951,44 +951,44 @@ { "checksumSHA1": "QhFIpuHPaV6hKejKcc2wm6y4MSQ=", "path": "github.com/elastic/go-sysinfo", - "revision": "59ef8c0eae46c0929e3b219ac86368d4b5934f91", - "revisionTime": "2019-01-07T12:18:35Z" + "revision": "ab4f04edfc3d6b3864f5f06a068ddab9ad79774f", + "revisionTime": "2019-03-27T18:53:17Z" }, { "checksumSHA1": "GiZCjX17K265TtamGZZw4R2Jwbk=", "path": "github.com/elastic/go-sysinfo/internal/registry", - "revision": "59ef8c0eae46c0929e3b219ac86368d4b5934f91", - "revisionTime": "2019-01-07T12:18:35Z" + "revision": "ab4f04edfc3d6b3864f5f06a068ddab9ad79774f", + "revisionTime": "2019-03-27T18:53:17Z" }, { "checksumSHA1": "ovafihHzpBx9Y7+lZh9X5KwNCvE=", "path": "github.com/elastic/go-sysinfo/providers/darwin", - "revision": "59ef8c0eae46c0929e3b219ac86368d4b5934f91", - "revisionTime": "2019-01-07T12:18:35Z" + "revision": "ab4f04edfc3d6b3864f5f06a068ddab9ad79774f", + "revisionTime": "2019-03-27T18:53:17Z" }, { - "checksumSHA1": "AK76ZxnuvK02Dfpmj7b2TD/aiSI=", + "checksumSHA1": "OyI+VwDiT4UZjncsDr1GYg1xcdw=", "path": "github.com/elastic/go-sysinfo/providers/linux", - "revision": "59ef8c0eae46c0929e3b219ac86368d4b5934f91", - "revisionTime": "2019-01-07T12:18:35Z" + "revision": "ab4f04edfc3d6b3864f5f06a068ddab9ad79774f", + "revisionTime": "2019-03-27T18:53:17Z" }, { "checksumSHA1": "RWLvcP1w9ynKbuCqiW6prwd+EDU=", "path": "github.com/elastic/go-sysinfo/providers/shared", - "revision": "59ef8c0eae46c0929e3b219ac86368d4b5934f91", - "revisionTime": "2019-01-07T12:18:35Z" + "revision": "ab4f04edfc3d6b3864f5f06a068ddab9ad79774f", + "revisionTime": "2019-03-27T18:53:17Z" }, { "checksumSHA1": "aF05MEkMjbRekzHlwFxmd5WBpeY=", "path": "github.com/elastic/go-sysinfo/providers/windows", - "revision": "59ef8c0eae46c0929e3b219ac86368d4b5934f91", - "revisionTime": "2019-01-07T12:18:35Z" + "revision": "ab4f04edfc3d6b3864f5f06a068ddab9ad79774f", + "revisionTime": "2019-03-27T18:53:17Z" }, { "checksumSHA1": "MLQioPEjULYbNqqCjfB1/cux08E=", "path": "github.com/elastic/go-sysinfo/types", - "revision": "59ef8c0eae46c0929e3b219ac86368d4b5934f91", - "revisionTime": "2019-01-07T12:18:35Z" + "revision": "ab4f04edfc3d6b3864f5f06a068ddab9ad79774f", + "revisionTime": "2019-03-27T18:53:17Z" }, { "checksumSHA1": "bNf3GDGhZh86bfCIMM5c5AYfo3g=",