Merge pull request #1797 from mmorel-35/golangci-lint-matrix

chore(golangci-lint): GOOS and GOARCH matrix
pull/1794/head
shirou 3 weeks ago committed by GitHub
commit edcde3adba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -12,12 +12,41 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- {os: macos-latest, GOOS: darwin, GOARCH: amd64}
- {os: macos-latest, GOOS: darwin, GOARCH: arm64}
- {os: ubuntu-latest, GOOS: dragonfly, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: 386}
- {os: ubuntu-latest, GOOS: freebsd, GOARCH: arm}
- {os: ubuntu-latest, GOOS: linux, GOARCH: 386}
- {os: ubuntu-latest, GOOS: linux, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: arm64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: arm}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips64le}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mips}
- {os: ubuntu-latest, GOOS: linux, GOARCH: mipsle}
- {os: ubuntu-latest, GOOS: linux, GOARCH: ppc64le}
- {os: ubuntu-latest, GOOS: linux, GOARCH: ppc64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: riscv64}
- {os: ubuntu-latest, GOOS: linux, GOARCH: s390x}
- {os: ubuntu-latest, GOOS: netbsd, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: openbsd, GOARCH: 386}
- {os: ubuntu-latest, GOOS: openbsd, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: plan9, GOARCH: amd64}
- {os: ubuntu-latest, GOOS: plan9, GOARCH: 386}
- {os: ubuntu-latest, GOOS: solaris, GOARCH: amd64}
- {os: windows-latest, GOOS: windows, GOARCH: amd64}
- {os: windows-latest, GOOS: windows, GOARCH: 386}
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ${{ matrix.os }}
env:
GOARCH: ${{ matrix.GOARCH }}
GOOS: ${{ matrix.GOOS }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

@ -11,9 +11,10 @@ import (
"strings"
"unsafe"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/internal/common"
)
var (
@ -135,7 +136,7 @@ func parseDmesgBoot(fileName string) (InfoStat, error) {
c.VendorID = matches[1]
t, err := strconv.ParseInt(matches[2], 10, 32)
if err != nil {
return c, fmt.Errorf("unable to parse DragonflyBSD CPU stepping information from %q: %v", line, err)
return c, fmt.Errorf("unable to parse DragonflyBSD CPU stepping information from %q: %w", line, err)
}
c.Stepping = int32(t)
} else if matches := featuresMatch.FindStringSubmatch(line); matches != nil {

@ -57,7 +57,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er
ncpu, err := unix.SysctlUint32("hw.ncpu")
if err != nil {
return
return //nolint:nakedret //FIXME
}
var i uint32

@ -9,9 +9,10 @@ import (
"runtime"
"unsafe"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/internal/common"
)
const (
@ -74,7 +75,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er
ncpu, err := unix.SysctlUint32("hw.ncpu")
if err != nil {
return
return //nolint:nakedret //FIXME
}
var i uint32

@ -9,6 +9,7 @@ import (
"runtime"
stats "github.com/lufia/plan9stats"
"github.com/shirou/gopsutil/v4/internal/common"
)

@ -42,7 +42,7 @@ var kstatSplit = regexp.MustCompile(`[:\s]+`)
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
kstatSysOut, err := invoke.CommandWithContext(ctx, "kstat", "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/")
if err != nil {
return nil, fmt.Errorf("cannot execute kstat: %s", err)
return nil, fmt.Errorf("cannot execute kstat: %w", err)
}
cpu := make(map[float64]float64)
idle := make(map[float64]float64)
@ -57,29 +57,29 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
}
cpuNumber, err := strconv.ParseFloat(fields[1], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse cpu number: %s", err)
return nil, fmt.Errorf("cannot parse cpu number: %w", err)
}
cpu[cpuNumber] = cpuNumber
switch fields[3] {
case "idle":
idle[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse idle: %s", err)
return nil, fmt.Errorf("cannot parse idle: %w", err)
}
case "user":
user[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse user: %s", err)
return nil, fmt.Errorf("cannot parse user: %w", err)
}
case "kernel":
kern[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse kernel: %s", err)
return nil, fmt.Errorf("cannot parse kernel: %w", err)
}
case "iowait":
iowt[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
if err != nil {
return nil, fmt.Errorf("cannot parse iowait: %s", err)
return nil, fmt.Errorf("cannot parse iowait: %w", err)
}
//not sure how this translates, don't report, add to kernel, something else?
/*case "swap":
@ -121,22 +121,22 @@ func Info() ([]InfoStat, error) {
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
psrInfoOut, err := invoke.CommandWithContext(ctx, "psrinfo", "-p", "-v")
if err != nil {
return nil, fmt.Errorf("cannot execute psrinfo: %s", err)
return nil, fmt.Errorf("cannot execute psrinfo: %w", err)
}
procs, err := parseProcessorInfo(string(psrInfoOut))
if err != nil {
return nil, fmt.Errorf("error parsing psrinfo output: %s", err)
return nil, fmt.Errorf("error parsing psrinfo output: %w", err)
}
isaInfoOut, err := invoke.CommandWithContext(ctx, "isainfo", "-b", "-v")
if err != nil {
return nil, fmt.Errorf("cannot execute isainfo: %s", err)
return nil, fmt.Errorf("cannot execute isainfo: %w", err)
}
flags, err := parseISAInfo(string(isaInfoOut))
if err != nil {
return nil, fmt.Errorf("error parsing isainfo output: %s", err)
return nil, fmt.Errorf("error parsing isainfo output: %w", err)
}
result := make([]InfoStat, 0, len(flags))
@ -160,7 +160,7 @@ func parseISAInfo(cmdOutput string) ([]string, error) {
}
flags := make([]string, len(words)-4)
for i, val := range words[4:] {
for i, val := range words[4:] { //nolint:gosimple //FIXME
flags[i] = val
}
sort.Strings(flags)
@ -194,7 +194,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
if physicalCPU[psrStepOffset] != "" {
stepParsed, err := strconv.ParseInt(physicalCPU[psrStepOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %s", physicalCPU[9], err)
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %w", physicalCPU[9], err)
}
step = int32(stepParsed)
}
@ -202,7 +202,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
if physicalCPU[psrClockOffset] != "" {
clockParsed, err := strconv.ParseInt(physicalCPU[psrClockOffset], 10, 64)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %s", physicalCPU[10], err)
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %w", physicalCPU[10], err)
}
clock = float64(clockParsed)
}
@ -214,7 +214,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
case physicalCPU[psrNumCoresOffset] != "":
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[1], err)
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[1], err)
}
for i := 0; i < int(numCores); i++ {
@ -235,12 +235,12 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
case physicalCPU[psrNumCoresHTOffset] != "":
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresHTOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[3], err)
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[3], err)
}
numHT, err = strconv.ParseInt(physicalCPU[psrNumHTOffset], 10, 32)
if err != nil {
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %s", physicalCPU[4], err)
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %w", physicalCPU[4], err)
}
for i := 0; i < int(numCores); i++ {

@ -8,8 +8,9 @@ import (
"context"
"encoding/binary"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/internal/common"
)
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {

@ -7,6 +7,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"math"
"os"
@ -16,8 +17,9 @@ import (
"strconv"
"strings"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/internal/common"
)
const (
@ -100,7 +102,7 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC
}
lines := strings.Split(strings.TrimSpace(string(kstatSysOut)), "\n")
if len(lines) == 0 {
return nil, fmt.Errorf("no disk class found")
return nil, errors.New("no disk class found")
}
dnamearr := make(map[string]string)
nreadarr := make(map[string]uint64)

@ -12,9 +12,10 @@ import (
"strings"
"unsafe"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/shirou/gopsutil/v4/process"
"golang.org/x/sys/unix"
)
const (

@ -7,6 +7,7 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"os"
"regexp"
@ -31,14 +32,13 @@ func HostIDWithContext(ctx context.Context) (string, error) {
line := sc.Text()
// If we're in the global zone, rely on the hostname.
if line == "global" {
hostname, err := os.Hostname()
if err == nil {
return hostname, nil
}
} else {
if line != "global" {
return strings.TrimSpace(line), nil
}
hostname, err := os.Hostname()
if err == nil {
return hostname, nil
}
}
}
}
@ -84,7 +84,7 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
}
func UptimeWithContext(ctx context.Context) (uint64, error) {
bootTime, err := BootTime()
bootTime, err := BootTime() //nolint:contextcheck //FIXME
if err != nil {
return 0, err
}
@ -139,7 +139,7 @@ func parseUnameOutput(ctx context.Context) (string, string, string, error) {
fields := strings.Fields(string(out))
if len(fields) < 3 {
return "", "", "", fmt.Errorf("malformed `uname` output")
return "", "", "", errors.New("malformed `uname` output")
}
return fields[0], fields[1], fields[2], nil

@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const validFreeBSD = `Device: 1kB-blocks Used:
@ -24,33 +25,31 @@ const invalid = `Device: 512-blocks Used:
`
func TestParseSwapctlOutput_FreeBSD(t *testing.T) {
assert := assert.New(t)
stats, err := parseSwapctlOutput(validFreeBSD)
assert.NoError(err)
require.NoError(t, err)
assert.Equal(*stats[0], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/gpt/swapfs",
UsedBytes: 1263616,
FreeBytes: 1072478208,
})
}, *stats[0])
assert.Equal(*stats[1], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/md0",
UsedBytes: 681984,
FreeBytes: 1073059840,
})
}, *stats[1])
}
func TestParseSwapctlOutput_OpenBSD(t *testing.T) {
assert := assert.New(t)
stats, err := parseSwapctlOutput(validOpenBSD)
assert.NoError(err)
require.NoError(t, err)
assert.Equal(*stats[0], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/wd0b",
UsedBytes: 1234 * 1024,
FreeBytes: 653791 * 1024,
})
}, *stats[0])
}
func TestParseSwapctlOutput_Invalid(t *testing.T) {

@ -151,17 +151,16 @@ const invalidFile = `INVALID Type Size Used Priority
`
func TestParseSwapsFile_ValidFile(t *testing.T) {
assert := assert.New(t)
stats, err := parseSwapsFile(context.Background(), strings.NewReader(validFile))
require.NoError(t, err)
assert.Equal(SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/dm-2",
UsedBytes: 502566912,
FreeBytes: 68128825344,
}, *stats[0])
assert.Equal(SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/swapfile",
UsedBytes: 1024,
FreeBytes: 1024,

@ -10,8 +10,9 @@ import (
"errors"
"fmt"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/internal/common"
)
func GetPageSize() (uint64, error) {

@ -8,6 +8,7 @@ import (
"os"
stats "github.com/lufia/plan9stats"
"github.com/shirou/gopsutil/v4/internal/common"
)

@ -11,8 +11,9 @@ import (
"strconv"
"strings"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/tklauser/go-sysconf"
"github.com/shirou/gopsutil/v4/internal/common"
)
// VirtualMemory for Solaris is a minimal implementation which only returns
@ -24,17 +25,17 @@ func VirtualMemory() (*VirtualMemoryStat, error) {
func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
result := &VirtualMemoryStat{}
zoneName, err := zoneName()
zoneName, err := zoneName() //nolint:contextcheck //FIXME
if err != nil {
return nil, err
}
if zoneName == "global" {
cap, err := globalZoneMemoryCapacity()
capacity, err := globalZoneMemoryCapacity() //nolint:contextcheck //FIXME
if err != nil {
return nil, err
}
result.Total = cap
result.Total = capacity
freemem, err := globalZoneFreeMemory(ctx)
if err != nil {
return nil, err
@ -43,11 +44,11 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
result.Free = freemem
result.Used = result.Total - result.Free
} else {
cap, err := nonGlobalZoneMemoryCapacity()
capacity, err := nonGlobalZoneMemoryCapacity() //nolint:contextcheck //FIXME
if err != nil {
return nil, err
}
result.Total = cap
result.Total = capacity
}
return result, nil

@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const validFile = `swapfile dev swaplo blocks free
@ -18,21 +19,20 @@ const invalidFile = `swapfile dev swaplo INVALID free
/dev/dsk/c0t0d0s1 136,1 16 1638608 1600528`
func TestParseSwapsCommandOutput_Valid(t *testing.T) {
assert := assert.New(t)
stats, err := parseSwapsCommandOutput(validFile)
assert.NoError(err)
require.NoError(t, err)
assert.Equal(*stats[0], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/zvol/dsk/rpool/swap",
UsedBytes: 0,
FreeBytes: 1058800 * 512,
})
}, *stats[0])
assert.Equal(*stats[1], SwapDevice{
assert.Equal(t, SwapDevice{
Name: "/dev/dsk/c0t0d0s1",
UsedBytes: 38080 * 512,
FreeBytes: 1600528 * 512,
})
}, *stats[1])
}
func TestParseSwapsCommandOutput_Invalid(t *testing.T) {

@ -255,7 +255,7 @@ func InterfacesWithContext(ctx context.Context) (InterfaceStatList, error) {
return ret, nil
}
func getIOCountersAll(n []IOCountersStat) ([]IOCountersStat, error) {
func getIOCountersAll(n []IOCountersStat) []IOCountersStat {
r := IOCountersStat{
Name: "all",
}
@ -270,7 +270,7 @@ func getIOCountersAll(n []IOCountersStat) ([]IOCountersStat, error) {
r.Dropout += nic.Dropout
}
return []IOCountersStat{r}, nil
return []IOCountersStat{r}
}
// NetIOCounters returns network I/O statistics for every network

@ -249,7 +249,7 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
}
if !pernic {
return getIOCountersAll(ret)
return getIOCountersAll(ret), nil
}
return ret, nil
}

@ -85,7 +85,7 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
}
if !pernic {
return getIOCountersAll(ret)
return getIOCountersAll(ret), nil
}
return ret, nil

@ -128,7 +128,7 @@ func IOCountersByFileWithContext(ctx context.Context, pernic bool, filename stri
}
if !pernic {
return getIOCountersAll(ret)
return getIOCountersAll(ret), nil
}
return ret, nil

@ -138,8 +138,6 @@ type AddrTest struct {
}
func TestDecodeAddress(t *testing.T) {
assert := assert.New(t)
addr := map[string]AddrTest{
"11111:0035": {
Error: true,
@ -182,11 +180,11 @@ func TestDecodeAddress(t *testing.T) {
}
addr, err := decodeAddress(uint32(family), src)
if dst.Error {
assert.Error(err, src)
assert.Error(t, err, src)
} else {
require.NoError(t, err, src)
assert.Equal(dst.IP, addr.IP, src)
assert.Equal(dst.Port, int(addr.Port), src)
assert.Equal(t, dst.IP, addr.IP, src)
assert.Equal(t, dst.Port, int(addr.Port), src)
}
}
}

@ -150,15 +150,15 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
ret = append(ret, ioc)
}
if pernic == false {
return getIOCountersAll(ret)
if !pernic {
return getIOCountersAll(ret), nil
}
return ret, nil
}
func IOCountersByFileWithContext(ctx context.Context, pernic bool, filename string) ([]IOCountersStat, error) {
return IOCounters(pernic)
return IOCounters(pernic) //nolint:contextcheck //FIXME
}
func FilterCountersWithContext(ctx context.Context) ([]FilterStat, error) {

@ -5,6 +5,7 @@ package net
import (
"context"
"errors"
"fmt"
"regexp"
"runtime"
@ -29,7 +30,7 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
lines := strings.Split(strings.TrimSpace(string(kstatSysOut)), "\n")
if len(lines) == 0 {
return nil, fmt.Errorf("no interface found")
return nil, errors.New("no interface found")
}
rbytes64arr := make(map[string]uint64)
ipackets64arr := make(map[string]uint64)
@ -104,7 +105,7 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
}
if !pernic {
return getIOCountersAll(ret)
return getIOCountersAll(ret), nil
}
return ret, nil

@ -133,11 +133,7 @@ func TestGetNetIOCountersAll(t *testing.T) {
Errin: 10,
},
}
ret, err := getIOCountersAll(n)
skipIfNotImplementedErr(t, err)
if err != nil {
t.Error(err)
}
ret := getIOCountersAll(n)
if len(ret) != 1 {
t.Errorf("invalid return count")
}

@ -193,7 +193,7 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat,
}
if !pernic {
return getIOCountersAll(counters)
return getIOCountersAll(counters), nil
}
return counters, nil
}

@ -8,7 +8,6 @@ import (
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"path/filepath"
"sort"
@ -16,11 +15,12 @@ import (
"strings"
"unsafe"
cpu "github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/internal/common"
mem "github.com/shirou/gopsutil/v4/mem"
net "github.com/shirou/gopsutil/v4/net"
"golang.org/x/sys/unix"
"github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/internal/common"
"github.com/shirou/gopsutil/v4/mem"
"github.com/shirou/gopsutil/v4/net"
)
func pidsWithContext(ctx context.Context) ([]int32, error) {
@ -130,7 +130,7 @@ func readPtr(r io.Reader) (uintptr, error) {
}
return uintptr(p), nil
default:
return 0, fmt.Errorf("unsupported pointer size")
return 0, errors.New("unsupported pointer size")
}
}

@ -247,10 +247,7 @@ func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error
return "", err
}
ret := strings.FieldsFunc(string(cmdline), func(r rune) bool {
if r == '\u0000' {
return true
}
return false
return r == '\u0000'
})
return strings.Join(ret, " "), nil

@ -8,8 +8,9 @@ import (
"syscall"
"unsafe"
"github.com/shirou/gopsutil/v4/internal/common"
"golang.org/x/sys/windows"
"github.com/shirou/gopsutil/v4/internal/common"
)
type PROCESS_MEMORY_COUNTERS struct {
@ -39,30 +40,27 @@ func queryPebAddress(procHandle syscall.Handle, is32BitProcess bool) (uint64, er
)
if status := windows.NTStatus(ret); status == windows.STATUS_SUCCESS {
return uint64(info.PebBaseAddress), nil
} else {
return 0, windows.NTStatus(ret)
}
} else {
// we are on a 32-bit process reading an external 64-bit process
if common.ProcNtWow64QueryInformationProcess64.Find() == nil { // avoid panic
var info processBasicInformation64
return 0, windows.NTStatus(ret)
}
// we are on a 32-bit process reading an external 64-bit process
if common.ProcNtWow64QueryInformationProcess64.Find() != nil {
return 0, errors.New("can't find API to query 64 bit process from 32 bit")
}
// avoid panic
var info processBasicInformation64
ret, _, _ := common.ProcNtWow64QueryInformationProcess64.Call(
uintptr(procHandle),
uintptr(common.ProcessBasicInformation),
uintptr(unsafe.Pointer(&info)),
uintptr(unsafe.Sizeof(info)),
uintptr(0),
)
if status := windows.NTStatus(ret); status == windows.STATUS_SUCCESS {
return info.PebBaseAddress, nil
} else {
return 0, windows.NTStatus(ret)
}
} else {
return 0, errors.New("can't find API to query 64 bit process from 32 bit")
}
ret, _, _ := common.ProcNtWow64QueryInformationProcess64.Call(
uintptr(procHandle),
uintptr(common.ProcessBasicInformation),
uintptr(unsafe.Pointer(&info)),
uintptr(unsafe.Sizeof(info)),
uintptr(0),
)
if status := windows.NTStatus(ret); status == windows.STATUS_SUCCESS {
return info.PebBaseAddress, nil
}
return 0, windows.NTStatus(ret)
}
func readProcessMemory(h syscall.Handle, is32BitProcess bool, address uint64, size uint) []byte {

@ -5,7 +5,7 @@ package sensors
import (
"context"
"fmt"
"errors"
"unsafe"
"github.com/shirou/gopsutil/v4/internal/common"
@ -129,7 +129,7 @@ func readSMC(smc *common.SMC, key string) (*smcReturn, error) {
resultSmc.kSMC = result.result
if err != nil || result.result != common.KSMCSuccess {
return resultSmc, fmt.Errorf("ERROR: IOConnectCallStructMethod failed")
return resultSmc, errors.New("ERROR: IOConnectCallStructMethod failed")
}
resultSmc.dataSize = uint32(result.keyInfo.dataSize)
@ -158,7 +158,7 @@ func callSMC(smc *common.SMC, input *smcParamStruct) (*smcParamStruct, error) {
uintptr(unsafe.Pointer(input)), inputCnt, uintptr(unsafe.Pointer(output)), &outputCnt)
if result != 0 {
return output, fmt.Errorf("ERROR: IOConnectCallStructMethod failed")
return output, errors.New("ERROR: IOConnectCallStructMethod failed")
}
return output, nil
@ -169,7 +169,7 @@ func toUint32(key string) uint32 {
return 0
}
var ans uint32 = 0
var ans uint32
var shift uint32 = 24
for i := 0; i < smcKeySize; i++ {

@ -6,6 +6,7 @@ package sensors
import (
"context"
"encoding/csv"
"errors"
"io"
"strconv"
"strings"
@ -24,7 +25,7 @@ func TemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
r.FieldsPerRecord = -1
for {
record, err := r.Read()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {

Loading…
Cancel
Save