From 192db801d174f61e710ad422efc2e951cbca24de Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Wed, 16 Aug 2017 15:05:24 -0700 Subject: [PATCH] Update gopsutil to stop calling SetEnv Fixes #3036 --- vendor/github.com/shirou/gopsutil/Makefile | 4 +- .../shirou/gopsutil/disk/disk_fallback.go | 2 +- .../shirou/gopsutil/host/host_darwin.go | 10 +-- .../shirou/gopsutil/host/host_fallback.go | 8 +++ .../shirou/gopsutil/host/host_freebsd.go | 10 +-- .../shirou/gopsutil/host/host_openbsd.go | 10 +-- .../shirou/gopsutil/host/host_solaris.go | 68 +++++++++++++++++++ .../shirou/gopsutil/host/host_windows.go | 9 +++ .../gopsutil/internal/common/common_linux.go | 17 +++-- .../shirou/gopsutil/process/process_linux.go | 19 ++++-- vendor/vendor.json | 42 ++++++------ 11 files changed, 154 insertions(+), 45 deletions(-) diff --git a/vendor/github.com/shirou/gopsutil/Makefile b/vendor/github.com/shirou/gopsutil/Makefile index 987af227f..dbe306ac5 100644 --- a/vendor/github.com/shirou/gopsutil/Makefile +++ b/vendor/github.com/shirou/gopsutil/Makefile @@ -20,7 +20,7 @@ build_test: ## test only buildable CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) GOOS=windows go test ./... | $(BUILD_FAIL_PATTERN) # Operating systems supported for building only (not implemented error if used) - GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN) +# GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) @echo 'Successfully built on all known operating systems' diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go b/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go index db521842d..ae9ffa852 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!openbsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris package disk diff --git a/vendor/github.com/shirou/gopsutil/host/host_darwin.go b/vendor/github.com/shirou/gopsutil/host/host_darwin.go index c5b24b853..0ea6d5149 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_darwin.go +++ b/vendor/github.com/shirou/gopsutil/host/host_darwin.go @@ -181,8 +181,10 @@ func PlatformInformation() (string, string, string, error) { } func Virtualization() (string, string, error) { - system := "" - role := "" - - return system, role, nil + return "", "", common.ErrNotImplementedError +} + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err } diff --git a/vendor/github.com/shirou/gopsutil/host/host_fallback.go b/vendor/github.com/shirou/gopsutil/host/host_fallback.go index bfd01432b..173f58c6a 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_fallback.go +++ b/vendor/github.com/shirou/gopsutil/host/host_fallback.go @@ -19,3 +19,11 @@ func Uptime() (uint64, error) { func Users() ([]UserStat, error) { return []UserStat{}, common.ErrNotImplementedError } + +func Virtualization() (string, string, error) { + return "", "", common.ErrNotImplementedError +} + +func KernelVersion() (string, error) { + return "", common.ErrNotImplementedError +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_freebsd.go b/vendor/github.com/shirou/gopsutil/host/host_freebsd.go index e7924f90d..6b2962cf6 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_freebsd.go +++ b/vendor/github.com/shirou/gopsutil/host/host_freebsd.go @@ -174,10 +174,7 @@ func PlatformInformation() (string, string, string, error) { } func Virtualization() (string, string, error) { - system := "" - role := "" - - return system, role, nil + return "", "", common.ErrNotImplementedError } // before 9.0 @@ -222,3 +219,8 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) { func SensorsTemperatures() ([]TemperatureStat, error) { return []TemperatureStat{}, common.ErrNotImplementedError } + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_openbsd.go b/vendor/github.com/shirou/gopsutil/host/host_openbsd.go index 5565bc3a0..13000b52d 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_openbsd.go +++ b/vendor/github.com/shirou/gopsutil/host/host_openbsd.go @@ -110,10 +110,7 @@ func PlatformInformation() (string, string, string, error) { } func Virtualization() (string, string, error) { - system := "" - role := "" - - return system, role, nil + return "", "", common.ErrNotImplementedError } func Users() ([]UserStat, error) { @@ -158,3 +155,8 @@ func Users() ([]UserStat, error) { func SensorsTemperatures() ([]TemperatureStat, error) { return []TemperatureStat{}, common.ErrNotImplementedError } + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_solaris.go b/vendor/github.com/shirou/gopsutil/host/host_solaris.go index 41391cd8a..24461fd93 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_solaris.go +++ b/vendor/github.com/shirou/gopsutil/host/host_solaris.go @@ -2,6 +2,7 @@ package host import ( "bufio" + "bytes" "fmt" "io/ioutil" "os" @@ -76,6 +77,50 @@ func Info() (*InfoStat, error) { } } + switch result.Platform { + case "SmartOS": + // If everything works, use the current zone ID as the HostID if present. + zonename, err := exec.LookPath("/usr/bin/zonename") + if err == nil { + out, err := invoke.Command(zonename) + if err == nil { + sc := bufio.NewScanner(bytes.NewReader(out)) + for sc.Scan() { + line := sc.Text() + + // If we're in the global zone, rely on the hostname. + if line == "global" { + hostname, err := os.Hostname() + if err == nil { + result.HostID = hostname + } + } else { + result.HostID = strings.TrimSpace(line) + break + } + } + } + } + } + + // If HostID is still empty, use hostid(1), which can lie to callers but at + // this point there are no hardware facilities available. This behavior + // matches that of other supported OSes. + if result.HostID == "" { + hostID, err := exec.LookPath("/usr/bin/hostid") + if err == nil { + out, err := invoke.Command(hostID) + if err == nil { + sc := bufio.NewScanner(bytes.NewReader(out)) + for sc.Scan() { + line := sc.Text() + result.HostID = strings.TrimSpace(line) + break + } + } + } + } + // Find the boot time and calculate uptime relative to it bootTime, err := BootTime() if err != nil { @@ -134,3 +179,26 @@ func Users() ([]UserStat, error) { func SensorsTemperatures() ([]TemperatureStat, error) { return []TemperatureStat{}, common.ErrNotImplementedError } + +func Virtualization() (string, string, error) { + return "", "", common.ErrNotImplementedError +} + +func KernelVersion() (string, error) { + // Parse versions from output of `uname(1)` + uname, err := exec.LookPath("/usr/bin/uname") + if err != nil { + return "", err + } + + out, err := invoke.Command(uname, "-srv") + if err != nil { + return "", err + } + + fields := strings.Fields(string(out)) + if len(fields) >= 2 { + return fields[1], nil + } + return "", fmt.Errorf("could not get kernel version") +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_windows.go b/vendor/github.com/shirou/gopsutil/host/host_windows.go index 4826f164e..98943021b 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_windows.go +++ b/vendor/github.com/shirou/gopsutil/host/host_windows.go @@ -188,3 +188,12 @@ func Users() ([]UserStat, error) { func SensorsTemperatures() ([]TemperatureStat, error) { return []TemperatureStat{}, common.ErrNotImplementedError } + +func Virtualization() (string, string, error) { + return "", "", common.ErrNotImplementedError +} + +func KernelVersion() (string, error) { + _, _, version, err := PlatformInformation() + return version, err +} diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common_linux.go b/vendor/github.com/shirou/gopsutil/internal/common/common_linux.go index c0aa9c78e..5347b609a 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common_linux.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common_linux.go @@ -9,15 +9,24 @@ import ( ) func DoSysctrl(mib string) ([]string, error) { - err := os.Setenv("LC_ALL", "C") - if err != nil { - return []string{}, err + hostEnv := os.Environ() + foundLC := false + for i, line := range hostEnv { + if strings.HasPrefix(line, "LC_ALL") { + hostEnv[i] = "LC_ALL=C" + foundLC = true + } + } + if !foundLC { + hostEnv = append(hostEnv, "LC_ALL=C") } sysctl, err := exec.LookPath("/sbin/sysctl") if err != nil { return []string{}, err } - out, err := exec.Command(sysctl, "-n", mib).Output() + cmd := exec.Command(sysctl, "-n", mib) + cmd.Env = hostEnv + out, err := cmd.Output() if err != nil { return []string{}, err } diff --git a/vendor/github.com/shirou/gopsutil/process/process_linux.go b/vendor/github.com/shirou/gopsutil/process/process_linux.go index c0d81c28a..b090dd9c8 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_linux.go +++ b/vendor/github.com/shirou/gopsutil/process/process_linux.go @@ -219,8 +219,8 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) { // NumFDs returns the number of File Descriptors used by the process. func (p *Process) NumFDs() (int32, error) { - numFds, _, err := p.fillFromfd() - return numFds, err + _, fnames, err := p.fillFromfdList() + return int32(len(fnames)), err } // NumThreads returns the number of threads used by the process. @@ -514,16 +514,25 @@ func (p *Process) fillFromLimits() ([]RlimitStat, error) { return limitStats, nil } -// Get num_fds from /proc/(pid)/fd -func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) { +// Get list of /proc/(pid)/fd files +func (p *Process) fillFromfdList() (string, []string, error) { pid := p.Pid statPath := common.HostProc(strconv.Itoa(int(pid)), "fd") d, err := os.Open(statPath) if err != nil { - return 0, nil, err + return statPath, []string{}, err } defer d.Close() fnames, err := d.Readdirnames(-1) + return statPath, fnames, err +} + +// Get num_fds from /proc/(pid)/fd +func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) { + statPath, fnames, err := p.fillFromfdList() + if err != nil { + return 0, nil, err + } numFDs := int32(len(fnames)) var openfiles []*OpenFilesStat diff --git a/vendor/vendor.json b/vendor/vendor.json index 9cafd3045..d7a51d6e9 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1146,52 +1146,52 @@ "revisionTime": "2016-04-29T17:20:22Z" }, { - "checksumSHA1": "E46Dj2ZLd5acESd5H2eJFUXWvOk=", + "checksumSHA1": "Hb1sfQh9zulWvKHq1eJB/Egteuc=", "path": "github.com/shirou/gopsutil", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { "checksumSHA1": "T2ThCk35wXAZGh37nrgA07199dA=", "path": "github.com/shirou/gopsutil/cpu", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { - "checksumSHA1": "MHee+YeuZOzzMIUPVPgXnWgH3jI=", + "checksumSHA1": "T4uyVXPqCS5rj4vYLgv04as0Avw=", "path": "github.com/shirou/gopsutil/disk", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { - "checksumSHA1": "G8v/DPfSDCCVGLVwLzDul6Jt5Oc=", + "checksumSHA1": "YBXpUckp1TtJf2mfMLx/bpnm22Q=", "path": "github.com/shirou/gopsutil/host", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { - "checksumSHA1": "YfGdUgCoLdHBhfG+kXczYXu/rKk=", + "checksumSHA1": "np3IEfSkqCxxEnVBFB86AORndoI=", "path": "github.com/shirou/gopsutil/internal/common", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { "checksumSHA1": "xIAuacHA0LNq1yM5Wd1q4lnbzxU=", "path": "github.com/shirou/gopsutil/mem", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { "checksumSHA1": "moxD+mq0dMHnbTeFyeEHK0Iq7i8=", "path": "github.com/shirou/gopsutil/net", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { - "checksumSHA1": "BbMfjHQ8vWKK4mJb8nj5guX7dgw=", + "checksumSHA1": "C6ybAAUmWz+PQKqJ8byV7Nj5JXQ=", "path": "github.com/shirou/gopsutil/process", - "revision": "42b5d5abb29c3033399cd15ef34104715ea487fc", - "revisionTime": "2017-07-28T02:04:42Z" + "revision": "565f5c8c5e5f8cf2f8a92cf9375f2f1c0e3ea034", + "revisionTime": "2017-08-16T21:54:50Z" }, { "checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=",