diff --git a/go.mod b/go.mod index dcfabfbf04f..3fe00c6a4b8 100644 --- a/go.mod +++ b/go.mod @@ -57,7 +57,7 @@ require ( github.com/opencontainers/selinux v1.12.0 github.com/openshift/imagebuilder v1.2.19 github.com/rootless-containers/rootlesskit/v2 v2.3.5 - github.com/shirou/gopsutil/v4 v4.25.9 + github.com/shirou/gopsutil/v4 v4.25.10 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.10.1 github.com/spf13/pflag v1.0.10 diff --git a/go.sum b/go.sum index 773dbc6afb6..7f915b44848 100644 --- a/go.sum +++ b/go.sum @@ -361,8 +361,8 @@ github.com/segmentio/ksuid v1.0.4 h1:sBo2BdShXjmcugAMwjugoGUdUV0pcxY5mW4xKRn3v4c github.com/segmentio/ksuid v1.0.4/go.mod h1:/XUiZBD3kVx5SmUOl55voK5yeAbBNNIed+2O73XgrPE= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= -github.com/shirou/gopsutil/v4 v4.25.9 h1:JImNpf6gCVhKgZhtaAHJ0serfFGtlfIlSC08eaKdTrU= -github.com/shirou/gopsutil/v4 v4.25.9/go.mod h1:gxIxoC+7nQRwUl/xNhutXlD8lq+jxTgpIkEf3rADHL8= +github.com/shirou/gopsutil/v4 v4.25.10 h1:at8lk/5T1OgtuCp+AwrDofFRjnvosn0nkN2OLQ6g8tA= +github.com/shirou/gopsutil/v4 v4.25.10/go.mod h1:+kSwyC8DRUD9XXEHCAFjK+0nuArFJM0lva+StQAcskM= github.com/sigstore/fulcio v1.7.1 h1:RcoW20Nz49IGeZyu3y9QYhyyV3ZKQ85T+FXPKkvE+aQ= github.com/sigstore/fulcio v1.7.1/go.mod h1:7lYY+hsd8Dt+IvKQRC+KEhWpCZ/GlmNvwIa5JhypMS8= github.com/sigstore/protobuf-specs v0.4.1 h1:5SsMqZbdkcO/DNHudaxuCUEjj6x29tS2Xby1BxGU7Zc= diff --git a/vendor/github.com/shirou/gopsutil/v4/cpu/cpu_windows.go b/vendor/github.com/shirou/gopsutil/v4/cpu/cpu_windows.go index 18315a018fa..8af2a7fab9e 100644 --- a/vendor/github.com/shirou/gopsutil/v4/cpu/cpu_windows.go +++ b/vendor/github.com/shirou/gopsutil/v4/cpu/cpu_windows.go @@ -8,12 +8,14 @@ import ( "errors" "fmt" "math/bits" + "path/filepath" "strconv" + "strings" "syscall" "unsafe" - "github.com/yusufpapurcu/wmi" "golang.org/x/sys/windows" + "golang.org/x/sys/windows/registry" "github.com/shirou/gopsutil/v4/internal/common" ) @@ -75,6 +77,8 @@ const ( smbiosEndOfTable = 127 // Minimum length for processor structure smbiosTypeProcessor = 4 // SMBIOS Type 4: Processor Information smbiosProcessorMinLength = 0x18 // Minimum length for processor structure + + centralProcessorRegistryKey = `HARDWARE\DESCRIPTION\System\CentralProcessor` ) type relationship uint32 @@ -179,61 +183,27 @@ func getProcessorPowerInformation(ctx context.Context) ([]processorPowerInformat func InfoWithContext(ctx context.Context) ([]InfoStat, error) { var ret []InfoStat - var dst []win32_Processor - q := wmi.CreateQuery(&dst, "") - if err := common.WMIQueryWithContext(ctx, q, &dst); err != nil { - return ret, err - } - - var procID string - for i, l := range dst { - procID = "" - if l.ProcessorID != nil { - procID = *l.ProcessorID - } - - cpu := InfoStat{ - CPU: int32(i), - Family: strconv.FormatUint(uint64(l.Family), 10), - VendorID: l.Manufacturer, - ModelName: l.Name, - Cores: int32(l.NumberOfLogicalProcessors), // TO BE REMOVED, set by getSystemLogicalProcessorInformationEx - PhysicalID: procID, - Mhz: float64(l.MaxClockSpeed), - Flags: []string{}, - } - ret = append(ret, cpu) - } - processorPackages, err := getSystemLogicalProcessorInformationEx(relationProcessorPackage) if err != nil { - // return an error whem wmi will be removed - // return ret, fmt.Errorf("failed to get processor package information: %w", err) - return ret, nil - } - - if len(processorPackages) != len(ret) { - // this should never happen, but it's kept for safety until wmi is removed - return ret, nil + return ret, fmt.Errorf("failed to get processor package information: %w", err) } ppis, powerInformationErr := getProcessorPowerInformation(ctx) if powerInformationErr != nil { - // return an error whem wmi will be removed - // return ret, fmt.Errorf("failed to get processor power information: %w", err) - return ret, nil + return ret, fmt.Errorf("failed to get processor power information: %w", err) } family, processorId, smBIOSErr := getSMBIOSProcessorInfo() if smBIOSErr != nil { - // return an error whem wmi will be removed - // return ret, smBIOSErr - return ret, nil + return ret, smBIOSErr } for i, pkg := range processorPackages { logicalCount := 0 maxMhz := 0 + model := "" + vendorId := "" + // iterate over each set bit in the package affinity mask for _, ga := range pkg.processor.groupMask { g := int(ga.group) forEachSetBit64(uint64(ga.mask), func(bit int) { @@ -246,12 +216,26 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { maxMhz = m } } + + registryKeyPath := filepath.Join(centralProcessorRegistryKey, strconv.Itoa(globalLpl)) + key, err := registry.OpenKey(registry.LOCAL_MACHINE, registryKeyPath, registry.QUERY_VALUE|registry.READ) + if err == nil { + model = getRegistryStringValueIfUnset(key, "ProcessorNameString", model) + vendorId = getRegistryStringValueIfUnset(key, "VendorIdentifier", vendorId) + _ = key.Close() + } }) } - ret[i].Mhz = float64(maxMhz) - ret[i].Cores = int32(logicalCount) - ret[i].Family = strconv.FormatUint(uint64(family), 10) - ret[i].PhysicalID = processorId + ret = append(ret, InfoStat{ + CPU: int32(i), + Family: strconv.FormatUint(uint64(family), 10), + VendorID: vendorId, + ModelName: model, + Cores: int32(logicalCount), + PhysicalID: processorId, + Mhz: float64(maxMhz), + Flags: []string{}, + }) } return ret, nil @@ -461,6 +445,17 @@ func getPhysicalCoreCount() (int, error) { return len(infos), err } +func getRegistryStringValueIfUnset(key registry.Key, keyName, value string) string { + if value != "" { + return value + } + val, _, err := key.GetStringValue(keyName) + if err == nil { + return strings.TrimSpace(val) + } + return "" +} + func CountsWithContext(_ context.Context, logical bool) (int, error) { if logical { // Get logical processor count https://github.com/giampaolo/psutil/blob/d01a9eaa35a8aadf6c519839e987a49d8be2d891/psutil/_psutil_windows.c#L97 diff --git a/vendor/github.com/shirou/gopsutil/v4/internal/common/common.go b/vendor/github.com/shirou/gopsutil/v4/internal/common/common.go index 851b5dc730e..36eb1d211f6 100644 --- a/vendor/github.com/shirou/gopsutil/v4/internal/common/common.go +++ b/vendor/github.com/shirou/gopsutil/v4/internal/common/common.go @@ -442,7 +442,7 @@ func HostRootWithContext(ctx context.Context, combineWith ...string) string { } // getSysctrlEnv sets LC_ALL=C in a list of env vars for use when running -// sysctl commands (see DoSysctrl). +// sysctl commands. func getSysctrlEnv(env []string) []string { foundLC := false for i, line := range env { diff --git a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_darwin.go b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_darwin.go index c9d610540e9..8b756a11d46 100644 --- a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_darwin.go +++ b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_darwin.go @@ -4,32 +4,14 @@ package common import ( - "context" "errors" "fmt" - "os" - "os/exec" - "strings" "unsafe" "github.com/ebitengine/purego" "golang.org/x/sys/unix" ) -func DoSysctrlWithContext(ctx context.Context, mib string) ([]string, error) { - cmd := exec.CommandContext(ctx, "sysctl", "-n", mib) - cmd.Env = getSysctrlEnv(os.Environ()) - out, err := cmd.Output() - if err != nil { - return []string{}, err - } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) - - return values, nil -} - func CallSyscall(mib []int32) ([]byte, uint64, error) { miblen := uint64(len(mib)) diff --git a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_freebsd.go b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_freebsd.go index 53cdceeb6d4..7a40a40c2bb 100644 --- a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_freebsd.go +++ b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_freebsd.go @@ -5,9 +5,6 @@ package common import ( "fmt" - "os" - "os/exec" - "strings" "unsafe" "golang.org/x/sys/unix" @@ -28,20 +25,6 @@ func SysctlUint(mib string) (uint64, error) { return 0, fmt.Errorf("unexpected size: %s, %d", mib, len(buf)) } -func DoSysctrl(mib string) ([]string, error) { - cmd := exec.Command("sysctl", "-n", mib) - cmd.Env = getSysctrlEnv(os.Environ()) - out, err := cmd.Output() - if err != nil { - return []string{}, err - } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) - - return values, nil -} - func CallSyscall(mib []int32) ([]byte, uint64, error) { mibptr := unsafe.Pointer(&mib[0]) miblen := uint64(len(mib)) diff --git a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_linux.go b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_linux.go index 1ec223150bb..a2473f41dcf 100644 --- a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_linux.go +++ b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_linux.go @@ -7,7 +7,6 @@ import ( "context" "errors" "os" - "os/exec" "path/filepath" "strconv" "strings" @@ -20,20 +19,6 @@ import ( // cachedBootTime must be accessed via atomic.Load/StoreUint64 var cachedBootTime uint64 -func DoSysctrl(mib string) ([]string, error) { - cmd := exec.Command("sysctl", "-n", mib) - cmd.Env = getSysctrlEnv(os.Environ()) - out, err := cmd.Output() - if err != nil { - return []string{}, err - } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) - - return values, nil -} - func NumProcs() (uint64, error) { return NumProcsWithContext(context.Background()) } diff --git a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_netbsd.go b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_netbsd.go index 206532126c9..52796ddbf50 100644 --- a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_netbsd.go +++ b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_netbsd.go @@ -4,28 +4,11 @@ package common import ( - "os" - "os/exec" - "strings" "unsafe" "golang.org/x/sys/unix" ) -func DoSysctrl(mib string) ([]string, error) { - cmd := exec.Command("sysctl", "-n", mib) - cmd.Env = getSysctrlEnv(os.Environ()) - out, err := cmd.Output() - if err != nil { - return []string{}, err - } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) - - return values, nil -} - func CallSyscall(mib []int32) ([]byte, uint64, error) { mibptr := unsafe.Pointer(&mib[0]) miblen := uint64(len(mib)) diff --git a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_openbsd.go b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_openbsd.go index 00fa19a2fb4..df44ac04288 100644 --- a/vendor/github.com/shirou/gopsutil/v4/internal/common/common_openbsd.go +++ b/vendor/github.com/shirou/gopsutil/v4/internal/common/common_openbsd.go @@ -4,28 +4,11 @@ package common import ( - "os" - "os/exec" - "strings" "unsafe" "golang.org/x/sys/unix" ) -func DoSysctrl(mib string) ([]string, error) { - cmd := exec.Command("sysctl", "-n", mib) - cmd.Env = getSysctrlEnv(os.Environ()) - out, err := cmd.Output() - if err != nil { - return []string{}, err - } - v := strings.Replace(string(out), "{ ", "", 1) - v = strings.Replace(string(v), " }", "", 1) - values := strings.Fields(string(v)) - - return values, nil -} - func CallSyscall(mib []int32) ([]byte, uint64, error) { mibptr := unsafe.Pointer(&mib[0]) miblen := uint64(len(mib)) diff --git a/vendor/github.com/shirou/gopsutil/v4/internal/common/warnings.go b/vendor/github.com/shirou/gopsutil/v4/internal/common/warnings.go index eb0b63144be..e09768f3cc7 100644 --- a/vendor/github.com/shirou/gopsutil/v4/internal/common/warnings.go +++ b/vendor/github.com/shirou/gopsutil/v4/internal/common/warnings.go @@ -1,7 +1,10 @@ // SPDX-License-Identifier: BSD-3-Clause package common -import "fmt" +import ( + "fmt" + "strings" +) const ( maxWarnings = 100 // An arbitrary limit to avoid excessive memory usage, it has no sense to store hundreds of errors @@ -33,9 +36,11 @@ func (w *Warnings) Reference() error { func (w *Warnings) Error() string { if w.Verbose { str := "" + var sb strings.Builder for i, e := range w.List { - str += fmt.Sprintf("\tError %d: %s\n", i, e.Error()) + sb.WriteString(fmt.Sprintf("\tError %d: %s\n", i, e.Error())) } + str += sb.String() if w.tooManyErrors { str += fmt.Sprintf("\t%s\n", tooManyErrorsMessage) } diff --git a/vendor/github.com/shirou/gopsutil/v4/net/net_linux.go b/vendor/github.com/shirou/gopsutil/v4/net/net_linux.go index f01b04b5038..d1e7f0ce773 100644 --- a/vendor/github.com/shirou/gopsutil/v4/net/net_linux.go +++ b/vendor/github.com/shirou/gopsutil/v4/net/net_linux.go @@ -50,26 +50,25 @@ func IOCountersByFileWithContext(_ context.Context, pernic bool, filename string return nil, err } - parts := make([]string, 2) - statlen := len(lines) - 1 ret := make([]IOCountersStat, 0, statlen) for _, line := range lines[2:] { + // Split interface name and stats data at the last ":" separatorPos := strings.LastIndex(line, ":") if separatorPos == -1 { continue } - parts[0] = line[0:separatorPos] - parts[1] = line[separatorPos+1:] + interfacePart := line[0:separatorPos] + statsPart := line[separatorPos+1:] - interfaceName := strings.TrimSpace(parts[0]) + interfaceName := strings.TrimSpace(interfacePart) if interfaceName == "" { continue } - fields := strings.Fields(strings.TrimSpace(parts[1])) + fields := strings.Fields(strings.TrimSpace(statsPart)) bytesRecv, err := strconv.ParseUint(fields[0], 10, 64) if err != nil { return ret, err @@ -610,7 +609,7 @@ func getProcInodesAllWithContext(ctx context.Context, root string, maxConn int) return ret, nil } -// decodeAddress decode addresse represents addr in proc/net/* +// decodeAddress decode address represents addr in proc/net/* // ex: // "0500000A:0016" -> "10.0.0.5", 22 // "0085002452100113070057A13F025401:0035" -> "2400:8500:1301:1052:a157:7:154:23f", 53 diff --git a/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go b/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go index 6fd57f3d847..d0bba150883 100644 --- a/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go +++ b/vendor/github.com/shirou/gopsutil/v4/process/process_darwin.go @@ -237,7 +237,7 @@ func (p *Process) getKProc() (*unix.KinfoProc, error) { // call ps command. // Return value deletes Header line(you must not input wrong arg). -// And splited by Space. Caller have responsibility to manage. +// And split by Space. Caller have responsibility to manage. // If passed arg pid is 0, get information from all process. func callPsWithContext(ctx context.Context, arg string, pid int32, threadOption, nameOption bool) ([][]string, error) { var cmd []string diff --git a/vendor/modules.txt b/vendor/modules.txt index da5218a2cd3..c571fa28784 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -605,8 +605,8 @@ github.com/secure-systems-lab/go-securesystemslib/encrypted # github.com/segmentio/ksuid v1.0.4 ## explicit; go 1.12 github.com/segmentio/ksuid -# github.com/shirou/gopsutil/v4 v4.25.9 -## explicit; go 1.23.0 +# github.com/shirou/gopsutil/v4 v4.25.10 +## explicit; go 1.24.0 github.com/shirou/gopsutil/v4/common github.com/shirou/gopsutil/v4/cpu github.com/shirou/gopsutil/v4/internal/common