From 2684012ab2a4a1469958bcd26e23a1cfc759d395 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 27 Aug 2023 22:48:51 +0800 Subject: [PATCH 01/66] Initial support for NetBSD. Currently the changes are all copied from shirou/gopsutil#1364 --- cpu/cpu_netbsd.go | 127 ++++++++++++++++++++++++++++++++++++++++ cpu/cpu_netbsd_arm64.go | 10 ++++ 2 files changed, 137 insertions(+) create mode 100644 cpu/cpu_netbsd.go create mode 100644 cpu/cpu_netbsd_arm64.go diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go new file mode 100644 index 000000000..a728f67a6 --- /dev/null +++ b/cpu/cpu_netbsd.go @@ -0,0 +1,127 @@ +//go:build openbsd +// +build openbsd + +package cpu + +import ( + "context" + "fmt" + "runtime" + "unsafe" + + "github.com/shirou/gopsutil/v3/internal/common" + "github.com/tklauser/go-sysconf" + "golang.org/x/sys/unix" +) + +type cpuTimes struct { + User uint64 + Nice uint64 + Sys uint64 + Intr uint64 + Idle uint64 +} + +const ( + // sys/sysctl.h + ctlKern = 1 // "high kernel": proc, limits + ctlHw = 6 // CTL_HW + kernCpTime = 51 // KERN_CPTIME +) + +var ClocksPerSec = float64(100) + +func init() { + clkTck, err := sysconf.Sysconf(sysconf.SC_CLK_TCK) + // ignore errors + if err == nil { + ClocksPerSec = float64(clkTck) + } +} + +func Times(percpu bool) ([]TimesStat, error) { + return TimesWithContext(context.Background(), percpu) +} + +func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err error) { + if !percpu { + mib := []int32{ctlKern, kernCpTime} + buf, _, err := common.CallSyscall(mib) + if err != nil { + return ret, err + } + times := (*cpuTimes)(unsafe.Pointer(&buf[0])) + stat := TimesStat{ + CPU: "cpu-total", + User: float64(times.User), + Nice: float64(times.Nice), + System: float64(times.Sys), + Idle: float64(times.Idle), + Irq: float64(times.Intr), + } + return []TimesStat{stat}, nil + } + + ncpu, err := unix.SysctlUint32("hw.ncpu") + if err != nil { + return + } + + var i uint32 + for i = 0; i < ncpu; i++ { + mib := []int32{ctlKern, kernCpTime, int32(i)} + buf, _, err := common.CallSyscall(mib) + if err != nil { + return ret, err + } + + stats := (*cpuTimes)(unsafe.Pointer(&buf[0])) + ret = append(ret, TimesStat{ + CPU: fmt.Sprintf("cpu%d", i), + User: float64(stats.User), + Nice: float64(stats.Nice), + System: float64(stats.Sys), + Idle: float64(stats.Idle), + Irq: float64(stats.Intr), + }) + } + + return ret, nil +} + +// Returns only one (minimal) CPUInfoStat on OpenBSD +func Info() ([]InfoStat, error) { + return InfoWithContext(context.Background()) +} + +func InfoWithContext(ctx context.Context) ([]InfoStat, error) { + var ret []InfoStat + var err error + + c := InfoStat{} + + mhz, err := unix.Sysctl("machdep.dmi.processor-frequency") + if err != nil { + return nil, err + } + _, err = fmt.Sscanf(mhz, "%f", &c.Mhz) + if err != nil { + return nil, err + } + + ncpu, err := unix.SysctlUint32("hw.ncpuonline") + if err != nil { + return nil, err + } + c.Cores = int32(ncpu) + + if c.ModelName, err = unix.Sysctl("machdep.dmi.processor-version"); err != nil { + return nil, err + } + + return append(ret, c), nil +} + +func CountsWithContext(ctx context.Context, logical bool) (int, error) { + return runtime.NumCPU(), nil +} diff --git a/cpu/cpu_netbsd_arm64.go b/cpu/cpu_netbsd_arm64.go new file mode 100644 index 000000000..d659058cd --- /dev/null +++ b/cpu/cpu_netbsd_arm64.go @@ -0,0 +1,10 @@ +package cpu + +type cpuTimes struct { + User uint64 + Nice uint64 + Sys uint64 + Spin uint64 + Intr uint64 + Idle uint64 +} From 7f4efa53585d34fa0938f1cbb0025120ea4183b8 Mon Sep 17 00:00:00 2001 From: Kevin Conaway Date: Thu, 31 Aug 2023 13:19:58 -0400 Subject: [PATCH 02/66] Add support for reading AnonHugePages from /proc/meminfo This commit adds support for reading the `AnonHugePages` field from `/proc/meminfo`. The values in this field allow monitoring the [THP](https://www.kernel.org/doc/Documentation/vm/transhuge.txt) usage by systems that use this type of memory --- mem/mem.go | 2 ++ mem/mem_linux.go | 6 ++++++ mem/mem_linux_test.go | 10 ++++++++++ mem/mem_test.go | 2 +- .../linux/virtualmemory/anonhugepages/proc/meminfo | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 mem/testdata/linux/virtualmemory/anonhugepages/proc/meminfo diff --git a/mem/mem.go b/mem/mem.go index ff960dacc..edaf268bb 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -50,6 +50,7 @@ type VirtualMemoryStat struct { // https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s2-proc-meminfo.html // https://www.kernel.org/doc/Documentation/filesystems/proc.txt // https://www.kernel.org/doc/Documentation/vm/overcommit-accounting + // https://www.kernel.org/doc/Documentation/vm/transhuge.txt Buffers uint64 `json:"buffers"` Cached uint64 `json:"cached"` WriteBack uint64 `json:"writeBack"` @@ -78,6 +79,7 @@ type VirtualMemoryStat struct { HugePagesRsvd uint64 `json:"hugePagesRsvd"` HugePagesSurp uint64 `json:"hugePagesSurp"` HugePageSize uint64 `json:"hugePageSize"` + AnonHugePages uint64 `json:"anonHugePages"` } type SwapMemoryStat struct { diff --git a/mem/mem_linux.go b/mem/mem_linux.go index 935331728..214a91e47 100644 --- a/mem/mem_linux.go +++ b/mem/mem_linux.go @@ -311,6 +311,12 @@ func fillFromMeminfoWithContext(ctx context.Context) (*VirtualMemoryStat, *Virtu return ret, retEx, err } ret.HugePageSize = t * 1024 + case "AnonHugePages": + t, err := strconv.ParseUint(value, 10, 64) + if err != nil { + return ret, retEx, err + } + ret.AnonHugePages = t * 1024 } } diff --git a/mem/mem_linux_test.go b/mem/mem_linux_test.go index d830fbf9c..6b6fb782a 100644 --- a/mem/mem_linux_test.go +++ b/mem/mem_linux_test.go @@ -108,6 +108,16 @@ var virtualMemoryTests = []struct { HugePageSize: 0, }, }, + { + "anonhugepages", &VirtualMemoryStat{ + Total: 260799420 * 1024, + Available: 127880216 * 1024, + Free: 119443248 * 1024, + AnonHugePages: 50409472 * 1024, + Used: 144748720128, + UsedPercent: 54.20110673559013, + }, + }, } func TestVirtualMemoryLinux(t *testing.T) { diff --git a/mem/mem_test.go b/mem/mem_test.go index 3be56562f..79ddb0fc6 100644 --- a/mem/mem_test.go +++ b/mem/mem_test.go @@ -89,7 +89,7 @@ func TestVirtualMemoryStat_String(t *testing.T) { Free: 40, } t.Log(v) - e := `{"total":10,"available":20,"used":30,"usedPercent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"laundry":0,"buffers":0,"cached":0,"writeBack":0,"dirty":0,"writeBackTmp":0,"shared":0,"slab":0,"sreclaimable":0,"sunreclaim":0,"pageTables":0,"swapCached":0,"commitLimit":0,"committedAS":0,"highTotal":0,"highFree":0,"lowTotal":0,"lowFree":0,"swapTotal":0,"swapFree":0,"mapped":0,"vmallocTotal":0,"vmallocUsed":0,"vmallocChunk":0,"hugePagesTotal":0,"hugePagesFree":0,"hugePagesRsvd":0,"hugePagesSurp":0,"hugePageSize":0}` + e := `{"total":10,"available":20,"used":30,"usedPercent":30.1,"free":40,"active":0,"inactive":0,"wired":0,"laundry":0,"buffers":0,"cached":0,"writeBack":0,"dirty":0,"writeBackTmp":0,"shared":0,"slab":0,"sreclaimable":0,"sunreclaim":0,"pageTables":0,"swapCached":0,"commitLimit":0,"committedAS":0,"highTotal":0,"highFree":0,"lowTotal":0,"lowFree":0,"swapTotal":0,"swapFree":0,"mapped":0,"vmallocTotal":0,"vmallocUsed":0,"vmallocChunk":0,"hugePagesTotal":0,"hugePagesFree":0,"hugePagesRsvd":0,"hugePagesSurp":0,"hugePageSize":0,"anonHugePages":0}` if e != fmt.Sprintf("%v", v) { t.Errorf("VirtualMemoryStat string is invalid: %v", v) } diff --git a/mem/testdata/linux/virtualmemory/anonhugepages/proc/meminfo b/mem/testdata/linux/virtualmemory/anonhugepages/proc/meminfo new file mode 100644 index 000000000..d158c677b --- /dev/null +++ b/mem/testdata/linux/virtualmemory/anonhugepages/proc/meminfo @@ -0,0 +1,4 @@ +MemTotal: 260799420 kB +MemFree: 119443248 kB +MemAvailable: 127880216 kB +AnonHugePages: 50409472 kB \ No newline at end of file From 4e662561c23819a33267e85a64940ed9c3e3b47e Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 2 Sep 2023 22:57:30 +0800 Subject: [PATCH 03/66] mem: Add support for NetBSD --- mem/mem_netbsd.go | 87 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 mem/mem_netbsd.go diff --git a/mem/mem_netbsd.go b/mem/mem_netbsd.go new file mode 100644 index 000000000..fb6fafecf --- /dev/null +++ b/mem/mem_netbsd.go @@ -0,0 +1,87 @@ +//go:build netbsd +// +build netbsd + +package mem + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + + "github.com/shirou/gopsutil/v3/internal/common" + "golang.org/x/sys/unix" +) + +func GetPageSize() (uint64, error) { + return GetPageSizeWithContext(context.Background()) +} + +func GetPageSizeWithContext(ctx context.Context) (uint64, error) { + uvmexp, err := unix.SysctlUvmexp("vm.uvmexp2") + if err != nil { + return 0, err + } + return uint64(uvmexp.Pagesize), nil +} + +func VirtualMemory() (*VirtualMemoryStat, error) { + return VirtualMemoryWithContext(context.Background()) +} + +func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { + uvmexp, err := unix.SysctlUvmexp("vm.uvmexp2") + if err != nil { + return nil, err + } + p := uint64(uvmexp.Pagesize) + + ret := &VirtualMemoryStat{ + Total: uint64(uvmexp.Npages) * p, + Free: uint64(uvmexp.Free) * p, + Active: uint64(uvmexp.Active) * p, + Inactive: uint64(uvmexp.Inactive) * p, + Cached: 0, // not available + Wired: uint64(uvmexp.Wired) * p, + } + + ret.Available = ret.Inactive + ret.Cached + ret.Free + ret.Used = ret.Total - ret.Available + ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 + + // Get buffers from vm.bufmem sysctl + ret.Buffers = unix.SysctlUint64("vm.bufmem") + + return ret, nil +} + +// Return swapctl summary info +func SwapMemory() (*SwapMemoryStat, error) { + return SwapMemoryWithContext(context.Background()) +} + +func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) { + out, err := invoke.CommandWithContext(ctx, "swapctl", "-sk") + if err != nil { + return &SwapMemoryStat{}, nil + } + + line := string(out) + var total, used, free uint64 + + _, err = fmt.Sscanf(line, + "total: %d 1K-blocks allocated, %d used, %d available", + &total, &used, &free) + if err != nil { + return nil, errors.New("failed to parse swapctl output") + } + + percent := float64(used) / float64(total) * 100 + return &SwapMemoryStat{ + Total: total * 1024, + Used: used * 1024, + Free: free * 1024, + UsedPercent: percent, + }, nil +} From 6a4ec32f3b549c7d2ead06b627b035dea1268968 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 2 Sep 2023 23:01:23 +0800 Subject: [PATCH 04/66] cpu: remove wrong info copied from openbsd --- cpu/cpu_netbsd.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go index a728f67a6..facc4237a 100644 --- a/cpu/cpu_netbsd.go +++ b/cpu/cpu_netbsd.go @@ -1,5 +1,5 @@ -//go:build openbsd -// +build openbsd +//go:build netbsd +// +build netbsd package cpu @@ -89,7 +89,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er return ret, nil } -// Returns only one (minimal) CPUInfoStat on OpenBSD +// Returns only one (minimal) CPUInfoStat on NetBSD func Info() ([]InfoStat, error) { return InfoWithContext(context.Background()) } From 302751d509e23cd4c8bdca1de9c58e407af6b11f Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 3 Sep 2023 23:08:54 +0800 Subject: [PATCH 05/66] disk: start porting to NetBSD, far from complete --- disk/disk_netbsd.go | 130 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 disk/disk_netbsd.go diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go new file mode 100644 index 000000000..6f1ba3ff5 --- /dev/null +++ b/disk/disk_netbsd.go @@ -0,0 +1,130 @@ +//go:build openbsd +// +build openbsd + +package disk + +import ( + "bytes" + "context" + "encoding/binary" + + "github.com/shirou/gopsutil/v3/internal/common" + "golang.org/x/sys/unix" +) + +func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { + var ret []PartitionStat + + // get required buffer size + r, _, err = unix.Syscall6( + 483, // SYS___getvfsstat90 syscall + nil, + 0, + 1, // ST_WAIT/MNT_WAIT, see sys/fstypes.h + ) + if err != nil { + return ret, err + } + mountedFsCount := uint64(r) + + d := PartitionStat{ + Device: common.ByteToString(stat.F_mntfromname[:]), + Mountpoint: common.ByteToString(stat.F_mntonname[:]), + Fstype: common.ByteToString(stat.F_fstypename[:]), + Opts: opts, + } + + ret = append(ret, d) + } + + return ret, nil +} + +func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { + ret := make(map[string]IOCountersStat) + + r, err := unix.SysctlRaw("hw.diskstats") + if err != nil { + return nil, err + } + buf := []byte(r) + length := len(buf) + + count := int(uint64(length) / uint64(sizeOfDiskstats)) + + // parse buf to Diskstats + for i := 0; i < count; i++ { + b := buf[i*sizeOfDiskstats : i*sizeOfDiskstats+sizeOfDiskstats] + d, err := parseDiskstats(b) + if err != nil { + continue + } + name := common.IntToString(d.Name[:]) + + if len(names) > 0 && !common.StringsHas(names, name) { + continue + } + + ds := IOCountersStat{ + ReadCount: d.Rxfer, + WriteCount: d.Wxfer, + ReadBytes: d.Rbytes, + WriteBytes: d.Wbytes, + Name: name, + } + ret[name] = ds + } + + return ret, nil +} + +// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE) + +func parseDiskstats(buf []byte) (Diskstats, error) { + var ds Diskstats + br := bytes.NewReader(buf) + // err := binary.Read(br, binary.LittleEndian, &ds) + err := common.Read(br, binary.LittleEndian, &ds) + if err != nil { + return ds, err + } + + return ds, nil +} + +func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { + stat := unix.Statfs_t{} + err := unix.Statfs(path, &stat) + if err != nil { + return nil, err + } + bsize := stat.F_bsize + + ret := &UsageStat{ + Path: path, + Fstype: getFsType(stat), + Total: (uint64(stat.F_blocks) * uint64(bsize)), + Free: (uint64(stat.F_bavail) * uint64(bsize)), + InodesTotal: (uint64(stat.F_files)), + InodesFree: (uint64(stat.F_ffree)), + } + + ret.InodesUsed = (ret.InodesTotal - ret.InodesFree) + ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 + ret.Used = (uint64(stat.F_blocks) - uint64(stat.F_bfree)) * uint64(bsize) + ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 + + return ret, nil +} + +func getFsType(stat unix.Statfs_t) string { + return common.ByteToString(stat.F_fstypename[:]) +} + +func SerialNumberWithContext(ctx context.Context, name string) (string, error) { + return "", common.ErrNotImplementedError +} + +func LabelWithContext(ctx context.Context, name string) (string, error) { + return "", common.ErrNotImplementedError +} From 85d37b91b38a03e13d02fca11f7ab3cdf47345a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 01:53:34 +0000 Subject: [PATCH 06/66] chore(deps): bump golang.org/x/sys from 0.11.0 to 0.12.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.11.0 to 0.12.0. - [Commits](https://github.com/golang/sys/compare/v0.11.0...v0.12.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 8fc781e97..78cc4af5f 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tklauser/go-sysconf v0.3.12 github.com/yusufpapurcu/wmi v1.2.3 - golang.org/x/sys v0.11.0 + golang.org/x/sys v0.12.0 ) retract v3.22.11 diff --git a/go.sum b/go.sum index 914427d7b..e558c9ce6 100644 --- a/go.sum +++ b/go.sum @@ -32,8 +32,9 @@ github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From eadf3f7a33b5d05e95ee2049c60ee848a982ecc8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 01:50:24 +0000 Subject: [PATCH 07/66] chore(deps): bump actions/checkout from 3.6.0 to 4.0.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.0.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/f43a0e5ff2bd294095638e18286ca9a3d1956744...3df4ab11eba7bda6032a0b82a6bb43b11571feac) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build_test.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/sbom_generator.yml | 2 +- .github/workflows/shellcheck.yml | 2 +- .github/workflows/test.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index ce255f926..5aa2677bb 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -26,7 +26,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 - id: cache-paths run: | echo "::set-output name=cache::$(go env GOCACHE)" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5a9ebcadf..91feb3940 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -20,7 +20,7 @@ jobs: with: go-version: 1.17 - name: Checkout repository - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 - name: Setup golangci-lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index efd3baea3..6bdd103ac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,6 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 - name: Release run: make release diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index 97565c191..3bd0a5d8a 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 - uses: advanced-security/sbom-generator-action@375dee8e6144d9fd0ec1f5667b4f6fb4faacefed # v0.0.1 id: sbom diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index b700ca8bd..2c2198f12 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -8,6 +8,6 @@ jobs: name: Shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 - name: Run ShellCheck uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dacda8bff..6055a1bd2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 - id: go-env run: | echo "::set-output name=cache::$(go env GOCACHE)" From 2d2033ed7dede52f74ffd228845d8fd06d439d4d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Sep 2023 01:12:39 +0000 Subject: [PATCH 08/66] chore(deps): bump actions/upload-artifact from 3.1.2 to 3.1.3 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.2 to 3.1.3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/0b7f8abb1508181956e8e162db84b466c27e18ce...a8a3f3ad30e3422c9c7b888a15615d19a852ae32) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/sbom_generator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index 97565c191..f2db27d2b 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -19,7 +19,7 @@ jobs: id: sbom env: GITHUB_TOKEN: ${{ github.token }} - - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 + - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 with: path: ${{steps.sbom.outputs.fileName }} name: "SBOM" From 1d4b8c3989e0da46526c4e05fbf74456098f1c15 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Sep 2023 01:37:26 +0000 Subject: [PATCH 09/66] chore(deps): bump actions/cache from 3.3.1 to 3.3.2 Bumps [actions/cache](https://github.com/actions/cache) from 3.3.1 to 3.3.2. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8...704facf57e6136b1bc63b828d79edcd491f0ee84) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/build_test.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index ce255f926..10a39597e 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -32,7 +32,7 @@ jobs: echo "::set-output name=cache::$(go env GOCACHE)" echo "::set-output name=mod-cache::$(go env GOMODCACHE)" - name: Cache go modules - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 with: path: | ${{ steps.cache-paths.outputs.cache }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dacda8bff..67f208132 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: echo "::set-output name=cache::$(go env GOCACHE)" echo "::set-output name=mod-cache::$(go env GOMODCACHE)" - name: Cache go modules - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 + uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 with: path: | ${{ steps.go-env.outputs.cache }} From 0665cafa1b8eb4b284231dd2b488f80227d99279 Mon Sep 17 00:00:00 2001 From: shirou Date: Fri, 8 Sep 2023 17:05:14 +0000 Subject: [PATCH 10/66] chore: replace deprecated ioutil package to os and io --- cpu/cpu_solaris_test.go | 6 +++--- disk/disk_linux.go | 9 ++++----- host/host_darwin.go | 4 ++-- host/host_freebsd.go | 6 +++--- host/host_linux.go | 16 ++++++++-------- host/host_openbsd.go | 4 ++-- host/host_solaris.go | 2 +- internal/common/common.go | 5 ++--- load/load_linux.go | 6 +++--- net/net_linux.go | 7 +++---- process/process_linux.go | 21 ++++++++++----------- process/process_linux_test.go | 2 +- process/process_solaris.go | 7 +++---- process/process_test.go | 3 ++- 14 files changed, 47 insertions(+), 51 deletions(-) diff --git a/cpu/cpu_solaris_test.go b/cpu/cpu_solaris_test.go index 508aad5e6..dd9362c3a 100644 --- a/cpu/cpu_solaris_test.go +++ b/cpu/cpu_solaris_test.go @@ -1,7 +1,7 @@ package cpu import ( - "io/ioutil" + "os" "path/filepath" "reflect" "sort" @@ -49,7 +49,7 @@ func TestParseISAInfo(t *testing.T) { } for _, tc := range cases { - content, err := ioutil.ReadFile(filepath.Join("testdata", "solaris", tc.filename)) + content, err := os.ReadFile(filepath.Join("testdata", "solaris", tc.filename)) if err != nil { t.Errorf("cannot read test case: %s", err) } @@ -138,7 +138,7 @@ func TestParseProcessorInfo(t *testing.T) { } for _, tc := range cases { - content, err := ioutil.ReadFile(filepath.Join("testdata", "solaris", tc.filename)) + content, err := os.ReadFile(filepath.Join("testdata", "solaris", tc.filename)) if err != nil { t.Errorf("cannot read test case: %s", err) } diff --git a/disk/disk_linux.go b/disk/disk_linux.go index 5015c34ae..c06516c6c 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -9,7 +9,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -497,7 +496,7 @@ func SerialNumberWithContext(ctx context.Context, name string) (string, error) { // Try to get the serial from udev data udevDataPath := common.HostRunWithContext(ctx, fmt.Sprintf("udev/data/b%d:%d", major, minor)) - if udevdata, err := ioutil.ReadFile(udevDataPath); err == nil { + if udevdata, err := os.ReadFile(udevDataPath); err == nil { scanner := bufio.NewScanner(bytes.NewReader(udevdata)) for scanner.Scan() { values := strings.Split(scanner.Text(), "=") @@ -510,8 +509,8 @@ func SerialNumberWithContext(ctx context.Context, name string) (string, error) { // Try to get the serial from sysfs, look at the disk device (minor 0) directly // because if it is a partition it is not going to contain any device information devicePath := common.HostSysWithContext(ctx, fmt.Sprintf("dev/block/%d:0/device", major)) - model, _ := ioutil.ReadFile(filepath.Join(devicePath, "model")) - serial, _ := ioutil.ReadFile(filepath.Join(devicePath, "serial")) + model, _ := os.ReadFile(filepath.Join(devicePath, "model")) + serial, _ := os.ReadFile(filepath.Join(devicePath, "serial")) if len(model) > 0 && len(serial) > 0 { return fmt.Sprintf("%s_%s", string(model), string(serial)), nil } @@ -526,7 +525,7 @@ func LabelWithContext(ctx context.Context, name string) (string, error) { return "", nil } - dmname, err := ioutil.ReadFile(dmname_filename) + dmname, err := os.ReadFile(dmname_filename) if err != nil { return "", err } diff --git a/host/host_darwin.go b/host/host_darwin.go index 1be2e8533..f045d4f17 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -8,7 +8,7 @@ import ( "context" "encoding/binary" "errors" - "io/ioutil" + "io" "os" "strings" "unsafe" @@ -59,7 +59,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { } defer file.Close() - buf, err := ioutil.ReadAll(file) + buf, err := io.ReadAll(file) if err != nil { return ret, err } diff --git a/host/host_freebsd.go b/host/host_freebsd.go index 2c9aa9d0d..9a5382d39 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -7,7 +7,7 @@ import ( "bytes" "context" "encoding/binary" - "io/ioutil" + "io" "math" "os" "strings" @@ -54,7 +54,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { } defer file.Close() - buf, err := ioutil.ReadAll(file) + buf, err := io.ReadAll(file) if err != nil { return ret, err } @@ -111,7 +111,7 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) { } defer file.Close() - buf, err := ioutil.ReadAll(file) + buf, err := io.ReadAll(file) if err != nil { return ret, err } diff --git a/host/host_linux.go b/host/host_linux.go index e6ac63a39..f9d7995e7 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -8,7 +8,7 @@ import ( "context" "encoding/binary" "fmt" - "io/ioutil" + "io" "os" "path/filepath" "regexp" @@ -91,7 +91,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { } defer file.Close() - buf, err := ioutil.ReadAll(file) + buf, err := io.ReadAll(file) if err != nil { return nil, err } @@ -411,13 +411,13 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err } for _, file := range files { // Get the name of the temperature you are reading - name, err := ioutil.ReadFile(filepath.Join(file, "type")) + name, err := os.ReadFile(filepath.Join(file, "type")) if err != nil { warns.Add(err) continue } // Get the temperature reading - current, err := ioutil.ReadFile(filepath.Join(file, "temp")) + current, err := os.ReadFile(filepath.Join(file, "temp")) if err != nil { warns.Add(err) continue @@ -461,13 +461,13 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err // Get the label of the temperature you are reading label := "" - if raw, _ = ioutil.ReadFile(basepath + "_label"); len(raw) != 0 { + if raw, _ = os.ReadFile(basepath + "_label"); len(raw) != 0 { // Format the label from "Core 0" to "core_0" label = strings.Join(strings.Split(strings.TrimSpace(strings.ToLower(string(raw))), " "), "_") } // Get the name of the temperature you are reading - if raw, err = ioutil.ReadFile(filepath.Join(directory, "name")); err != nil { + if raw, err = os.ReadFile(filepath.Join(directory, "name")); err != nil { warns.Add(err) continue } @@ -479,7 +479,7 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err } // Get the temperature reading - if raw, err = ioutil.ReadFile(file); err != nil { + if raw, err = os.ReadFile(file); err != nil { warns.Add(err) continue } @@ -513,7 +513,7 @@ func optionalValueReadFromFile(filename string) float64 { return 0 } - if raw, err = ioutil.ReadFile(filename); err != nil { + if raw, err = os.ReadFile(filename); err != nil { return 0 } diff --git a/host/host_openbsd.go b/host/host_openbsd.go index 569de4abd..325015c23 100644 --- a/host/host_openbsd.go +++ b/host/host_openbsd.go @@ -7,7 +7,7 @@ import ( "bytes" "context" "encoding/binary" - "io/ioutil" + "io" "os" "strings" "unsafe" @@ -65,7 +65,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { } defer file.Close() - buf, err := ioutil.ReadAll(file) + buf, err := io.ReadAll(file) if err != nil { return ret, err } diff --git a/host/host_solaris.go b/host/host_solaris.go index 7d3625acb..e0661b00a 100644 --- a/host/host_solaris.go +++ b/host/host_solaris.go @@ -138,7 +138,7 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) { // Find distribution name from /etc/release func parseReleaseFile() (string, error) { - b, err := ioutil.ReadFile("/etc/release") + b, err := os.ReadFile("/etc/release") if err != nil { return "", err } diff --git a/internal/common/common.go b/internal/common/common.go index 7a31d251b..99ed6a58e 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -14,7 +14,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/url" "os" "os/exec" @@ -87,7 +86,7 @@ func (i FakeInvoke) Command(name string, arg ...string) ([]byte, error) { fpath += "_" + i.Suffix } if PathExists(fpath) { - return ioutil.ReadFile(fpath) + return os.ReadFile(fpath) } return []byte{}, fmt.Errorf("could not find testdata: %s", fpath) } @@ -100,7 +99,7 @@ var ErrNotImplementedError = errors.New("not implemented yet") // ReadFile reads contents from a file func ReadFile(filename string) (string, error) { - content, err := ioutil.ReadFile(filename) + content, err := os.ReadFile(filename) if err != nil { return "", err } diff --git a/load/load_linux.go b/load/load_linux.go index 0298c8bed..06bceeb84 100644 --- a/load/load_linux.go +++ b/load/load_linux.go @@ -5,7 +5,7 @@ package load import ( "context" - "io/ioutil" + "os" "strconv" "strings" "syscall" @@ -76,7 +76,7 @@ func Misc() (*MiscStat, error) { func MiscWithContext(ctx context.Context) (*MiscStat, error) { filename := common.HostProcWithContext(ctx, "stat") - out, err := ioutil.ReadFile(filename) + out, err := os.ReadFile(filename) if err != nil { return nil, err } @@ -126,7 +126,7 @@ func getProcsTotal(ctx context.Context) (int64, error) { func readLoadAvgFromFile(ctx context.Context) ([]string, error) { loadavgFilename := common.HostProcWithContext(ctx, "loadavg") - line, err := ioutil.ReadFile(loadavgFilename) + line, err := os.ReadFile(loadavgFilename) if err != nil { return nil, err } diff --git a/net/net_linux.go b/net/net_linux.go index de0ea7345..6e8ce67fb 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -10,7 +10,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "os" "strconv" @@ -643,7 +642,7 @@ func (p *process) getUids(ctx context.Context) ([]int32, error) { func (p *process) fillFromStatus(ctx context.Context) error { pid := p.Pid statPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "status") - contents, err := ioutil.ReadFile(statPath) + contents, err := os.ReadFile(statPath) if err != nil { return err } @@ -784,7 +783,7 @@ func processInetWithContext(ctx context.Context, file string, kind netConnection // This minimizes duplicates in the returned connections // For more info: // https://github.com/shirou/gopsutil/pull/361 - contents, err := ioutil.ReadFile(file) + contents, err := os.ReadFile(file) if err != nil { return nil, err } @@ -845,7 +844,7 @@ func processUnix(file string, kind netConnectionKindType, inodes map[string][]in // This minimizes duplicates in the returned connections // For more info: // https://github.com/shirou/gopsutil/pull/361 - contents, err := ioutil.ReadFile(file) + contents, err := os.ReadFile(file) if err != nil { return nil, err } diff --git a/process/process_linux.go b/process/process_linux.go index 37cb7ca44..f7989cd21 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -9,7 +9,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "math" "os" "path/filepath" @@ -136,7 +135,7 @@ func (p *Process) ForegroundWithContext(ctx context.Context) (bool, error) { // see https://github.com/shirou/gopsutil/issues/596#issuecomment-432707831 for implementation details pid := p.Pid statPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "stat") - contents, err := ioutil.ReadFile(statPath) + contents, err := os.ReadFile(statPath) if err != nil { return false, err } @@ -391,7 +390,7 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M smapsPath = smapsRollupPath } } - contents, err := ioutil.ReadFile(smapsPath) + contents, err := os.ReadFile(smapsPath) if err != nil { return nil, err } @@ -484,7 +483,7 @@ func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]M func (p *Process) EnvironWithContext(ctx context.Context) ([]string, error) { environPath := common.HostProcWithContext(ctx, strconv.Itoa(int(p.Pid)), "environ") - environContent, err := ioutil.ReadFile(environPath) + environContent, err := os.ReadFile(environPath) if err != nil { return nil, err } @@ -668,7 +667,7 @@ func (p *Process) fillFromExeWithContext(ctx context.Context) (string, error) { func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error) { pid := p.Pid cmdPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "cmdline") - cmdline, err := ioutil.ReadFile(cmdPath) + cmdline, err := os.ReadFile(cmdPath) if err != nil { return "", err } @@ -682,7 +681,7 @@ func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error func (p *Process) fillSliceFromCmdlineWithContext(ctx context.Context) ([]string, error) { pid := p.Pid cmdPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "cmdline") - cmdline, err := ioutil.ReadFile(cmdPath) + cmdline, err := os.ReadFile(cmdPath) if err != nil { return nil, err } @@ -705,7 +704,7 @@ func (p *Process) fillSliceFromCmdlineWithContext(ctx context.Context) ([]string func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, error) { pid := p.Pid ioPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "io") - ioline, err := ioutil.ReadFile(ioPath) + ioline, err := os.ReadFile(ioPath) if err != nil { return nil, err } @@ -741,7 +740,7 @@ func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, e func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoStat, *MemoryInfoExStat, error) { pid := p.Pid memPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "statm") - contents, err := ioutil.ReadFile(memPath) + contents, err := os.ReadFile(memPath) if err != nil { return nil, nil, err } @@ -802,7 +801,7 @@ func (p *Process) fillNameWithContext(ctx context.Context) error { func (p *Process) fillFromCommWithContext(ctx context.Context) error { pid := p.Pid statPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "comm") - contents, err := ioutil.ReadFile(statPath) + contents, err := os.ReadFile(statPath) if err != nil { return err } @@ -819,7 +818,7 @@ func (p *Process) fillFromStatus() error { func (p *Process) fillFromStatusWithContext(ctx context.Context) error { pid := p.Pid statPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "status") - contents, err := ioutil.ReadFile(statPath) + contents, err := os.ReadFile(statPath) if err != nil { return err } @@ -1026,7 +1025,7 @@ func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (ui statPath = common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "task", strconv.Itoa(int(tid)), "stat") } - contents, err := ioutil.ReadFile(statPath) + contents, err := os.ReadFile(statPath) if err != nil { return 0, 0, nil, 0, 0, 0, nil, err } diff --git a/process/process_linux_test.go b/process/process_linux_test.go index e8c2e8350..c2001149d 100644 --- a/process/process_linux_test.go +++ b/process/process_linux_test.go @@ -72,7 +72,7 @@ func Test_Process_splitProcStat_fromFile(t *testing.T) { if _, err := os.Stat(statFile); err != nil { continue } - contents, err := ioutil.ReadFile(statFile) + contents, err := os.ReadFile(statFile) assert.NoError(t, err) pidStr := strconv.Itoa(int(pid)) diff --git a/process/process_solaris.go b/process/process_solaris.go index ad1c3cfc1..dd4bd4760 100644 --- a/process/process_solaris.go +++ b/process/process_solaris.go @@ -3,7 +3,6 @@ package process import ( "bytes" "context" - "io/ioutil" "os" "strconv" "strings" @@ -232,7 +231,7 @@ func (p *Process) fillFromPathAOutWithContext(ctx context.Context) (string, erro func (p *Process) fillFromExecnameWithContext(ctx context.Context) (string, error) { pid := p.Pid execNamePath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "execname") - exe, err := ioutil.ReadFile(execNamePath) + exe, err := os.ReadFile(execNamePath) if err != nil { return "", err } @@ -242,7 +241,7 @@ func (p *Process) fillFromExecnameWithContext(ctx context.Context) (string, erro func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error) { pid := p.Pid cmdPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "cmdline") - cmdline, err := ioutil.ReadFile(cmdPath) + cmdline, err := os.ReadFile(cmdPath) if err != nil { return "", err } @@ -259,7 +258,7 @@ func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error func (p *Process) fillSliceFromCmdlineWithContext(ctx context.Context) ([]string, error) { pid := p.Pid cmdPath := common.HostProcWithContext(ctx, strconv.Itoa(int(pid)), "cmdline") - cmdline, err := ioutil.ReadFile(cmdPath) + cmdline, err := os.ReadFile(cmdPath) if err != nil { return nil, err } diff --git a/process/process_test.go b/process/process_test.go index fc44963ef..fcb11fadc 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -4,6 +4,7 @@ import ( "bufio" "errors" "fmt" + "io" "io/ioutil" "net" "os" @@ -571,7 +572,7 @@ func Test_Connections(t *testing.T) { defer conn.Close() serverEstablished <- struct{}{} - _, err = ioutil.ReadAll(conn) + _, err = io.ReadAll(conn) if err != nil { panic(err) } From 7df86f0f6aef333f3b875c64f280e56b88cec950 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 9 Sep 2023 17:47:44 +0800 Subject: [PATCH 11/66] Add disk partitions support for NetBSD --- disk/disk_netbsd.go | 26 ++++++++++++++++++++++---- disk/disk_netbsd_arm64.go | 38 ++++++++++++++++++++++++++++++++++++++ disk/types_netbsd.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 disk/disk_netbsd_arm64.go create mode 100644 disk/types_netbsd.go diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 6f1ba3ff5..062d77399 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -14,23 +14,41 @@ import ( func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat + + flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h // get required buffer size r, _, err = unix.Syscall6( 483, // SYS___getvfsstat90 syscall nil, 0, - 1, // ST_WAIT/MNT_WAIT, see sys/fstypes.h + uintptr(unsafe.Pointer(&flag)), ) if err != nil { return ret, err } mountedFsCount := uint64(r) + // calculate the buffer size + bufSize := sizeOfStatvfs * mountedFsCount + buf := make([]Statvfs, bufSize) + + // request agian to get desired mount data + _, _, err = unix.Syscall6( + 483, + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&bufSize)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != nil { + return ret, err + } + + for _, stat := range buf { d := PartitionStat{ - Device: common.ByteToString(stat.F_mntfromname[:]), - Mountpoint: common.ByteToString(stat.F_mntonname[:]), - Fstype: common.ByteToString(stat.F_fstypename[:]), + Device: common.ByteToString([]byte(stat.Mntfromname[:])), + Mountpoint: common.ByteToString([]byte(stat.Mntonname[:])), + Fstype: common.ByteToString([]byte(stat.Fstypename[:])), Opts: opts, } diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go new file mode 100644 index 000000000..9d364d4f2 --- /dev/null +++ b/disk/disk_netbsd_arm64.go @@ -0,0 +1,38 @@ +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs types_netbsd.go + +package disk + +const ( + sizeOfStatvfs = 0xce0 +) + +type ( + Statvfs struct { + Flag uint64 + Bsize uint64 + Frsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail uint64 + Bresvd uint64 + Files uint64 + Ffree uint64 + Favail uint64 + Fresvd uint64 + Syncreads uint64 + Syncwrites uint64 + Asyncreads uint64 + Asyncwrites uint64 + Fsidx _Ctype_struct___0 + Fsid uint64 + Namemax uint64 + Owner uint32 + Spare [4]uint64 + Fstypename [32]uint8 + Mntonname [1024]uint8 + Mntfromname [1024]uint8 + Mntfromlabel [1024]uint8 + } +) diff --git a/disk/types_netbsd.go b/disk/types_netbsd.go new file mode 100644 index 000000000..25217a08b --- /dev/null +++ b/disk/types_netbsd.go @@ -0,0 +1,30 @@ +//go:build ignore +// +build ignore + +// Hand writing: _Ctype_struct_statvfs + +/* +Input to cgo -godefs. +*/ + +package disk + +/* +#include +#include +#include +#include +#include +#include +#include +#include +*/ +import "C" + +const ( + sizeOfStatvfs = C.sizeof_struct_statvfs +) + +type ( + Statvfs C.struct_statvfs +) From b6a10e04e7a1c2d09252d1f96c6f020ddf0dad72 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 9 Sep 2023 20:32:59 +0800 Subject: [PATCH 12/66] disk: Implement Usage for NetBSD --- disk/disk_netbsd.go | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 062d77399..32f4319d1 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -111,32 +111,40 @@ func parseDiskstats(buf []byte) (Diskstats, error) { } func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { - stat := unix.Statfs_t{} - err := unix.Statfs(path, &stat) - if err != nil { - return nil, err - } - bsize := stat.F_bsize + stat := Statvfs{} + flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h + + // request agian to get desired mount data + ret, _, err = unix.Syscall6( + 485, // SYS___fstatvfs190, see sys/syscall.h + uintptr(unsafe.Pointer(&path)), + uintptr(unsafe.Pointer(&stat)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != nil { + return ret, err + } + bsize := stat.Bsize ret := &UsageStat{ Path: path, Fstype: getFsType(stat), - Total: (uint64(stat.F_blocks) * uint64(bsize)), - Free: (uint64(stat.F_bavail) * uint64(bsize)), - InodesTotal: (uint64(stat.F_files)), - InodesFree: (uint64(stat.F_ffree)), + Total: (uint64(stat.Blocks) * uint64(bsize)), + Free: (uint64(stat.Bavail) * uint64(bsize)), + InodesTotal: (uint64(stat.Files)), + InodesFree: (uint64(stat.Ffree)), } ret.InodesUsed = (ret.InodesTotal - ret.InodesFree) ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 - ret.Used = (uint64(stat.F_blocks) - uint64(stat.F_bfree)) * uint64(bsize) + ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize) ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 return ret, nil } -func getFsType(stat unix.Statfs_t) string { - return common.ByteToString(stat.F_fstypename[:]) +func getFsType(stat Statvfs) string { + return common.ByteToString(stat.Fstypename[:]) } func SerialNumberWithContext(ctx context.Context, name string) (string, error) { From e82d2e4ca8868c2f3db2a7b61945a0f796167089 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 9 Sep 2023 21:25:51 +0800 Subject: [PATCH 13/66] host: enable uptime for NetBSD --- host/host_bsd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/host/host_bsd.go b/host/host_bsd.go index 4dc2bba58..67ae900bc 100644 --- a/host/host_bsd.go +++ b/host/host_bsd.go @@ -1,5 +1,5 @@ -//go:build darwin || freebsd || openbsd -// +build darwin freebsd openbsd +//go:build darwin || freebsd || openbsd || netbsd +// +build darwin freebsd openbsd netbsd package host From 6100e33de2789668fac4d9290cdd13f52ea2673c Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 02:31:10 +0800 Subject: [PATCH 14/66] mem: code cleanup --- mem/mem_fallback.go | 4 ++-- mem/mem_netbsd.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mem/mem_fallback.go b/mem/mem_fallback.go index 0b6c528f2..697fd8709 100644 --- a/mem/mem_fallback.go +++ b/mem/mem_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !plan9 && !aix -// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!plan9,!aix +//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !plan9 && !aix && !netbsd +// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!plan9,!aix,!netbsd package mem diff --git a/mem/mem_netbsd.go b/mem/mem_netbsd.go index fb6fafecf..6e2be3fa1 100644 --- a/mem/mem_netbsd.go +++ b/mem/mem_netbsd.go @@ -4,13 +4,10 @@ package mem import ( - "bytes" "context" - "encoding/binary" "errors" "fmt" - "github.com/shirou/gopsutil/v3/internal/common" "golang.org/x/sys/unix" ) @@ -51,7 +48,10 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 // Get buffers from vm.bufmem sysctl - ret.Buffers = unix.SysctlUint64("vm.bufmem") + ret.Buffers, err = unix.SysctlUint64("vm.bufmem") + if err != nil { + return nil, err + } return ret, nil } From caafa49ed19251151a646a94ade123c34d37844f Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 02:40:14 +0800 Subject: [PATCH 15/66] disk: code cleanup --- disk/disk_netbsd.go | 49 +-------------------------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 32f4319d1..2f9a39a11 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -60,54 +60,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { ret := make(map[string]IOCountersStat) - - r, err := unix.SysctlRaw("hw.diskstats") - if err != nil { - return nil, err - } - buf := []byte(r) - length := len(buf) - - count := int(uint64(length) / uint64(sizeOfDiskstats)) - - // parse buf to Diskstats - for i := 0; i < count; i++ { - b := buf[i*sizeOfDiskstats : i*sizeOfDiskstats+sizeOfDiskstats] - d, err := parseDiskstats(b) - if err != nil { - continue - } - name := common.IntToString(d.Name[:]) - - if len(names) > 0 && !common.StringsHas(names, name) { - continue - } - - ds := IOCountersStat{ - ReadCount: d.Rxfer, - WriteCount: d.Wxfer, - ReadBytes: d.Rbytes, - WriteBytes: d.Wbytes, - Name: name, - } - ret[name] = ds - } - - return ret, nil -} - -// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE) - -func parseDiskstats(buf []byte) (Diskstats, error) { - var ds Diskstats - br := bytes.NewReader(buf) - // err := binary.Read(br, binary.LittleEndian, &ds) - err := common.Read(br, binary.LittleEndian, &ds) - if err != nil { - return ds, err - } - - return ds, nil + return ret, common.ErrNotImplementedError } func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { From ec817bfa68866cbd5d6f8e70cc9a2761c2e16b09 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 23:33:42 +0800 Subject: [PATCH 16/66] disk: code cleanup (not finish yet) --- disk/disk_fallback.go | 4 +-- disk/disk_netbsd.go | 59 ++++++++++++++++++++++++++++++++------- disk/disk_netbsd_arm64.go | 7 +++++ disk/types_netbsd.go | 4 +-- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/disk/disk_fallback.go b/disk/disk_fallback.go index 476873340..36525f694 100644 --- a/disk/disk_fallback.go +++ b/disk/disk_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !windows && !solaris && !aix -// +build !darwin,!linux,!freebsd,!openbsd,!windows,!solaris,!aix +//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !windows && !solaris && !aix +// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!windows,!solaris,!aix package disk diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 2f9a39a11..94ff76eb8 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -1,5 +1,5 @@ -//go:build openbsd -// +build openbsd +//go:build netbsd +// +build netbsd package disk @@ -7,24 +7,37 @@ import ( "bytes" "context" "encoding/binary" + "unsafe" "github.com/shirou/gopsutil/v3/internal/common" "golang.org/x/sys/unix" ) +const ( + // see sys/fstypes.h and `man 5 statvfs` + MNT_RDONLY = 0x00000001 /* read only filesystem */ + MNT_SYNCHRONOUS = 0x00000002 /* file system written synchronously */ + MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ + MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ + MNT_NODEV = 0x00000010 /* don't interpret special files */ + MNT_ASYNC = 0x00000040 /* file system written asynchronously */ + MNT_NOATIME = 0x04000000 /* Never update access times in fs */ + MNT_SOFTDEP = 0x80000000 /* Use soft dependencies */ +) + func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h // get required buffer size - r, _, err = unix.Syscall6( + r, _, err := unix.Syscall( 483, // SYS___getvfsstat90 syscall - nil, 0, - uintptr(unsafe.Pointer(&flag)), + 0, + uintptr(unsafe.Pointer(&flag)), ) - if err != nil { + if err != 0 { return ret, err } mountedFsCount := uint64(r) @@ -34,17 +47,43 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro buf := make([]Statvfs, bufSize) // request agian to get desired mount data - _, _, err = unix.Syscall6( + _, _, err = unix.Syscall( 483, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bufSize)), uintptr(unsafe.Pointer(&flag)), ) - if err != nil { + if err != 0 { return ret, err } for _, stat := range buf { + opts := []string{"rw"} + if stat.Flag&MNT_RDONLY != 0 { + opts = []string{"rw"} + } + if stat.Flag&MNT_SYNCHRONOUS != 0 { + opts = append(opts, "sync") + } + if stat.Flag&MNT_NOEXEC != 0 { + opts = append(opts, "noexec") + } + if stat.Flag&MNT_NOSUID != 0 { + opts = append(opts, "nosuid") + } + if stat.Flag&MNT_NODEV != 0 { + opts = append(opts, "nodev") + } + if stat.Flag&MNT_ASYNC != 0 { + opts = append(opts, "async") + } + if stat.Flag&MNT_SOFTDEP != 0 { + opts = append(opts, "softdep") + } + if stat.Flag&MNT_NOATIME != 0 { + opts = append(opts, "noatime") + } + d := PartitionStat{ Device: common.ByteToString([]byte(stat.Mntfromname[:])), Mountpoint: common.ByteToString([]byte(stat.Mntonname[:])), @@ -68,13 +107,13 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h // request agian to get desired mount data - ret, _, err = unix.Syscall6( + ret, _, err := unix.Syscall( 485, // SYS___fstatvfs190, see sys/syscall.h uintptr(unsafe.Pointer(&path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), ) - if err != nil { + if err != 0 { return ret, err } diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go index 9d364d4f2..c98be60e3 100644 --- a/disk/disk_netbsd_arm64.go +++ b/disk/disk_netbsd_arm64.go @@ -1,3 +1,6 @@ +//go:build netbsd && arm64 +// +build netbsd,arm64 + // Code generated by cmd/cgo -godefs; DO NOT EDIT. // cgo -godefs types_netbsd.go @@ -36,3 +39,7 @@ type ( Mntfromlabel [1024]uint8 } ) + +type _Ctype_struct___0 struct { + FsidVal [32]int32 +} diff --git a/disk/types_netbsd.go b/disk/types_netbsd.go index 25217a08b..c0326f5c2 100644 --- a/disk/types_netbsd.go +++ b/disk/types_netbsd.go @@ -1,7 +1,7 @@ //go:build ignore // +build ignore -// Hand writing: _Ctype_struct_statvfs +// Hand writing: _Ctype_struct___0 /* Input to cgo -godefs. @@ -17,7 +17,7 @@ package disk #include #include #include -#include + */ import "C" From 1136aa25dac981a7abf8e12c1921b8e54bc1be86 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 10 Sep 2023 23:37:30 +0800 Subject: [PATCH 17/66] disk: code can be compiled now, but test still failed though --- disk/disk_netbsd.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 94ff76eb8..09432d6bf 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -4,9 +4,7 @@ package disk import ( - "bytes" "context" - "encoding/binary" "unsafe" "github.com/shirou/gopsutil/v3/internal/common" @@ -106,15 +104,14 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { stat := Statvfs{} flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h - // request agian to get desired mount data - ret, _, err := unix.Syscall( + _, _, err := unix.Syscall( 485, // SYS___fstatvfs190, see sys/syscall.h uintptr(unsafe.Pointer(&path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), ) if err != 0 { - return ret, err + return nil, err } bsize := stat.Bsize From 319f5ea6e5393d415e3b95fab8737bac85109bec Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Tue, 12 Sep 2023 00:16:22 +0800 Subject: [PATCH 18/66] disk: small improvement, but still doesn't work --- disk/disk_netbsd.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 09432d6bf..c3459e15b 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -26,13 +26,15 @@ const ( func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat + trap := 483 // SYS___getvfsstat90 syscall flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h // get required buffer size + emptyBufSize := 0 r, _, err := unix.Syscall( - 483, // SYS___getvfsstat90 syscall - 0, - 0, + uintptr(unsafe.Pointer(&trap)), + uintptr(unsafe.Pointer(nil)), + uintptr(unsafe.Pointer(&emptyBufSize)), uintptr(unsafe.Pointer(&flag)), ) if err != 0 { @@ -46,7 +48,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro // request agian to get desired mount data _, _, err = unix.Syscall( - 483, + uintptr(unsafe.Pointer(&flag)), uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bufSize)), uintptr(unsafe.Pointer(&flag)), @@ -102,10 +104,11 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { stat := Statvfs{} + trap := 485 // SYS___fstatvfs190, see sys/syscall.h flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h _, _, err := unix.Syscall( - 485, // SYS___fstatvfs190, see sys/syscall.h + uintptr(unsafe.Pointer(&trap)), uintptr(unsafe.Pointer(&path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), From c806740b348abc3b0a5abb0aa181cf1982b7acc4 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Tue, 12 Sep 2023 14:14:04 +0200 Subject: [PATCH 19/66] ci(lint): ensure io/ioutil replacement (#1525) * ci(lint): enure ioutil replacement Signed-off-by: Matthieu MOREL * Update host_solaris.go * Update process_linux_test.go * Update net_linux_test.go * Update net_linux_test.go * Update process_test.go * Update process_linux_test.go * Update process_linux_test.go --------- Signed-off-by: Matthieu MOREL --- .github/workflows/lint.yml | 1 + .golangci.yml | 47 ++++++++++++++++++++--------------- host/host_solaris.go | 3 +-- net/net_linux_test.go | 5 ++-- process/process_linux_test.go | 9 +++---- process/process_test.go | 9 +++---- 6 files changed, 39 insertions(+), 35 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 91feb3940..245f7e983 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -19,6 +19,7 @@ jobs: uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 with: go-version: 1.17 + cache: false - name: Checkout repository uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 - name: Setup golangci-lint diff --git a/.golangci.yml b/.golangci.yml index 4d163db1a..170626bfd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,21 +1,21 @@ issues: max-same-issues: 0 - exclude-rules: - - linters: - - gosec - text: "G204" - - linters: - - revive - text: "var-naming" - - linters: - - revive - text: "exported" - - linters: - - revive - text: "empty-block" - - linters: - - revive - text: "unused-parameter" + exclude-rules: + - linters: + - gosec + text: "G204" + - linters: + - revive + text: "var-naming" + - linters: + - revive + text: "exported" + - linters: + - revive + text: "empty-block" + - linters: + - revive + text: "unused-parameter" linters: enable: - asciicheck @@ -26,6 +26,7 @@ linters: - gofmt - gofumpt - goimports + - gomodguard - gosec - gosimple - importas @@ -46,10 +47,16 @@ linters: - structcheck - unused - varcheck - linters-settings: gci: sections: - - standard - - default - - prefix(github.com/shirou) + - standard + - default + - prefix(github.com/shirou) + gomodguard: + blocked: + modules: + - io/ioutil: + recommandations: + - io + - os diff --git a/host/host_solaris.go b/host/host_solaris.go index e0661b00a..fef67f835 100644 --- a/host/host_solaris.go +++ b/host/host_solaris.go @@ -7,7 +7,6 @@ import ( "encoding/csv" "fmt" "io" - "io/ioutil" "os" "regexp" "strconv" @@ -60,7 +59,7 @@ func HostIDWithContext(ctx context.Context) (string, error) { // Count number of processes based on the number of entries in /proc func numProcs(ctx context.Context) (uint64, error) { - dirs, err := ioutil.ReadDir("/proc") + dirs, err := os.ReadDir("/proc") if err != nil { return 0, err } diff --git a/net/net_linux_test.go b/net/net_linux_test.go index f1b7fbaa7..eae0e71b9 100644 --- a/net/net_linux_test.go +++ b/net/net_linux_test.go @@ -3,7 +3,6 @@ package net import ( "context" "fmt" - "io/ioutil" "net" "os" "strings" @@ -17,7 +16,7 @@ import ( func TestIOCountersByFileParsing(t *testing.T) { // Prpare a temporary file, which will be read during the test - tmpfile, err := ioutil.TempFile("", "proc_dev_net") + tmpfile, err := os.CreateTemp("", "proc_dev_net") defer os.Remove(tmpfile.Name()) // clean up assert.Nil(t, err, "Temporary file creation failed: ", err) @@ -195,7 +194,7 @@ func TestReverse(t *testing.T) { } func TestConntrackStatFileParsing(t *testing.T) { - tmpfile, err := ioutil.TempFile("", "proc_net_stat_conntrack") + tmpfile, err := os.CreateTemp("", "proc_net_stat_conntrack") defer os.Remove(tmpfile.Name()) assert.Nil(t, err, "Temporary file creation failed: ", err) diff --git a/process/process_linux_test.go b/process/process_linux_test.go index c2001149d..87df81231 100644 --- a/process/process_linux_test.go +++ b/process/process_linux_test.go @@ -6,7 +6,6 @@ package process import ( "context" "fmt" - "io/ioutil" "os" "strconv" "strings" @@ -58,7 +57,7 @@ func Test_Process_splitProcStat(t *testing.T) { } func Test_Process_splitProcStat_fromFile(t *testing.T) { - pids, err := ioutil.ReadDir("testdata/linux/") + pids, err := os.ReadDir("testdata/linux/") if err != nil { t.Error(err) } @@ -94,7 +93,7 @@ func Test_Process_splitProcStat_fromFile(t *testing.T) { } func Test_fillFromCommWithContext(t *testing.T) { - pids, err := ioutil.ReadDir("testdata/linux/") + pids, err := os.ReadDir("testdata/linux/") if err != nil { t.Error(err) } @@ -115,7 +114,7 @@ func Test_fillFromCommWithContext(t *testing.T) { } func Test_fillFromStatusWithContext(t *testing.T) { - pids, err := ioutil.ReadDir("testdata/linux/") + pids, err := os.ReadDir("testdata/linux/") if err != nil { t.Error(err) } @@ -154,7 +153,7 @@ func Benchmark_fillFromStatusWithContext(b *testing.B) { } func Test_fillFromTIDStatWithContext_lx_brandz(t *testing.T) { - pids, err := ioutil.ReadDir("testdata/lx_brandz/") + pids, err := os.ReadDir("testdata/lx_brandz/") if err != nil { t.Error(err) } diff --git a/process/process_test.go b/process/process_test.go index fcb11fadc..51f7d9cf6 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net" "os" "os/exec" @@ -303,7 +302,7 @@ func Test_Process_Name(t *testing.T) { } func Test_Process_Long_Name_With_Spaces(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "") + tmpdir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("unable to create temp dir %v", err) } @@ -349,7 +348,7 @@ func Test_Process_Long_Name_With_Spaces(t *testing.T) { } func Test_Process_Long_Name(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "") + tmpdir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("unable to create temp dir %v", err) } @@ -406,7 +405,7 @@ func Test_Process_Name_Against_Python(t *testing.T) { t.Skipf("psutil not found for %s: %s", py3Path, out) } - tmpdir, err := ioutil.TempDir("", "") + tmpdir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("unable to create temp dir %v", err) } @@ -775,7 +774,7 @@ func Test_IsRunning(t *testing.T) { } func Test_Process_Environ(t *testing.T) { - tmpdir, err := ioutil.TempDir("", "") + tmpdir, err := os.MkdirTemp("", "") if err != nil { t.Fatalf("unable to create temp dir %v", err) } From 03d43fb5a25e9c62cc3662c11e05c2bb7c00d651 Mon Sep 17 00:00:00 2001 From: TossPig Date: Thu, 14 Sep 2023 05:05:59 +0800 Subject: [PATCH 20/66] [load][windows] Fix DATA RACE in load. Avg() fixed #1526 --- load/load_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/load/load_windows.go b/load/load_windows.go index b48483849..8f53efae3 100644 --- a/load/load_windows.go +++ b/load/load_windows.go @@ -45,8 +45,8 @@ func loadAvgGoroutine(ctx context.Context) { f := func() { currentLoad, err = counter.GetValue() - loadErr = err loadAvgMutex.Lock() + loadErr = err loadAvg1M = loadAvg1M*loadAvgFactor1M + currentLoad*(1-loadAvgFactor1M) loadAvg5M = loadAvg5M*loadAvgFactor5M + currentLoad*(1-loadAvgFactor5M) loadAvg15M = loadAvg15M*loadAvgFactor15M + currentLoad*(1-loadAvgFactor15M) From dd0253b0ec811dd1f7cf419e244ebe0a328ff0d1 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 16 Sep 2023 04:03:33 +0800 Subject: [PATCH 21/66] disk: fix various bugs --- disk/disk_netbsd.go | 17 ++++++++++------- disk/disk_netbsd_arm64.go | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index c3459e15b..8973ec516 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -26,13 +26,12 @@ const ( func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat - trap := 483 // SYS___getvfsstat90 syscall flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h // get required buffer size emptyBufSize := 0 r, _, err := unix.Syscall( - uintptr(unsafe.Pointer(&trap)), + 483, // SYS___getvfsstat90 syscall uintptr(unsafe.Pointer(nil)), uintptr(unsafe.Pointer(&emptyBufSize)), uintptr(unsafe.Pointer(&flag)), @@ -44,11 +43,11 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro // calculate the buffer size bufSize := sizeOfStatvfs * mountedFsCount - buf := make([]Statvfs, bufSize) + buf := make([]Statvfs, mountedFsCount) // request agian to get desired mount data _, _, err = unix.Syscall( - uintptr(unsafe.Pointer(&flag)), + 483, // SYS___getvfsstat90 syscall uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&bufSize)), uintptr(unsafe.Pointer(&flag)), @@ -104,12 +103,16 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { stat := Statvfs{} - trap := 485 // SYS___fstatvfs190, see sys/syscall.h flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h + _path, e := unix.BytePtrFromString(path) + if e != nil { + return nil, e + } + _, _, err := unix.Syscall( - uintptr(unsafe.Pointer(&trap)), - uintptr(unsafe.Pointer(&path)), + 484, // SYS___fstatvfs190, see sys/syscall.h + uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), ) diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go index c98be60e3..a2e806226 100644 --- a/disk/disk_netbsd_arm64.go +++ b/disk/disk_netbsd_arm64.go @@ -41,5 +41,5 @@ type ( ) type _Ctype_struct___0 struct { - FsidVal [32]int32 + FsidVal [2]int32 } From 734a7a6e5532143f572ecdaf3269dd1447e40ade Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 16 Sep 2023 15:49:22 +0800 Subject: [PATCH 22/66] disk: we should use frsize as the real block size --- disk/disk_netbsd.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index 8973ec516..d737d3142 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -111,7 +111,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { } _, _, err := unix.Syscall( - 484, // SYS___fstatvfs190, see sys/syscall.h + 484, // SYS___statvfs190, see sys/syscall.h uintptr(unsafe.Pointer(_path)), uintptr(unsafe.Pointer(&stat)), uintptr(unsafe.Pointer(&flag)), @@ -120,7 +120,8 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { return nil, err } - bsize := stat.Bsize + // frsize is the real block size on NetBSD. See discuss here: https://bugzilla.samba.org/show_bug.cgi?id=11810 + bsize := stat.Frsize ret := &UsageStat{ Path: path, Fstype: getFsType(stat), From 4a46201e00ab39278656b0e9727a1b9167312e5c Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sat, 16 Sep 2023 17:44:58 +0800 Subject: [PATCH 23/66] cpu && host: fix compile time errors --- cpu/cpu_fallback.go | 4 +- cpu/cpu_netbsd.go | 8 ---- cpu/cpu_netbsd_arm64.go | 5 +-- host/host_fallback.go | 4 +- host/host_netbsd.go | 55 ++++++++++++++++++++++++++ host/host_posix.go | 4 +- internal/common/common_netbsd.go | 66 ++++++++++++++++++++++++++++++++ 7 files changed, 129 insertions(+), 17 deletions(-) create mode 100644 host/host_netbsd.go create mode 100644 internal/common/common_netbsd.go diff --git a/cpu/cpu_fallback.go b/cpu/cpu_fallback.go index 6d7007ff9..089f603c8 100644 --- a/cpu/cpu_fallback.go +++ b/cpu/cpu_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows && !dragonfly && !plan9 && !aix -// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows,!dragonfly,!plan9,!aix +//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !solaris && !windows && !dragonfly && !plan9 && !aix +// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!solaris,!windows,!dragonfly,!plan9,!aix package cpu diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go index facc4237a..519ffdb25 100644 --- a/cpu/cpu_netbsd.go +++ b/cpu/cpu_netbsd.go @@ -14,14 +14,6 @@ import ( "golang.org/x/sys/unix" ) -type cpuTimes struct { - User uint64 - Nice uint64 - Sys uint64 - Intr uint64 - Idle uint64 -} - const ( // sys/sysctl.h ctlKern = 1 // "high kernel": proc, limits diff --git a/cpu/cpu_netbsd_arm64.go b/cpu/cpu_netbsd_arm64.go index d659058cd..8d5cfd9eb 100644 --- a/cpu/cpu_netbsd_arm64.go +++ b/cpu/cpu_netbsd_arm64.go @@ -1,10 +1,9 @@ package cpu type cpuTimes struct { - User uint64 + User uint64 Nice uint64 Sys uint64 - Spin uint64 - Intr uint64 + Intr uint64 Idle uint64 } diff --git a/host/host_fallback.go b/host/host_fallback.go index 585250f9a..a393ca15d 100644 --- a/host/host_fallback.go +++ b/host/host_fallback.go @@ -1,5 +1,5 @@ -//go:build !darwin && !linux && !freebsd && !openbsd && !solaris && !windows -// +build !darwin,!linux,!freebsd,!openbsd,!solaris,!windows +//go:build !darwin && !linux && !freebsd && !openbsd && !netbsd && !solaris && !windows +// +build !darwin,!linux,!freebsd,!openbsd,!netbsd,!solaris,!windows package host diff --git a/host/host_netbsd.go b/host/host_netbsd.go new file mode 100644 index 000000000..488f1dfc2 --- /dev/null +++ b/host/host_netbsd.go @@ -0,0 +1,55 @@ +//go:build netbsd +// +build netbsd + +package host + +import ( + "context" + "strings" + + "github.com/shirou/gopsutil/v3/internal/common" + "golang.org/x/sys/unix" +) + +func HostIDWithContext(ctx context.Context) (string, error) { + return "", common.ErrNotImplementedError +} + +func numProcs(ctx context.Context) (uint64, error) { + return 0, common.ErrNotImplementedError +} + +func PlatformInformationWithContext(ctx context.Context) (string, string, string, error) { + platform := "" + family := "" + version := "" + + p, err := unix.Sysctl("kern.ostype") + if err == nil { + platform = strings.ToLower(p) + } + v, err := unix.Sysctl("kern.osrelease") + if err == nil { + version = strings.ToLower(v) + } + + return platform, family, version, nil +} + +func VirtualizationWithContext(ctx context.Context) (string, string, error) { + return "", "", common.ErrNotImplementedError +} + +func UsersWithContext(ctx context.Context) ([]UserStat, error) { + var ret []UserStat + return ret, common.ErrNotImplementedError +} + +func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) { + return []TemperatureStat{}, common.ErrNotImplementedError +} + +func KernelVersionWithContext(ctx context.Context) (string, error) { + _, _, version, err := PlatformInformationWithContext(ctx) + return version, err +} diff --git a/host/host_posix.go b/host/host_posix.go index 24529f19f..e7e0d837f 100644 --- a/host/host_posix.go +++ b/host/host_posix.go @@ -1,5 +1,5 @@ -//go:build linux || freebsd || openbsd || darwin || solaris -// +build linux freebsd openbsd darwin solaris +//go:build linux || freebsd || openbsd || netbsd || darwin || solaris +// +build linux freebsd openbsd netbsd darwin solaris package host diff --git a/internal/common/common_netbsd.go b/internal/common/common_netbsd.go new file mode 100644 index 000000000..efbc710a5 --- /dev/null +++ b/internal/common/common_netbsd.go @@ -0,0 +1,66 @@ +//go:build netbsd +// +build netbsd + +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)) + + // get required buffer size + length := uint64(0) + _, _, err := unix.Syscall6( + unix.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + 0, + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + var b []byte + return b, length, err + } + if length == 0 { + var b []byte + return b, length, err + } + // get proc info itself + buf := make([]byte, length) + _, _, err = unix.Syscall6( + unix.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + return buf, length, err + } + + return buf, length, nil +} From def3572629f18c1dae4789ff8ddce716078697ed Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Sun, 17 Sep 2023 01:43:13 +0800 Subject: [PATCH 24/66] format the code --- cpu/cpu_netbsd.go | 10 +-- cpu/cpu_netbsd_arm64.go | 4 +- disk/disk_netbsd.go | 124 +++++++++++++++++++------------------- disk/disk_netbsd_arm64.go | 52 ++++++++-------- mem/mem_netbsd.go | 2 +- 5 files changed, 96 insertions(+), 96 deletions(-) diff --git a/cpu/cpu_netbsd.go b/cpu/cpu_netbsd.go index 519ffdb25..1f66be342 100644 --- a/cpu/cpu_netbsd.go +++ b/cpu/cpu_netbsd.go @@ -16,9 +16,9 @@ import ( const ( // sys/sysctl.h - ctlKern = 1 // "high kernel": proc, limits - ctlHw = 6 // CTL_HW - kernCpTime = 51 // KERN_CPTIME + ctlKern = 1 // "high kernel": proc, limits + ctlHw = 6 // CTL_HW + kernCpTime = 51 // KERN_CPTIME ) var ClocksPerSec = float64(100) @@ -67,7 +67,7 @@ func TimesWithContext(ctx context.Context, percpu bool) (ret []TimesStat, err er return ret, err } - stats := (*cpuTimes)(unsafe.Pointer(&buf[0])) + stats := (*cpuTimes)(unsafe.Pointer(&buf[0])) ret = append(ret, TimesStat{ CPU: fmt.Sprintf("cpu%d", i), User: float64(stats.User), @@ -96,7 +96,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { if err != nil { return nil, err } - _, err = fmt.Sscanf(mhz, "%f", &c.Mhz) + _, err = fmt.Sscanf(mhz, "%f", &c.Mhz) if err != nil { return nil, err } diff --git a/cpu/cpu_netbsd_arm64.go b/cpu/cpu_netbsd_arm64.go index 8d5cfd9eb..57e14528d 100644 --- a/cpu/cpu_netbsd_arm64.go +++ b/cpu/cpu_netbsd_arm64.go @@ -1,9 +1,9 @@ package cpu type cpuTimes struct { - User uint64 + User uint64 Nice uint64 Sys uint64 - Intr uint64 + Intr uint64 Idle uint64 } diff --git a/disk/disk_netbsd.go b/disk/disk_netbsd.go index d737d3142..5976efadb 100644 --- a/disk/disk_netbsd.go +++ b/disk/disk_netbsd.go @@ -5,58 +5,58 @@ package disk import ( "context" - "unsafe" + "unsafe" "github.com/shirou/gopsutil/v3/internal/common" "golang.org/x/sys/unix" ) const ( - // see sys/fstypes.h and `man 5 statvfs` - MNT_RDONLY = 0x00000001 /* read only filesystem */ - MNT_SYNCHRONOUS = 0x00000002 /* file system written synchronously */ - MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ - MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ - MNT_NODEV = 0x00000010 /* don't interpret special files */ - MNT_ASYNC = 0x00000040 /* file system written asynchronously */ - MNT_NOATIME = 0x04000000 /* Never update access times in fs */ - MNT_SOFTDEP = 0x80000000 /* Use soft dependencies */ + // see sys/fstypes.h and `man 5 statvfs` + MNT_RDONLY = 0x00000001 /* read only filesystem */ + MNT_SYNCHRONOUS = 0x00000002 /* file system written synchronously */ + MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ + MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ + MNT_NODEV = 0x00000010 /* don't interpret special files */ + MNT_ASYNC = 0x00000040 /* file system written asynchronously */ + MNT_NOATIME = 0x04000000 /* Never update access times in fs */ + MNT_SOFTDEP = 0x80000000 /* Use soft dependencies */ ) func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) { var ret []PartitionStat - - flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h - - // get required buffer size - emptyBufSize := 0 - r, _, err := unix.Syscall( - 483, // SYS___getvfsstat90 syscall - uintptr(unsafe.Pointer(nil)), - uintptr(unsafe.Pointer(&emptyBufSize)), - uintptr(unsafe.Pointer(&flag)), - ) - if err != 0 { - return ret, err - } - mountedFsCount := uint64(r) - - // calculate the buffer size - bufSize := sizeOfStatvfs * mountedFsCount - buf := make([]Statvfs, mountedFsCount) - - // request agian to get desired mount data - _, _, err = unix.Syscall( - 483, // SYS___getvfsstat90 syscall - uintptr(unsafe.Pointer(&buf[0])), - uintptr(unsafe.Pointer(&bufSize)), - uintptr(unsafe.Pointer(&flag)), - ) - if err != 0 { - return ret, err - } - - for _, stat := range buf { + + flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h + + // get required buffer size + emptyBufSize := 0 + r, _, err := unix.Syscall( + 483, // SYS___getvfsstat90 syscall + uintptr(unsafe.Pointer(nil)), + uintptr(unsafe.Pointer(&emptyBufSize)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != 0 { + return ret, err + } + mountedFsCount := uint64(r) + + // calculate the buffer size + bufSize := sizeOfStatvfs * mountedFsCount + buf := make([]Statvfs, mountedFsCount) + + // request agian to get desired mount data + _, _, err = unix.Syscall( + 483, // SYS___getvfsstat90 syscall + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&bufSize)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != 0 { + return ret, err + } + + for _, stat := range buf { opts := []string{"rw"} if stat.Flag&MNT_RDONLY != 0 { opts = []string{"rw"} @@ -102,26 +102,26 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC } func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { - stat := Statvfs{} - flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h - - _path, e := unix.BytePtrFromString(path) - if e != nil { - return nil, e - } - - _, _, err := unix.Syscall( - 484, // SYS___statvfs190, see sys/syscall.h - uintptr(unsafe.Pointer(_path)), - uintptr(unsafe.Pointer(&stat)), - uintptr(unsafe.Pointer(&flag)), - ) - if err != 0 { - return nil, err - } - - // frsize is the real block size on NetBSD. See discuss here: https://bugzilla.samba.org/show_bug.cgi?id=11810 - bsize := stat.Frsize + stat := Statvfs{} + flag := uint64(1) // ST_WAIT/MNT_WAIT, see sys/fstypes.h + + _path, e := unix.BytePtrFromString(path) + if e != nil { + return nil, e + } + + _, _, err := unix.Syscall( + 484, // SYS___statvfs190, see sys/syscall.h + uintptr(unsafe.Pointer(_path)), + uintptr(unsafe.Pointer(&stat)), + uintptr(unsafe.Pointer(&flag)), + ) + if err != 0 { + return nil, err + } + + // frsize is the real block size on NetBSD. See discuss here: https://bugzilla.samba.org/show_bug.cgi?id=11810 + bsize := stat.Frsize ret := &UsageStat{ Path: path, Fstype: getFsType(stat), diff --git a/disk/disk_netbsd_arm64.go b/disk/disk_netbsd_arm64.go index a2e806226..dfe48f812 100644 --- a/disk/disk_netbsd_arm64.go +++ b/disk/disk_netbsd_arm64.go @@ -12,34 +12,34 @@ const ( type ( Statvfs struct { - Flag uint64 - Bsize uint64 - Frsize uint64 - Iosize uint64 - Blocks uint64 - Bfree uint64 - Bavail uint64 - Bresvd uint64 - Files uint64 - Ffree uint64 - Favail uint64 - Fresvd uint64 - Syncreads uint64 - Syncwrites uint64 - Asyncreads uint64 - Asyncwrites uint64 - Fsidx _Ctype_struct___0 - Fsid uint64 - Namemax uint64 - Owner uint32 - Spare [4]uint64 - Fstypename [32]uint8 - Mntonname [1024]uint8 - Mntfromname [1024]uint8 - Mntfromlabel [1024]uint8 + Flag uint64 + Bsize uint64 + Frsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail uint64 + Bresvd uint64 + Files uint64 + Ffree uint64 + Favail uint64 + Fresvd uint64 + Syncreads uint64 + Syncwrites uint64 + Asyncreads uint64 + Asyncwrites uint64 + Fsidx _Ctype_struct___0 + Fsid uint64 + Namemax uint64 + Owner uint32 + Spare [4]uint64 + Fstypename [32]uint8 + Mntonname [1024]uint8 + Mntfromname [1024]uint8 + Mntfromlabel [1024]uint8 } ) type _Ctype_struct___0 struct { - FsidVal [2]int32 + FsidVal [2]int32 } diff --git a/mem/mem_netbsd.go b/mem/mem_netbsd.go index 6e2be3fa1..d1f54ecaf 100644 --- a/mem/mem_netbsd.go +++ b/mem/mem_netbsd.go @@ -47,7 +47,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { ret.Used = ret.Total - ret.Available ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 - // Get buffers from vm.bufmem sysctl + // Get buffers from vm.bufmem sysctl ret.Buffers, err = unix.SysctlUint64("vm.bufmem") if err != nil { return nil, err From 826037fe4be5cef3c1e693e1f909b7330c8b57cd Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Fri, 29 Sep 2023 16:36:44 +0800 Subject: [PATCH 25/66] Fix build_test on amd64 NetBSD --- Makefile | 96 +++++++++++++++++++-------------------- cpu/cpu_netbsd_amd64.go | 9 ++++ disk/disk_netbsd_amd64.go | 45 ++++++++++++++++++ mem/mem_bsd.go | 4 +- 4 files changed, 104 insertions(+), 50 deletions(-) create mode 100644 cpu/cpu_netbsd_amd64.go create mode 100644 disk/disk_netbsd_amd64.go diff --git a/Makefile b/Makefile index 3f5cd8416..a2cb5afef 100644 --- a/Makefile +++ b/Makefile @@ -13,72 +13,72 @@ check: ## Check BUILD_FAIL_PATTERN=grep -v "exec format error" | grep "build failed" && exit 1 || exit 0 build_test: ## test only buildable # Supported operating systems - GOOS=linux GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=loong64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=riscv64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=s390x go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=windows go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=loong64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=riscv64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=s390x go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=windows go120 test ./... | $(BUILD_FAIL_PATTERN) # Operating systems supported for building only (not implemented error if used) - GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=solaris go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=dragonfly go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=netbsd go120 test ./... | $(BUILD_FAIL_PATTERN) # cross build to OpenBSD not worked since process has "C" -# GOOS=openbsd go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=plan9 go test ./... | $(BUILD_FAIL_PATTERN) +# GOOS=openbsd go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=plan9 go120 test ./... | $(BUILD_FAIL_PATTERN) ifeq ($(shell uname -s), Darwin) - CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) endif @echo 'Successfully built on all known operating systems' vet: - GOOS=darwin GOARCH=amd64 go vet ./... - GOOS=darwin GOARCH=arm64 go vet ./... + GOOS=darwin GOARCH=amd64 go120 vet ./... + GOOS=darwin GOARCH=arm64 go120 vet ./... - GOOS=dragonfly GOARCH=amd64 go vet ./... + GOOS=dragonfly GOARCH=amd64 go120 vet ./... - GOOS=freebsd GOARCH=amd64 go vet ./... - GOOS=freebsd GOARCH=386 go vet ./... - GOOS=freebsd GOARCH=arm go vet ./... + GOOS=freebsd GOARCH=amd64 go120 vet ./... + GOOS=freebsd GOARCH=386 go120 vet ./... + GOOS=freebsd GOARCH=arm go120 vet ./... - GOOS=linux GOARCH=386 go vet ./... - GOOS=linux GOARCH=amd64 go vet ./... - GOOS=linux GOARCH=arm64 go vet ./... - GOOS=linux GOARCH=arm go vet ./... - GOOS=linux GOARCH=loong64 go vet ./... - GOOS=linux GOARCH=mips64 go vet ./... - GOOS=linux GOARCH=mips64le go vet ./... - GOOS=linux GOARCH=mips go vet ./... - GOOS=linux GOARCH=mipsle go vet ./... - GOOS=linux GOARCH=ppc64le go vet ./... - GOOS=linux GOARCH=ppc64 go vet ./... - GOOS=linux GOARCH=riscv64 go vet ./... - GOOS=linux GOARCH=s390x go vet ./... + GOOS=linux GOARCH=386 go120 vet ./... + GOOS=linux GOARCH=amd64 go120 vet ./... + GOOS=linux GOARCH=arm64 go120 vet ./... + GOOS=linux GOARCH=arm go120 vet ./... + GOOS=linux GOARCH=loong64 go120 vet ./... + GOOS=linux GOARCH=mips64 go120 vet ./... + GOOS=linux GOARCH=mips64le go120 vet ./... + GOOS=linux GOARCH=mips go120 vet ./... + GOOS=linux GOARCH=mipsle go120 vet ./... + GOOS=linux GOARCH=ppc64le go120 vet ./... + GOOS=linux GOARCH=ppc64 go120 vet ./... + GOOS=linux GOARCH=riscv64 go120 vet ./... + GOOS=linux GOARCH=s390x go120 vet ./... - GOOS=netbsd GOARCH=amd64 go vet ./... + GOOS=netbsd GOARCH=amd64 go120 vet ./... - GOOS=openbsd GOARCH=386 go vet ./... - GOOS=openbsd GOARCH=amd64 go vet ./... + GOOS=openbsd GOARCH=386 go120 vet ./... + GOOS=openbsd GOARCH=amd64 go120 vet ./... - GOOS=solaris GOARCH=amd64 go vet ./... + GOOS=solaris GOARCH=amd64 go120 vet ./... - GOOS=windows GOARCH=amd64 go vet ./... - GOOS=windows GOARCH=386 go vet ./... + GOOS=windows GOARCH=amd64 go120 vet ./... + GOOS=windows GOARCH=386 go120 vet ./... - GOOS=plan9 GOARCH=amd64 go vet ./... - GOOS=plan9 GOARCH=386 go vet ./... + GOOS=plan9 GOARCH=amd64 go120 vet ./... + GOOS=plan9 GOARCH=386 go120 vet ./... macos_test: - CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) init_tools: go get github.com/golang/dep/cmd/dep diff --git a/cpu/cpu_netbsd_amd64.go b/cpu/cpu_netbsd_amd64.go new file mode 100644 index 000000000..57e14528d --- /dev/null +++ b/cpu/cpu_netbsd_amd64.go @@ -0,0 +1,9 @@ +package cpu + +type cpuTimes struct { + User uint64 + Nice uint64 + Sys uint64 + Intr uint64 + Idle uint64 +} diff --git a/disk/disk_netbsd_amd64.go b/disk/disk_netbsd_amd64.go new file mode 100644 index 000000000..c21421cfe --- /dev/null +++ b/disk/disk_netbsd_amd64.go @@ -0,0 +1,45 @@ +//go:build netbsd && amd64 +// +build netbsd,amd64 + +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs types_netbsd.go + +package disk + +const ( + sizeOfStatvfs = 0xce0 +) + +type ( + Statvfs struct { + Flag uint64 + Bsize uint64 + Frsize uint64 + Iosize uint64 + Blocks uint64 + Bfree uint64 + Bavail uint64 + Bresvd uint64 + Files uint64 + Ffree uint64 + Favail uint64 + Fresvd uint64 + Syncreads uint64 + Syncwrites uint64 + Asyncreads uint64 + Asyncwrites uint64 + Fsidx _Ctype_struct___0 + Fsid uint64 + Namemax uint64 + Owner uint32 + Spare [4]uint64 + Fstypename [32]uint8 + Mntonname [1024]uint8 + Mntfromname [1024]uint8 + Mntfromlabel [1024]uint8 + } +) + +type _Ctype_struct___0 struct { + FsidVal [2]int32 +} diff --git a/mem/mem_bsd.go b/mem/mem_bsd.go index ce930fbe4..ef867d742 100644 --- a/mem/mem_bsd.go +++ b/mem/mem_bsd.go @@ -1,5 +1,5 @@ -//go:build freebsd || openbsd -// +build freebsd openbsd +//go:build freebsd || openbsd || netbsd +// +build freebsd openbsd netbsd package mem From 66ee833b9ea2277fafc7878aa0f5db1ed2a592d2 Mon Sep 17 00:00:00 2001 From: Justin Yang Date: Fri, 29 Sep 2023 16:49:18 +0800 Subject: [PATCH 26/66] Makefile: revert back to original one --- Makefile | 96 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index a2cb5afef..3f5cd8416 100644 --- a/Makefile +++ b/Makefile @@ -13,72 +13,72 @@ check: ## Check BUILD_FAIL_PATTERN=grep -v "exec format error" | grep "build failed" && exit 1 || exit 0 build_test: ## test only buildable # Supported operating systems - GOOS=linux GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=loong64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=riscv64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=linux GOARCH=s390x go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=amd64 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=386 go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd GOARCH=arm64 go120 test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=windows go120 test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=loong64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=riscv64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=s390x go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 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=solaris go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=dragonfly go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=netbsd go120 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) # cross build to OpenBSD not worked since process has "C" -# GOOS=openbsd go120 test ./... | $(BUILD_FAIL_PATTERN) - GOOS=plan9 go120 test ./... | $(BUILD_FAIL_PATTERN) +# GOOS=openbsd go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=plan9 go test ./... | $(BUILD_FAIL_PATTERN) ifeq ($(shell uname -s), Darwin) - CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) endif @echo 'Successfully built on all known operating systems' vet: - GOOS=darwin GOARCH=amd64 go120 vet ./... - GOOS=darwin GOARCH=arm64 go120 vet ./... + GOOS=darwin GOARCH=amd64 go vet ./... + GOOS=darwin GOARCH=arm64 go vet ./... - GOOS=dragonfly GOARCH=amd64 go120 vet ./... + GOOS=dragonfly GOARCH=amd64 go vet ./... - GOOS=freebsd GOARCH=amd64 go120 vet ./... - GOOS=freebsd GOARCH=386 go120 vet ./... - GOOS=freebsd GOARCH=arm go120 vet ./... + GOOS=freebsd GOARCH=amd64 go vet ./... + GOOS=freebsd GOARCH=386 go vet ./... + GOOS=freebsd GOARCH=arm go vet ./... - GOOS=linux GOARCH=386 go120 vet ./... - GOOS=linux GOARCH=amd64 go120 vet ./... - GOOS=linux GOARCH=arm64 go120 vet ./... - GOOS=linux GOARCH=arm go120 vet ./... - GOOS=linux GOARCH=loong64 go120 vet ./... - GOOS=linux GOARCH=mips64 go120 vet ./... - GOOS=linux GOARCH=mips64le go120 vet ./... - GOOS=linux GOARCH=mips go120 vet ./... - GOOS=linux GOARCH=mipsle go120 vet ./... - GOOS=linux GOARCH=ppc64le go120 vet ./... - GOOS=linux GOARCH=ppc64 go120 vet ./... - GOOS=linux GOARCH=riscv64 go120 vet ./... - GOOS=linux GOARCH=s390x go120 vet ./... + GOOS=linux GOARCH=386 go vet ./... + GOOS=linux GOARCH=amd64 go vet ./... + GOOS=linux GOARCH=arm64 go vet ./... + GOOS=linux GOARCH=arm go vet ./... + GOOS=linux GOARCH=loong64 go vet ./... + GOOS=linux GOARCH=mips64 go vet ./... + GOOS=linux GOARCH=mips64le go vet ./... + GOOS=linux GOARCH=mips go vet ./... + GOOS=linux GOARCH=mipsle go vet ./... + GOOS=linux GOARCH=ppc64le go vet ./... + GOOS=linux GOARCH=ppc64 go vet ./... + GOOS=linux GOARCH=riscv64 go vet ./... + GOOS=linux GOARCH=s390x go vet ./... - GOOS=netbsd GOARCH=amd64 go120 vet ./... + GOOS=netbsd GOARCH=amd64 go vet ./... - GOOS=openbsd GOARCH=386 go120 vet ./... - GOOS=openbsd GOARCH=amd64 go120 vet ./... + GOOS=openbsd GOARCH=386 go vet ./... + GOOS=openbsd GOARCH=amd64 go vet ./... - GOOS=solaris GOARCH=amd64 go120 vet ./... + GOOS=solaris GOARCH=amd64 go vet ./... - GOOS=windows GOARCH=amd64 go120 vet ./... - GOOS=windows GOARCH=386 go120 vet ./... + GOOS=windows GOARCH=amd64 go vet ./... + GOOS=windows GOARCH=386 go vet ./... - GOOS=plan9 GOARCH=amd64 go120 vet ./... - GOOS=plan9 GOARCH=386 go120 vet ./... + GOOS=plan9 GOARCH=amd64 go vet ./... + GOOS=plan9 GOARCH=386 go vet ./... macos_test: - CGO_ENABLED=0 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=1 GOOS=darwin go120 test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) init_tools: go get github.com/golang/dep/cmd/dep From f1405efa25dc1af20f1b9fe2248c5c0647a5010e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:53:20 +0000 Subject: [PATCH 27/66] chore(deps): bump golang.org/x/sys from 0.12.0 to 0.13.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.12.0 to 0.13.0. - [Commits](https://github.com/golang/sys/compare/v0.12.0...v0.13.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 78cc4af5f..e77cc53ea 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tklauser/go-sysconf v0.3.12 github.com/yusufpapurcu/wmi v1.2.3 - golang.org/x/sys v0.12.0 + golang.org/x/sys v0.13.0 ) retract v3.22.11 diff --git a/go.sum b/go.sum index e558c9ce6..26b15ef94 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,8 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 83427f964f30fc677ac1395a0587063bc8a41888 Mon Sep 17 00:00:00 2001 From: shirou Date: Sat, 7 Oct 2023 13:27:39 +0000 Subject: [PATCH 28/66] [process][darwin]: skip process.Nice test if darwin on GitHub Action fix: https://github.com/shirou/gopsutil/issues/1532 --- process/process_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/process/process_test.go b/process/process_test.go index 51f7d9cf6..877992b25 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -227,6 +227,11 @@ func Test_Process_NumCtx(t *testing.T) { func Test_Process_Nice(t *testing.T) { p := testGetProcess() + // https://github.com/shirou/gopsutil/issues/1532 + if os.Getenv("CI") == "true" && runtime.GOOS == "darwin" { + t.Skip("Skip CI") + } + n, err := p.Nice() skipIfNotImplementedErr(t, err) if err != nil { From 33898971563921507479ede96a5a5ec4758128c9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 13:36:11 +0000 Subject: [PATCH 29/66] chore(deps): bump actions/checkout from 4.0.0 to 4.1.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.0.0 to 4.1.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/3df4ab11eba7bda6032a0b82a6bb43b11571feac...8ade135a41bc03ea155e62e844d188df1ea18608) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build_test.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/sbom_generator.yml | 2 +- .github/workflows/shellcheck.yml | 2 +- .github/workflows/test.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index e636b763a..ce5b347eb 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -26,7 +26,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - id: cache-paths run: | echo "::set-output name=cache::$(go env GOCACHE)" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 245f7e983..cd9bfa6e5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: go-version: 1.17 cache: false - name: Checkout repository - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - name: Setup golangci-lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6bdd103ac..c3ea2b96f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,6 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - name: Release run: make release diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index 771a7e1b4..be07dd4d2 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - uses: advanced-security/sbom-generator-action@375dee8e6144d9fd0ec1f5667b4f6fb4faacefed # v0.0.1 id: sbom diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 2c2198f12..c733e20d4 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -8,6 +8,6 @@ jobs: name: Shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - name: Run ShellCheck uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f1f3a7c9..79b0fa070 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - id: go-env run: | echo "::set-output name=cache::$(go env GOCACHE)" From 4b46f2b70cd40834334d484dfdd55456e8caa72f Mon Sep 17 00:00:00 2001 From: shirou Date: Tue, 10 Oct 2023 23:05:52 +0900 Subject: [PATCH 30/66] [host][darwin]: fix Users --- host/host_darwin.go | 3 +++ host/host_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/host/host_darwin.go b/host/host_darwin.go index f045d4f17..873ed4aee 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -64,6 +64,9 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { return ret, err } + // Skip macOS utmpx header part + buf = buf[604:] + u := Utmpx{} entrySize := int(unsafe.Sizeof(u)) count := len(buf) / entrySize diff --git a/host/host_test.go b/host/host_test.go index 17ced6dac..0aa092598 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -89,6 +89,7 @@ func TestUsers(t *testing.T) { if u == empty { t.Errorf("Could not Users %v", v) } + t.Log(u) } } From 2121939c2a7d4c5cd51f624a8f68279b37d8e847 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 01:33:34 +0000 Subject: [PATCH 31/66] chore(deps): bump github.com/google/go-cmp from 0.5.9 to 0.6.0 Bumps [github.com/google/go-cmp](https://github.com/google/go-cmp) from 0.5.9 to 0.6.0. - [Release notes](https://github.com/google/go-cmp/releases) - [Commits](https://github.com/google/go-cmp/compare/v0.5.9...v0.6.0) --- updated-dependencies: - dependency-name: github.com/google/go-cmp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index e77cc53ea..0ff9d48fa 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/shirou/gopsutil/v3 go 1.15 require ( - github.com/google/go-cmp v0.5.9 + github.com/google/go-cmp v0.6.0 github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c github.com/shoenig/go-m1cpu v0.1.6 diff --git a/go.sum b/go.sum index 26b15ef94..92b9ffbd6 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= From be90da9b839fb24182f037c16973d3cb69907615 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 01:30:37 +0000 Subject: [PATCH 32/66] chore(deps): bump actions/checkout from 4.1.0 to 4.1.1 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/8ade135a41bc03ea155e62e844d188df1ea18608...b4ffde65f46336ab88eb53be808477a3936bae11) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/build_test.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/sbom_generator.yml | 2 +- .github/workflows/shellcheck.yml | 2 +- .github/workflows/test.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index ce5b347eb..987a2370d 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -26,7 +26,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - id: cache-paths run: | echo "::set-output name=cache::$(go env GOCACHE)" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cd9bfa6e5..8075ff04a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: go-version: 1.17 cache: false - name: Checkout repository - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Setup golangci-lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c3ea2b96f..dd4701037 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,6 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Release run: make release diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index be07dd4d2..1e03853b3 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: advanced-security/sbom-generator-action@375dee8e6144d9fd0ec1f5667b4f6fb4faacefed # v0.0.1 id: sbom diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index c733e20d4..3c83dfd38 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -8,6 +8,6 @@ jobs: name: Shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Run ShellCheck uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 79b0fa070..b11534621 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - id: go-env run: | echo "::set-output name=cache::$(go env GOCACHE)" From a1eedcae8efd7fdd16406bfc68b8214c7b62e1b1 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 30 Oct 2023 08:32:36 +0100 Subject: [PATCH 33/66] fix(linux): validate cpu fields length before accessing index --- cpu/cpu_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index b5a20e366..da467e2dd 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -309,7 +309,7 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { func parseStatLine(line string) (*TimesStat, error) { fields := strings.Fields(line) - if len(fields) == 0 { + if len(fields) < 8 { return nil, errors.New("stat does not contain cpu info") } From ac63a5690eb6b08cb0451e23a18ffcd82734379e Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 30 Oct 2023 08:39:26 +0100 Subject: [PATCH 34/66] fix(windows): remove log statement --- load/load_windows.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/load/load_windows.go b/load/load_windows.go index 8f53efae3..5241dfaab 100644 --- a/load/load_windows.go +++ b/load/load_windows.go @@ -5,7 +5,6 @@ package load import ( "context" - "log" "math" "sync" "time" @@ -37,7 +36,6 @@ func loadAvgGoroutine(ctx context.Context) { counter, err := common.ProcessorQueueLengthCounter() if err != nil || counter == nil { - log.Printf("unexpected processor queue length counter error, %v\n", err) return } From 807d46607893f9dd42a0d60b0bfbc154295bcae9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 01:27:06 +0000 Subject: [PATCH 35/66] chore(deps): bump golang.org/x/sys from 0.13.0 to 0.14.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.13.0 to 0.14.0. - [Commits](https://github.com/golang/sys/compare/v0.13.0...v0.14.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0ff9d48fa..0263c559b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tklauser/go-sysconf v0.3.12 github.com/yusufpapurcu/wmi v1.2.3 - golang.org/x/sys v0.13.0 + golang.org/x/sys v0.14.0 ) retract v3.22.11 diff --git a/go.sum b/go.sum index 92b9ffbd6..9d2dbca2a 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From a8418dfd73098a842e15bc2747dfcd25c9aadac0 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Thu, 9 Nov 2023 18:19:10 -0500 Subject: [PATCH 36/66] feat: use lsof for net_connections on FreeBSD Use net.ConnectionsPidWithContext on FreeBSD, similarly to how it is done on Darwin. This uses common.CallLsofWithContext underneath the hood, which will use lsof under the hood, if available. Tested on FreeBSD 13.2-RELEASE Signed-off-by: Chris Gianelloni --- README.md | 2 +- process/process_freebsd.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 78751d72f..2cbdc71a3 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ Some code is ported from Ohai. Many thanks. |users |x |x |x |x |x | | | |pids |x |x |x |x |x | | | |pid\_exists |x |x |x |x |x | | | -|net\_connections |x | |x |x | | | | +|net\_connections |x |x |x |x | | | | |net\_protocols |x | | | | | | | |net\_if\_addrs | | | | | | | | |net\_if\_stats | | | | | | | | diff --git a/process/process_freebsd.go b/process/process_freebsd.go index 85134b7ee..40b10e14f 100644 --- a/process/process_freebsd.go +++ b/process/process_freebsd.go @@ -286,11 +286,11 @@ func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) { } func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error) { - return nil, common.ErrNotImplementedError + return net.ConnectionsPidWithContext(ctx, "all", p.Pid) } func (p *Process) ConnectionsMaxWithContext(ctx context.Context, max int) ([]net.ConnectionStat, error) { - return nil, common.ErrNotImplementedError + return net.ConnectionsPidMaxWithContext(ctx, "all", p.Pid, max) } func ProcessesWithContext(ctx context.Context) ([]*Process, error) { From e1bb8db88f3f55da94347e75dfb7468ee24d4a2d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 28 Nov 2023 01:29:38 +0000 Subject: [PATCH 37/66] chore(deps): bump golang.org/x/sys from 0.14.0 to 0.15.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.14.0 to 0.15.0. - [Commits](https://github.com/golang/sys/compare/v0.14.0...v0.15.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0263c559b..cc32d8d6b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tklauser/go-sysconf v0.3.12 github.com/yusufpapurcu/wmi v1.2.3 - golang.org/x/sys v0.14.0 + golang.org/x/sys v0.15.0 ) retract v3.22.11 diff --git a/go.sum b/go.sum index 9d2dbca2a..091d94127 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 4086e97048d70778622cfc02c3008b78509ed1dd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Dec 2023 01:29:04 +0000 Subject: [PATCH 38/66] chore(deps): bump actions/labeler from 4.3.0 to 5.0.0 Bumps [actions/labeler](https://github.com/actions/labeler) from 4.3.0 to 5.0.0. - [Release notes](https://github.com/actions/labeler/releases) - [Commits](https://github.com/actions/labeler/compare/ac9175f8a1f3625fd0d4fb234536d26811351594...8558fd74291d67161a8a78ce36a881fa63b766a9) --- updated-dependencies: - dependency-name: actions/labeler dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 5626060c8..7614b3279 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -12,6 +12,6 @@ jobs: pull-requests: write # for actions/labeler to add labels to PRs runs-on: ubuntu-latest steps: - - uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 # v4.3.0 + - uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" From 9dd090e1b085be022383275496843b18c74c8c6d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 7 Dec 2023 01:28:30 +0000 Subject: [PATCH 39/66] chore(deps): bump actions/setup-go from 4.1.0 to 5.0.0 Bumps [actions/setup-go](https://github.com/actions/setup-go) from 4.1.0 to 5.0.0. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/93397bea11091df50f3d7e59dc26a7711a8bcfbe...0c52d547c9bc32b1aa3301fd7a9cb496313a4491) --- updated-dependencies: - dependency-name: actions/setup-go dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build_test.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 987a2370d..12589491a 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Install Go - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: go-version: ${{ matrix.go-version }} - name: Checkout code diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8075ff04a..216558905 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Setup go - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: go-version: 1.17 cache: false diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b11534621..876b9f4ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: go-version: ${{ matrix.go-version }} - name: Checkout code From 0de2d14a7cf2eb281f06a4bcae7c0e79407fac22 Mon Sep 17 00:00:00 2001 From: Xie Weineng Date: Wed, 13 Dec 2023 09:54:52 +0800 Subject: [PATCH 40/66] add deepin and uos distro --- host/host_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/host/host_linux.go b/host/host_linux.go index f9d7995e7..b64432229 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -212,6 +212,12 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil } else if lsb.ID == `"Cumulus Linux"` { platform = "cumuluslinux" version = lsb.Release + } else if lsb.ID == "uos" { + platform = "uos" + version = lsb.Release + } else if lsb.ID == "Deepin" { + platform = "Deepin" + version = lsb.Release } else { if common.PathExistsWithContents("/usr/bin/raspi-config") { platform = "raspbian" @@ -289,7 +295,7 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil platform = strings.Trim(platform, `"`) switch platform { - case "debian", "ubuntu", "linuxmint", "raspbian", "Kylin", "cumuluslinux": + case "debian", "ubuntu", "linuxmint", "raspbian", "Kylin", "cumuluslinux", "uos", "Deepin": family = "debian" case "fedora": family = "fedora" From b9cb0e2f30c802c632053703507ecc59d9ae17f6 Mon Sep 17 00:00:00 2001 From: shirou Date: Sat, 16 Dec 2023 12:24:10 +0900 Subject: [PATCH 41/66] Revert "chore(deps): bump actions/labeler from 4.3.0 to 5.0.0" --- .github/workflows/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index 7614b3279..5626060c8 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -12,6 +12,6 @@ jobs: pull-requests: write # for actions/labeler to add labels to PRs runs-on: ubuntu-latest steps: - - uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0 + - uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 # v4.3.0 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" From 5ce87a61133b1f0a3508591dde9f6104dea799ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Dec 2023 03:42:22 +0000 Subject: [PATCH 42/66] chore(deps): bump actions/upload-artifact from 3.1.3 to 4.0.0 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.3 to 4.0.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/a8a3f3ad30e3422c9c7b888a15615d19a852ae32...c7d193f32edcb7bfad88892161225aeda64e9392) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sbom_generator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index 1e03853b3..008629c10 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -19,7 +19,7 @@ jobs: id: sbom env: GITHUB_TOKEN: ${{ github.token }} - - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 with: path: ${{steps.sbom.outputs.fileName }} name: "SBOM" From 362fa4b9c4058915c41458e68fd0ac297f2625cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 21 Dec 2023 09:51:14 +0200 Subject: [PATCH 43/66] Avoid repeated regexp compilations --- cpu/cpu_solaris.go | 5 +++-- disk/disk_solaris.go | 5 +++-- host/host_linux.go | 13 ++++++++++--- net/net_solaris.go | 5 +++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cpu/cpu_solaris.go b/cpu/cpu_solaris.go index f828c843e..4231ad168 100644 --- a/cpu/cpu_solaris.go +++ b/cpu/cpu_solaris.go @@ -36,6 +36,8 @@ func Times(percpu bool) ([]TimesStat, error) { return TimesWithContext(context.Background(), percpu) } +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 { @@ -47,9 +49,8 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { kern := make(map[float64]float64) iowt := make(map[float64]float64) // swap := make(map[float64]float64) - re := regexp.MustCompile(`[:\s]+`) for _, line := range strings.Split(string(kstatSysOut), "\n") { - fields := re.Split(line, -1) + fields := kstatSplit.Split(line, -1) if fields[0] != "cpu_stat" { continue } diff --git a/disk/disk_solaris.go b/disk/disk_solaris.go index 934d651ff..5d6ea8653 100644 --- a/disk/disk_solaris.go +++ b/disk/disk_solaris.go @@ -83,6 +83,8 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro return ret, err } +var kstatSplit = regexp.MustCompile(`[:\s]+`) + func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) { var issolaris bool if runtime.GOOS == "illumos" { @@ -107,7 +109,6 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC writesarr := make(map[string]uint64) rtimearr := make(map[string]uint64) wtimearr := make(map[string]uint64) - re := regexp.MustCompile(`[:\s]+`) // in case the name is "/dev/sda1", then convert to "sda1" for i, name := range names { @@ -115,7 +116,7 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC } for _, line := range lines { - fields := re.Split(line, -1) + fields := kstatSplit.Split(line, -1) if len(fields) == 0 { continue } diff --git a/host/host_linux.go b/host/host_linux.go index b64432229..0618a6967 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -339,13 +339,15 @@ func getSlackwareVersion(contents []string) string { return c } +var redhatishReleaseMatch = regexp.MustCompile(`release (\w[\d.]*)`) + func getRedhatishVersion(contents []string) string { c := strings.ToLower(strings.Join(contents, "")) if strings.Contains(c, "rawhide") { return "rawhide" } - if matches := regexp.MustCompile(`release (\w[\d.]*)`).FindStringSubmatch(c); matches != nil { + if matches := redhatishReleaseMatch.FindStringSubmatch(c); matches != nil { return matches[1] } return "" @@ -362,12 +364,17 @@ func getRedhatishPlatform(contents []string) string { return f[0] } +var ( + suseVersionMatch = regexp.MustCompile(`VERSION = ([\d.]+)`) + susePatchLevelMatch = regexp.MustCompile(`PATCHLEVEL = (\d+)`) +) + func getSuseVersion(contents []string) string { version := "" for _, line := range contents { - if matches := regexp.MustCompile(`VERSION = ([\d.]+)`).FindStringSubmatch(line); matches != nil { + if matches := suseVersionMatch.FindStringSubmatch(line); matches != nil { version = matches[1] - } else if matches := regexp.MustCompile(`PATCHLEVEL = ([\d]+)`).FindStringSubmatch(line); matches != nil { + } else if matches = susePatchLevelMatch.FindStringSubmatch(line); matches != nil { version = version + "." + matches[1] } } diff --git a/net/net_solaris.go b/net/net_solaris.go index 7f1f5c86f..79d8ac30e 100644 --- a/net/net_solaris.go +++ b/net/net_solaris.go @@ -23,6 +23,8 @@ func IOCounters(pernic bool) ([]IOCountersStat, error) { return IOCountersWithContext(context.Background(), pernic) } +var kstatSplit = regexp.MustCompile(`[:\s]+`) + func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat, error) { // collect all the net class's links with below statistics filterstr := "/^(?!vnic)/::phys:/^rbytes64$|^ipackets64$|^idrops64$|^ierrors$|^obytes64$|^opackets64$|^odrops64$|^oerrors$/" @@ -47,9 +49,8 @@ func IOCountersWithContext(ctx context.Context, pernic bool) ([]IOCountersStat, odrops64arr := make(map[string]uint64) oerrorsarr := make(map[string]uint64) - re := regexp.MustCompile(`[:\s]+`) for _, line := range lines { - fields := re.Split(line, -1) + fields := kstatSplit.Split(line, -1) interfaceName := fields[0] instance := fields[1] switch fields[3] { From 11bc5b3970859642148dbd0fa3157c4945498a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 21 Dec 2023 09:59:41 +0200 Subject: [PATCH 44/66] Avoid some uses of regexps --- cpu/cpu_aix_nocgo.go | 11 ++++------- disk/disk_aix_nocgo.go | 3 +-- mem/mem_aix_nocgo.go | 7 ++----- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/cpu/cpu_aix_nocgo.go b/cpu/cpu_aix_nocgo.go index 1a291532a..a77b4dbb7 100644 --- a/cpu/cpu_aix_nocgo.go +++ b/cpu/cpu_aix_nocgo.go @@ -5,15 +5,12 @@ package cpu import ( "context" - "regexp" "strconv" "strings" "github.com/shirou/gopsutil/v3/internal/common" ) -var whiteSpaces = regexp.MustCompile(`\s+`) - func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { if percpu { return []TimesStat{}, common.ErrNotImplementedError @@ -28,8 +25,8 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) { } ret := TimesStat{CPU: "cpu-total"} - h := whiteSpaces.Split(lines[len(lines)-3], -1) // headers - v := whiteSpaces.Split(lines[len(lines)-2], -1) // values + h := strings.Fields(lines[len(lines)-3]) // headers + v := strings.Fields(lines[len(lines)-2]) // values for i, header := range h { if t, err := strconv.ParseFloat(v[i], 64); err == nil { switch header { @@ -58,14 +55,14 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) { ret := InfoStat{} for _, line := range strings.Split(string(out), "\n") { if strings.HasPrefix(line, "Number Of Processors:") { - p := whiteSpaces.Split(line, 4) + p := strings.Fields(line) if len(p) > 3 { if t, err := strconv.ParseUint(p[3], 10, 64); err == nil { ret.Cores = int32(t) } } } else if strings.HasPrefix(line, "Processor Clock Speed:") { - p := whiteSpaces.Split(line, 5) + p := strings.Fields(line) if len(p) > 4 { if t, err := strconv.ParseFloat(p[3], 64); err == nil { switch strings.ToUpper(p[4]) { diff --git a/disk/disk_aix_nocgo.go b/disk/disk_aix_nocgo.go index 4f93c7522..17e2b9c84 100644 --- a/disk/disk_aix_nocgo.go +++ b/disk/disk_aix_nocgo.go @@ -12,7 +12,6 @@ import ( "golang.org/x/sys/unix" ) -var whiteSpaces = regexp.MustCompile(`\s+`) var startBlank = regexp.MustCompile(`^\s+`) var ignoreFSType = map[string]bool{"procfs": true} @@ -60,7 +59,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro if startBlank.MatchString(line) { line = "localhost" + line } - p := whiteSpaces.Split(lines[idx], 6) + p := strings.Fields(lines[idx]) if len(p) < 5 || ignoreFSType[p[colidx["vfs"]]] { continue } diff --git a/mem/mem_aix_nocgo.go b/mem/mem_aix_nocgo.go index fc9e49222..cc6a76d2f 100644 --- a/mem/mem_aix_nocgo.go +++ b/mem/mem_aix_nocgo.go @@ -5,15 +5,12 @@ package mem import ( "context" - "regexp" "strconv" "strings" "github.com/shirou/gopsutil/v3/internal/common" ) -var whiteSpaces = regexp.MustCompile(`\s+`) - func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) { vmem, swap, err := callSVMon(ctx) if err != nil { @@ -49,7 +46,7 @@ func callSVMon(ctx context.Context) (*VirtualMemoryStat, *SwapMemoryStat, error) swap := &SwapMemoryStat{} for _, line := range strings.Split(string(out), "\n") { if strings.HasPrefix(line, "memory") { - p := whiteSpaces.Split(line, 7) + p := strings.Fields(line) if len(p) > 2 { if t, err := strconv.ParseUint(p[1], 10, 64); err == nil { vmem.Total = t * pagesize @@ -65,7 +62,7 @@ func callSVMon(ctx context.Context) (*VirtualMemoryStat, *SwapMemoryStat, error) } } } else if strings.HasPrefix(line, "pg space") { - p := whiteSpaces.Split(line, 4) + p := strings.Fields(line) if len(p) > 3 { if t, err := strconv.ParseUint(p[2], 10, 64); err == nil { swap.Total = t * pagesize From adaeba09d9ed5b0a95d0cf7656034d8873565ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 25 Dec 2023 12:06:43 +0200 Subject: [PATCH 45/66] feat(disk): look for filesystem labels from udev on Linux --- disk/disk_linux.go | 59 ++++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/disk/disk_linux.go b/disk/disk_linux.go index c06516c6c..d96109fa7 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -5,7 +5,6 @@ package disk import ( "bufio" - "bytes" "context" "errors" "fmt" @@ -485,25 +484,35 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC return ret, nil } -func SerialNumberWithContext(ctx context.Context, name string) (string, error) { - var stat unix.Stat_t - err := unix.Stat(name, &stat) - if err != nil { - return "", err - } - major := unix.Major(uint64(stat.Rdev)) - minor := unix.Minor(uint64(stat.Rdev)) - - // Try to get the serial from udev data +func udevData(ctx context.Context, major uint32, minor uint32, name string) (string, error) { udevDataPath := common.HostRunWithContext(ctx, fmt.Sprintf("udev/data/b%d:%d", major, minor)) - if udevdata, err := os.ReadFile(udevDataPath); err == nil { - scanner := bufio.NewScanner(bytes.NewReader(udevdata)) + if f, err := os.Open(udevDataPath); err == nil { + defer f.Close() + scanner := bufio.NewScanner(f) for scanner.Scan() { - values := strings.Split(scanner.Text(), "=") - if len(values) == 2 && values[0] == "E:ID_SERIAL" { + values := strings.SplitN(scanner.Text(), "=", 3) + if len(values) == 2 && values[0] == name { return values[1], nil } } + return "", scanner.Err() + } else if !os.IsNotExist(err) { + return "", err + } + return "", nil +} + +func SerialNumberWithContext(ctx context.Context, name string) (string, error) { + var stat unix.Stat_t + if err := unix.Stat(name, &stat); err != nil { + return "", err + } + major := unix.Major(stat.Rdev) + minor := unix.Minor(stat.Rdev) + + sserial, _ := udevData(ctx, major, minor, "E:ID_SERIAL") + if sserial != "" { + return sserial, nil } // Try to get the serial from sysfs, look at the disk device (minor 0) directly @@ -520,16 +529,26 @@ func SerialNumberWithContext(ctx context.Context, name string) (string, error) { func LabelWithContext(ctx context.Context, name string) (string, error) { // Try label based on devicemapper name dmname_filename := common.HostSysWithContext(ctx, fmt.Sprintf("block/%s/dm/name", name)) - - if !common.PathExists(dmname_filename) { - return "", nil + // Could errors.Join errs with Go >= 1.20 + if common.PathExists(dmname_filename) { + dmname, err := os.ReadFile(dmname_filename) + if err == nil { + return strings.TrimSpace(string(dmname)), nil + } + } + // Try udev data + var stat unix.Stat_t + if err := unix.Stat(common.HostDevWithContext(ctx, name), &stat); err != nil { + return "", err } + major := unix.Major(stat.Rdev) + minor := unix.Minor(stat.Rdev) - dmname, err := os.ReadFile(dmname_filename) + label, err := udevData(ctx, major, minor, "E:ID_FS_LABEL") if err != nil { return "", err } - return strings.TrimSpace(string(dmname)), nil + return label, nil } func getFsType(stat unix.Statfs_t) string { From ce11e9ca5f434eb1f2c0c468df2b2a369a332f33 Mon Sep 17 00:00:00 2001 From: shirou Date: Mon, 1 Jan 2024 22:07:23 +0900 Subject: [PATCH 46/66] [linux][disk]: fix Rdev cast --- disk/disk_linux.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/disk/disk_linux.go b/disk/disk_linux.go index d96109fa7..ada9f9e76 100644 --- a/disk/disk_linux.go +++ b/disk/disk_linux.go @@ -507,8 +507,8 @@ func SerialNumberWithContext(ctx context.Context, name string) (string, error) { if err := unix.Stat(name, &stat); err != nil { return "", err } - major := unix.Major(stat.Rdev) - minor := unix.Minor(stat.Rdev) + major := unix.Major(uint64(stat.Rdev)) + minor := unix.Minor(uint64(stat.Rdev)) sserial, _ := udevData(ctx, major, minor, "E:ID_SERIAL") if sserial != "" { @@ -541,8 +541,8 @@ func LabelWithContext(ctx context.Context, name string) (string, error) { if err := unix.Stat(common.HostDevWithContext(ctx, name), &stat); err != nil { return "", err } - major := unix.Major(stat.Rdev) - minor := unix.Minor(stat.Rdev) + major := unix.Major(uint64(stat.Rdev)) + minor := unix.Minor(uint64(stat.Rdev)) label, err := udevData(ctx, major, minor, "E:ID_FS_LABEL") if err != nil { From 3a36b46e6c1e614c0aacce15875c89d30cf53d3c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Jan 2024 01:59:24 +0000 Subject: [PATCH 47/66] chore(deps): bump golang.org/x/sys from 0.15.0 to 0.16.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.15.0 to 0.16.0. - [Commits](https://github.com/golang/sys/compare/v0.15.0...v0.16.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cc32d8d6b..f28006260 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tklauser/go-sysconf v0.3.12 github.com/yusufpapurcu/wmi v1.2.3 - golang.org/x/sys v0.15.0 + golang.org/x/sys v0.16.0 ) retract v3.22.11 diff --git a/go.sum b/go.sum index 091d94127..d99536176 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 13218ce5b1e1184425fdd11343ebfdfa944bd237 Mon Sep 17 00:00:00 2001 From: shirou Date: Wed, 10 Jan 2024 23:08:22 +0900 Subject: [PATCH 48/66] feat: add linux, mips on build test --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 3f5cd8416..864b1f666 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ build_test: ## test only buildable GOOS=linux GOARCH=loong64 go test ./... | $(BUILD_FAIL_PATTERN) GOOS=linux GOARCH=riscv64 go test ./... | $(BUILD_FAIL_PATTERN) GOOS=linux GOARCH=s390x go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=mips go test ./... | $(BUILD_FAIL_PATTERN) GOOS=freebsd GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) GOOS=freebsd GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) GOOS=freebsd GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) From b10acd4894be6dff7faa9bad71e90889c8eb42ec Mon Sep 17 00:00:00 2001 From: shirou Date: Thu, 11 Jan 2024 00:45:21 +0900 Subject: [PATCH 49/66] [host]: add EnableBootTimeCache function --- README.md | 11 +++++++++++ host/host.go | 7 +++++++ host/host_bsd.go | 12 ++++++++---- host/host_linux.go | 2 +- host/host_test.go | 14 ++++++++++++++ host/host_windows.go | 14 +++++++++----- internal/common/common_linux.go | 26 ++++++++++++++++++++++++-- process/process.go | 7 +++++++ process/process_linux.go | 2 +- 9 files changed, 82 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2cbdc71a3..6fe9cc347 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,17 @@ As of v3.23.6, it is now possible to pass a path location using `context`: impor First priority is given to the value set in `context`, then the value from the environment variable, and finally the default location. +### Caching + +As of v3.24.1, it is now possible to cached some values. These values default to false, not cached. + +Be very careful that enabling the cache may cause inconsistencies. For example, if you enable caching of boottime on Linux, be aware that unintended values may be returned if [the boottime is changed by NTP after booted](https://github.com/shirou/gopsutil/issues/1070#issuecomment-842512782). + +- `host` + - EnableBootTimeCache +- `process` + - EnableBootTimeCache + ## Documentation See https://pkg.go.dev/github.com/shirou/gopsutil/v3 or https://godocs.io/github.com/shirou/gopsutil/v3 diff --git a/host/host.go b/host/host.go index c7e84e3a5..ee9486369 100644 --- a/host/host.go +++ b/host/host.go @@ -62,6 +62,13 @@ func (t TemperatureStat) String() string { return string(s) } +var enableBootTimeCache bool + +// EnableBootTimeCache change cache behavior of BootTime. If true, cache BootTime value. Default is false. +func EnableBootTimeCache(enable bool) { + enableBootTimeCache = enable +} + func Info() (*InfoStat, error) { return InfoWithContext(context.Background()) } diff --git a/host/host_bsd.go b/host/host_bsd.go index 67ae900bc..f9a296148 100644 --- a/host/host_bsd.go +++ b/host/host_bsd.go @@ -14,16 +14,20 @@ import ( var cachedBootTime uint64 func BootTimeWithContext(ctx context.Context) (uint64, error) { - t := atomic.LoadUint64(&cachedBootTime) - if t != 0 { - return t, nil + if enableBootTimeCache { + t := atomic.LoadUint64(&cachedBootTime) + if t != 0 { + return t, nil + } } tv, err := unix.SysctlTimeval("kern.boottime") if err != nil { return 0, err } - atomic.StoreUint64(&cachedBootTime, uint64(tv.Sec)) + if enableBootTimeCache { + atomic.StoreUint64(&cachedBootTime, uint64(tv.Sec)) + } return uint64(tv.Sec), nil } diff --git a/host/host_linux.go b/host/host_linux.go index 0618a6967..86044d3d0 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -71,7 +71,7 @@ func numProcs(ctx context.Context) (uint64, error) { } func BootTimeWithContext(ctx context.Context) (uint64, error) { - return common.BootTimeWithContext(ctx) + return common.BootTimeWithContext(ctx, enableBootTimeCache) } func UptimeWithContext(ctx context.Context) (uint64, error) { diff --git a/host/host_test.go b/host/host_test.go index 0aa092598..d3b75859e 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -195,3 +195,17 @@ func TestPlatformInformation(t *testing.T) { t.Logf("PlatformInformation(): %v, %v, %v", platform, family, version) } + +func BenchmarkBootTimeWithCache(b *testing.B) { + EnableBootTimeCache(true) + for i := 0; i < b.N; i++ { + BootTime() + } +} + +func BenchmarkBootTimeWithoutCache(b *testing.B) { + EnableBootTimeCache(false) + for i := 0; i < b.N; i++ { + BootTime() + } +} diff --git a/host/host_windows.go b/host/host_windows.go index 1fe0551b3..b83ad6db1 100644 --- a/host/host_windows.go +++ b/host/host_windows.go @@ -127,16 +127,20 @@ func uptimeMillis() (uint64, error) { var cachedBootTime uint64 func BootTimeWithContext(ctx context.Context) (uint64, error) { - t := atomic.LoadUint64(&cachedBootTime) - if t != 0 { - return t, nil + if enableBootTimeCache { + t := atomic.LoadUint64(&cachedBootTime) + if t != 0 { + return t, nil + } } up, err := uptimeMillis() if err != nil { return 0, err } - t = uint64((time.Duration(timeSinceMillis(up)) * time.Millisecond).Seconds()) - atomic.StoreUint64(&cachedBootTime, t) + t := uint64((time.Duration(timeSinceMillis(up)) * time.Millisecond).Seconds()) + if enableBootTimeCache { + atomic.StoreUint64(&cachedBootTime, t) + } return t, nil } diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index a644687ba..b08cf33ae 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -12,10 +12,14 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "syscall" "time" ) +// 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()) @@ -56,7 +60,14 @@ func NumProcsWithContext(ctx context.Context) (uint64, error) { return cnt, nil } -func BootTimeWithContext(ctx context.Context) (uint64, error) { +func BootTimeWithContext(ctx context.Context, enableCache bool) (uint64, error) { + if enableCache { + t := atomic.LoadUint64(&cachedBootTime) + if t != 0 { + return t, nil + } + } + system, role, err := VirtualizationWithContext(ctx) if err != nil { return 0, err @@ -72,7 +83,13 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { } if useStatFile { - return readBootTimeStat(ctx) + t, err := readBootTimeStat(ctx) + if err != nil { + return 0, err + } + if enableCache { + atomic.StoreUint64(&cachedBootTime, t) + } } filename := HostProcWithContext(ctx, "uptime") @@ -90,6 +107,11 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) { } currentTime := float64(time.Now().UnixNano()) / float64(time.Second) t := currentTime - b + + if enableCache { + atomic.StoreUint64(&cachedBootTime, uint64(t)) + } + return uint64(t), nil } diff --git a/process/process.go b/process/process.go index 1a7fe1b80..1bb27abf8 100644 --- a/process/process.go +++ b/process/process.go @@ -171,6 +171,13 @@ func (p NumCtxSwitchesStat) String() string { return string(s) } +var enableBootTimeCache bool + +// EnableBootTimeCache change cache behavior of BootTime. If true, cache BootTime value. Default is false. +func EnableBootTimeCache(enable bool) { + enableBootTimeCache = enable +} + // Pids returns a slice of process ID list which are running now. func Pids() ([]int32, error) { return PidsWithContext(context.Background()) diff --git a/process/process_linux.go b/process/process_linux.go index f7989cd21..557435b34 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -1071,7 +1071,7 @@ func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (ui Iowait: iotime / float64(clockTicks), } - bootTime, _ := common.BootTimeWithContext(ctx) + bootTime, _ := common.BootTimeWithContext(ctx, enableBootTimeCache) t, err := strconv.ParseUint(fields[22], 10, 64) if err != nil { return 0, 0, nil, 0, 0, 0, nil, err From 15f7946fcb288a213cb59d967bec90793ec704c1 Mon Sep 17 00:00:00 2001 From: Jason Newman Date: Thu, 11 Jan 2024 13:04:15 -0700 Subject: [PATCH 50/66] Windows, read all pids if there are more than 1024 pids. Convert bytes read to number of uint32s that were read. --- process/process_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/process_windows.go b/process/process_windows.go index 14ed0309f..f2053d985 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -253,7 +253,7 @@ func pidsWithContext(ctx context.Context) ([]int32, error) { if err := windows.EnumProcesses(ps, &read); err != nil { return nil, err } - if uint32(len(ps)) == read { // ps buffer was too small to host every results, retry with a bigger one + if uint32(len(ps)) == read/dwordSize { // ps buffer was too small to host every results, retry with a bigger one psSize += 1024 continue } From 2b5830f6f916fc00ecaf3e11addb0a5b09d552ad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 01:12:28 +0000 Subject: [PATCH 51/66] chore(deps): bump actions/cache from 3.3.2 to 3.3.3 Bumps [actions/cache](https://github.com/actions/cache) from 3.3.2 to 3.3.3. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/704facf57e6136b1bc63b828d79edcd491f0ee84...e12d46a63a90f2fae62d114769bbf2a179198b5c) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/build_test.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 12589491a..f7be24fc7 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -32,7 +32,7 @@ jobs: echo "::set-output name=cache::$(go env GOCACHE)" echo "::set-output name=mod-cache::$(go env GOMODCACHE)" - name: Cache go modules - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3.3.3 with: path: | ${{ steps.cache-paths.outputs.cache }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 876b9f4ca..f5eea9d62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: echo "::set-output name=cache::$(go env GOCACHE)" echo "::set-output name=mod-cache::$(go env GOMODCACHE)" - name: Cache go modules - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 + uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3.3.3 with: path: | ${{ steps.go-env.outputs.cache }} From 73f479fdcd28477ac1a25275f824b60a795cc59c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 01:40:04 +0000 Subject: [PATCH 52/66] chore(deps): bump actions/upload-artifact from 4.0.0 to 4.1.0 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.0.0 to 4.1.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/c7d193f32edcb7bfad88892161225aeda64e9392...1eb3cb2b3e0f29609092a73eb033bb759a334595) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/sbom_generator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index 008629c10..c8bbe56b5 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -19,7 +19,7 @@ jobs: id: sbom env: GITHUB_TOKEN: ${{ github.token }} - - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 + - uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0 with: path: ${{steps.sbom.outputs.fileName }} name: "SBOM" From f28a23e3b3332b9f4ea6fa04afbb7ec3fae3126b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Jan 2024 01:10:14 +0000 Subject: [PATCH 53/66] chore(deps): bump actions/cache from 3.3.3 to 4.0.0 Bumps [actions/cache](https://github.com/actions/cache) from 3.3.3 to 4.0.0. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/e12d46a63a90f2fae62d114769bbf2a179198b5c...13aacd865c20de90d75de3b17ebe84f7a17d57d2) --- updated-dependencies: - dependency-name: actions/cache dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/build_test.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index f7be24fc7..1a800a7de 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -32,7 +32,7 @@ jobs: echo "::set-output name=cache::$(go env GOCACHE)" echo "::set-output name=mod-cache::$(go env GOMODCACHE)" - name: Cache go modules - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3.3.3 + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 with: path: | ${{ steps.cache-paths.outputs.cache }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f5eea9d62..1eca993ff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: echo "::set-output name=cache::$(go env GOCACHE)" echo "::set-output name=mod-cache::$(go env GOMODCACHE)" - name: Cache go modules - uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3.3.3 + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 with: path: | ${{ steps.go-env.outputs.cache }} From b0d976c49b50f2d73621222c1adbf7da3563528f Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Thu, 18 Jan 2024 10:21:42 -0800 Subject: [PATCH 54/66] ensure host platform are files and have contents In a containerized deployment, it is common to mount several files from /etc. Within the container, those files will be created regardless if they exist on the host or not. In those instances, the existing code would erroneously return empty platform information. --- host/host_linux.go | 16 ++++++++-------- internal/common/common.go | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/host/host_linux.go b/host/host_linux.go index 86044d3d0..5d4c1a90f 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -229,47 +229,47 @@ func PlatformInformationWithContext(ctx context.Context) (platform string, famil version = contents[0] } } - } else if common.PathExists(common.HostEtcWithContext(ctx, "neokylin-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "neokylin-release")) { contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "neokylin-release")) if err == nil { version = getRedhatishVersion(contents) platform = getRedhatishPlatform(contents) } - } else if common.PathExists(common.HostEtcWithContext(ctx, "redhat-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "redhat-release")) { contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "redhat-release")) if err == nil { version = getRedhatishVersion(contents) platform = getRedhatishPlatform(contents) } - } else if common.PathExists(common.HostEtcWithContext(ctx, "system-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "system-release")) { contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "system-release")) if err == nil { version = getRedhatishVersion(contents) platform = getRedhatishPlatform(contents) } - } else if common.PathExists(common.HostEtcWithContext(ctx, "gentoo-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "gentoo-release")) { platform = "gentoo" contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "gentoo-release")) if err == nil { version = getRedhatishVersion(contents) } - } else if common.PathExists(common.HostEtcWithContext(ctx, "SuSE-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "SuSE-release")) { contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "SuSE-release")) if err == nil { version = getSuseVersion(contents) platform = getSusePlatform(contents) } // TODO: slackware detecion - } else if common.PathExists(common.HostEtcWithContext(ctx, "arch-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "arch-release")) { platform = "arch" version = lsb.Release - } else if common.PathExists(common.HostEtcWithContext(ctx, "alpine-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "alpine-release")) { platform = "alpine" contents, err := common.ReadLines(common.HostEtcWithContext(ctx, "alpine-release")) if err == nil && len(contents) > 0 && contents[0] != "" { version = contents[0] } - } else if common.PathExists(common.HostEtcWithContext(ctx, "os-release")) { + } else if common.PathExistsWithContents(common.HostEtcWithContext(ctx, "os-release")) { p, v, err := common.GetOSReleaseWithContext(ctx) if err == nil { platform = p diff --git a/internal/common/common.go b/internal/common/common.go index 99ed6a58e..5e25e507b 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -343,7 +343,7 @@ func PathExistsWithContents(filename string) bool { if err != nil { return false } - return info.Size() > 4 // at least 4 bytes + return info.Size() > 4 && !info.IsDir() // at least 4 bytes } // GetEnvWithContext retrieves the environment variable key. If it does not exist it returns the default. From d753f78612a0af2d3359375e71f70f337023471a Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Thu, 18 Jan 2024 10:34:34 -0800 Subject: [PATCH 55/66] use VERSION_ID from os-release MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `VERSION_ID` is more appropriate for scripts and other usages, since `VERSION` can contain spaces and codenames from `os-release` manpage: ``` VERSION= A string identifying the operating system version, excluding any OS name information, possibly including a release code name, and suitable for presentation to the user. This field is optional. Examples: "VERSION=17", "VERSION="17 (Beefy Miracle)"". VERSION_ID= A lower-case string (mostly numeric, no spaces or other characters outside of 0–9, a–z, ".", "_" and "-") identifying the operating system version, excluding any OS name information or release code name, and suitable for processing by scripts or usage in generated filenames. This field is optional. Examples: "VERSION_ID=17", "VERSION_ID=11.04". ``` --- internal/common/common_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index b08cf33ae..a429e16a2 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -329,7 +329,7 @@ func GetOSReleaseWithContext(ctx context.Context) (platform string, version stri switch field[0] { case "ID": // use ID for lowercase platform = trimQuotes(field[1]) - case "VERSION": + case "VERSION_ID": version = trimQuotes(field[1]) } } From 61758d5e3cca7cad12a6f9e567c331c9ede0f72a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 01:25:55 +0000 Subject: [PATCH 56/66] chore(deps): bump actions/upload-artifact from 4.1.0 to 4.2.0 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.1.0 to 4.2.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/1eb3cb2b3e0f29609092a73eb033bb759a334595...694cdabd8bdb0f10b2cea11669e1bf5453eed0a6) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/sbom_generator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index c8bbe56b5..082c992af 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -19,7 +19,7 @@ jobs: id: sbom env: GITHUB_TOKEN: ${{ github.token }} - - uses: actions/upload-artifact@1eb3cb2b3e0f29609092a73eb033bb759a334595 # v4.1.0 + - uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0 with: path: ${{steps.sbom.outputs.fileName }} name: "SBOM" From 22413975af47bca4d01c9db47b160857a12db23c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 24 Jan 2024 01:04:27 +0000 Subject: [PATCH 57/66] chore(deps): bump actions/upload-artifact from 4.2.0 to 4.3.0 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.2.0 to 4.3.0. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/694cdabd8bdb0f10b2cea11669e1bf5453eed0a6...26f96dfa697d77e81fd5907df203aa23a56210a8) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/sbom_generator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index 082c992af..581e267c0 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -19,7 +19,7 @@ jobs: id: sbom env: GITHUB_TOKEN: ${{ github.token }} - - uses: actions/upload-artifact@694cdabd8bdb0f10b2cea11669e1bf5453eed0a6 # v4.2.0 + - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0 with: path: ${{steps.sbom.outputs.fileName }} name: "SBOM" From 1a8f96c633e68d23454512278c91e3a3f5f9a92f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 01:51:03 +0000 Subject: [PATCH 58/66] chore(deps): bump actions/upload-artifact from 4.3.0 to 4.3.1 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.0 to 4.3.1. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/26f96dfa697d77e81fd5907df203aa23a56210a8...5d5d22a31266ced268874388b861e4b58bb5c2f3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/sbom_generator.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sbom_generator.yml b/.github/workflows/sbom_generator.yml index 581e267c0..1ec0ae762 100644 --- a/.github/workflows/sbom_generator.yml +++ b/.github/workflows/sbom_generator.yml @@ -19,7 +19,7 @@ jobs: id: sbom env: GITHUB_TOKEN: ${{ github.token }} - - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0 + - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: path: ${{steps.sbom.outputs.fileName }} name: "SBOM" From 4e79582e339df4abbdac8bf48d63d2f4400a8502 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 01:10:01 +0000 Subject: [PATCH 59/66] chore(deps): bump golang.org/x/sys from 0.16.0 to 0.17.0 Bumps [golang.org/x/sys](https://github.com/golang/sys) from 0.16.0 to 0.17.0. - [Commits](https://github.com/golang/sys/compare/v0.16.0...v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f28006260..916e1a1f4 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/stretchr/testify v1.8.4 github.com/tklauser/go-sysconf v0.3.12 github.com/yusufpapurcu/wmi v1.2.3 - golang.org/x/sys v0.16.0 + golang.org/x/sys v0.17.0 ) retract v3.22.11 diff --git a/go.sum b/go.sum index d99536176..4005e10cf 100644 --- a/go.sum +++ b/go.sum @@ -34,8 +34,8 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 44981c6f45e8125ddea0f030243436db6e226ce6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Feb 2024 01:48:05 +0000 Subject: [PATCH 60/66] chore(deps): bump github.com/yusufpapurcu/wmi from 1.2.3 to 1.2.4 Bumps [github.com/yusufpapurcu/wmi](https://github.com/yusufpapurcu/wmi) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/yusufpapurcu/wmi/releases) - [Commits](https://github.com/yusufpapurcu/wmi/compare/v1.2.3...v1.2.4) --- updated-dependencies: - dependency-name: github.com/yusufpapurcu/wmi dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 916e1a1f4..4233d40ac 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/shoenig/go-m1cpu v0.1.6 github.com/stretchr/testify v1.8.4 github.com/tklauser/go-sysconf v0.3.12 - github.com/yusufpapurcu/wmi v1.2.3 + github.com/yusufpapurcu/wmi v1.2.4 golang.org/x/sys v0.17.0 ) diff --git a/go.sum b/go.sum index 4005e10cf..390501b5e 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,8 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= -github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= -github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 27ffa28a0d97df0fde4df6982597d85c06859d78 Mon Sep 17 00:00:00 2001 From: Jonathan Matthew Date: Sun, 11 Feb 2024 16:20:56 +1000 Subject: [PATCH 61/66] add support for OpenBSD/riscv64 --- cpu/cpu_openbsd_riscv64.go | 10 ++ disk/disk_openbsd_riscv64.go | 40 ++++++ host/host_openbsd_riscv64.go | 36 +++++ mem/mem_openbsd_riscv64.go | 38 ++++++ process/process_openbsd_riscv64.go | 204 +++++++++++++++++++++++++++++ 5 files changed, 328 insertions(+) create mode 100644 cpu/cpu_openbsd_riscv64.go create mode 100644 disk/disk_openbsd_riscv64.go create mode 100644 host/host_openbsd_riscv64.go create mode 100644 mem/mem_openbsd_riscv64.go create mode 100644 process/process_openbsd_riscv64.go diff --git a/cpu/cpu_openbsd_riscv64.go b/cpu/cpu_openbsd_riscv64.go new file mode 100644 index 000000000..d659058cd --- /dev/null +++ b/cpu/cpu_openbsd_riscv64.go @@ -0,0 +1,10 @@ +package cpu + +type cpuTimes struct { + User uint64 + Nice uint64 + Sys uint64 + Spin uint64 + Intr uint64 + Idle uint64 +} diff --git a/disk/disk_openbsd_riscv64.go b/disk/disk_openbsd_riscv64.go new file mode 100644 index 000000000..8374b94eb --- /dev/null +++ b/disk/disk_openbsd_riscv64.go @@ -0,0 +1,40 @@ +//go:build openbsd && riscv64 +// +build openbsd,riscv64 + +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs disk/types_openbsd.go + +package disk + +const ( + devstat_NO_DATA = 0x00 + devstat_READ = 0x01 + devstat_WRITE = 0x02 + devstat_FREE = 0x03 +) + +const ( + sizeOfDiskstats = 0x70 +) + +type ( + Diskstats struct { + Name [16]int8 + Busy int32 + Rxfer uint64 + Wxfer uint64 + Seek uint64 + Rbytes uint64 + Wbytes uint64 + Attachtime Timeval + Timestamp Timeval + Time Timeval + } + Timeval struct { + Sec int64 + Usec int64 + } +) + +type Diskstat struct{} +type bintime struct{} diff --git a/host/host_openbsd_riscv64.go b/host/host_openbsd_riscv64.go new file mode 100644 index 000000000..7a123b649 --- /dev/null +++ b/host/host_openbsd_riscv64.go @@ -0,0 +1,36 @@ +//go:build openbsd && riscv64 +// +build openbsd,riscv64 + +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs host/types_openbsd.go + +package host + +const ( + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 + sizeOfUtmp = 0x130 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type ( + Utmp struct { + Line [8]int8 + Name [32]int8 + Host [256]int8 + Time int64 + } + Timeval struct { + Sec int64 + Usec int64 + } +) diff --git a/mem/mem_openbsd_riscv64.go b/mem/mem_openbsd_riscv64.go new file mode 100644 index 000000000..7a7b48038 --- /dev/null +++ b/mem/mem_openbsd_riscv64.go @@ -0,0 +1,38 @@ +//go:build openbsd && riscv64 +// +build openbsd,riscv64 + +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs mem/types_openbsd.go + +package mem + +const ( + CTLVfs = 10 + VfsGeneric = 0 + VfsBcacheStat = 3 +) + +const ( + sizeOfBcachestats = 0x90 +) + +type Bcachestats struct { + Numbufs int64 + Numbufpages int64 + Numdirtypages int64 + Numcleanpages int64 + Pendingwrites int64 + Pendingreads int64 + Numwrites int64 + Numreads int64 + Cachehits int64 + Busymapped int64 + Dmapages int64 + Highpages int64 + Delwribufs int64 + Kvaslots int64 + Avail int64 + Highflips int64 + Highflops int64 + Dmaflips int64 +} diff --git a/process/process_openbsd_riscv64.go b/process/process_openbsd_riscv64.go new file mode 100644 index 000000000..076f095ea --- /dev/null +++ b/process/process_openbsd_riscv64.go @@ -0,0 +1,204 @@ +//go:build openbsd && riscv64 +// +build openbsd,riscv64 + +// Code generated by cmd/cgo -godefs; DO NOT EDIT. +// cgo -godefs process/types_openbsd.go + +package process + +const ( + CTLKern = 1 + KernProc = 66 + KernProcAll = 0 + KernProcPID = 1 + KernProcProc = 8 + KernProcPathname = 12 + KernProcArgs = 55 + KernProcArgv = 1 + KernProcEnv = 3 +) + +const ( + ArgMax = 256 * 1024 +) + +const ( + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 +) + +const ( + sizeOfKinfoVmentry = 0x50 + sizeOfKinfoProc = 0x288 +) + +const ( + SIDL = 1 + SRUN = 2 + SSLEEP = 3 + SSTOP = 4 + SZOMB = 5 + SDEAD = 6 + SONPROC = 7 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int64 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type KinfoProc struct { + Forw uint64 + Back uint64 + Paddr uint64 + Addr uint64 + Fd uint64 + Stats uint64 + Limit uint64 + Vmspace uint64 + Sigacts uint64 + Sess uint64 + Tsess uint64 + Ru uint64 + Eflag int32 + Exitsig int32 + Flag int32 + Pid int32 + Ppid int32 + Sid int32 + X_pgid int32 + Tpgid int32 + Uid uint32 + Ruid uint32 + Gid uint32 + Rgid uint32 + Groups [16]uint32 + Ngroups int16 + Jobc int16 + Tdev uint32 + Estcpu uint32 + Rtime_sec uint32 + Rtime_usec uint32 + Cpticks int32 + Pctcpu uint32 + Swtime uint32 + Slptime uint32 + Schedflags int32 + Uticks uint64 + Sticks uint64 + Iticks uint64 + Tracep uint64 + Traceflag int32 + Holdcnt int32 + Siglist int32 + Sigmask uint32 + Sigignore uint32 + Sigcatch uint32 + Stat int8 + Priority uint8 + Usrpri uint8 + Nice uint8 + Xstat uint16 + Spare uint16 + Comm [24]int8 + Wmesg [8]uint8 + Wchan uint64 + Login [32]uint8 + Vm_rssize int32 + Vm_tsize int32 + Vm_dsize int32 + Vm_ssize int32 + Uvalid int64 + Ustart_sec uint64 + Ustart_usec uint32 + Uutime_sec uint32 + Uutime_usec uint32 + Ustime_sec uint32 + Ustime_usec uint32 + Uru_maxrss uint64 + Uru_ixrss uint64 + Uru_idrss uint64 + Uru_isrss uint64 + Uru_minflt uint64 + Uru_majflt uint64 + Uru_nswap uint64 + Uru_inblock uint64 + Uru_oublock uint64 + Uru_msgsnd uint64 + Uru_msgrcv uint64 + Uru_nsignals uint64 + Uru_nvcsw uint64 + Uru_nivcsw uint64 + Uctime_sec uint32 + Uctime_usec uint32 + Psflags uint32 + Acflag uint32 + Svuid uint32 + Svgid uint32 + Emul [8]uint8 + Rlim_rss_cur uint64 + Cpuid uint64 + Vm_map_size uint64 + Tid int32 + Rtableid uint32 + Pledge uint64 + Name [24]uint8 +} + +type Priority struct{} + +type KinfoVmentry struct { + Start uint64 + End uint64 + Guard uint64 + Fspace uint64 + Fspace_augment uint64 + Offset uint64 + Wired_count int32 + Etype int32 + Protection int32 + Max_protection int32 + Advice int32 + Inheritance int32 + Flags uint8 + Pad_cgo_0 [7]byte +} From 6ccc60519ec242820e0b2dddb0fae18376363ad3 Mon Sep 17 00:00:00 2001 From: Jonathan Matthew Date: Sun, 11 Feb 2024 16:21:34 +1000 Subject: [PATCH 62/66] update list OpenBSD arch list --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fe9cc347..f6e118272 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ can be skipped. - Linux i386/amd64/arm(raspberry pi) - Windows i386/amd64/arm/arm64 - Darwin amd64/arm64 -- OpenBSD amd64 (Thank you @mpfz0r!) +- OpenBSD i386/amd64/armv7/arm64/riscv64 (Thank you @mpfz0r!) - Solaris amd64 (developed and tested on SmartOS/Illumos, Thank you @jen20!) From d0037dd62b71f9f239b56858c8e72d65ff831c7a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Feb 2024 01:54:44 +0000 Subject: [PATCH 63/66] chore(deps): bump golangci/golangci-lint-action from 3.7.0 to 4.0.0 Bumps [golangci/golangci-lint-action](https://github.com/golangci/golangci-lint-action) from 3.7.0 to 4.0.0. - [Release notes](https://github.com/golangci/golangci-lint-action/releases) - [Commits](https://github.com/golangci/golangci-lint-action/compare/3a919529898de77ec3da873e3063ca4b10e7f5cc...3cfe3a4abbb849e10058ce4af15d205b6da42804) --- updated-dependencies: - dependency-name: golangci/golangci-lint-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 216558905..5f03e0148 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -23,7 +23,7 @@ jobs: - name: Checkout repository uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Setup golangci-lint - uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 + uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.0 with: args: --verbose version: latest From d3057c252fe2c12f0b2f62a597d47dddeadcb6e7 Mon Sep 17 00:00:00 2001 From: vlnaum <33950764+vlnaum@users.noreply.github.com> Date: Mon, 19 Feb 2024 16:23:27 +0000 Subject: [PATCH 64/66] cwd support windows doc --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6e118272..fea8e7efd 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ Some code is ported from Ohai. Many thanks. |cmdline |x |x | |x |x | |create\_time |x | | |x |x | |status |x |x |x |x | | -|cwd |x | | |x | | +|cwd |x | | |x |x | |exe |x |x |x | |x | |uids |x |x |x |x | | |gids |x |x |x |x | | From 25c3f409bd30649a00cfdf52a65b267522fb2bc5 Mon Sep 17 00:00:00 2001 From: shirou Date: Wed, 21 Feb 2024 10:06:30 +0000 Subject: [PATCH 65/66] [ci]: add macos-13 and macos-14 on GitHub Action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1eca993ff..85c1f0bcf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false matrix: go-version: ${{fromJson(needs.go-versions.outputs.versions)}} - os: [ubuntu-22.04, ubuntu-20.04, windows-2022, windows-2019, macos-11, macos-12] + os: [ubuntu-22.04, ubuntu-20.04, windows-2022, windows-2019, macos-11, macos-12, macos-13, macos-14] runs-on: ${{ matrix.os }} steps: - name: Install Go From 53fb8caad4bf683e50b5ee73e6bb1fbaafafd314 Mon Sep 17 00:00:00 2001 From: shirou Date: Sat, 24 Feb 2024 01:25:24 +0000 Subject: [PATCH 66/66] [darwin][ci]: skip frequency check on GitHub Action --- cpu/cpu_darwin_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpu/cpu_darwin_test.go b/cpu/cpu_darwin_test.go index 57b3d66ee..a95862369 100644 --- a/cpu/cpu_darwin_test.go +++ b/cpu/cpu_darwin_test.go @@ -4,6 +4,7 @@ package cpu import ( + "os" "testing" "github.com/shoenig/go-m1cpu" @@ -23,7 +24,7 @@ func Test_CpuInfo_AppleSilicon(t *testing.T) { if vv.ModelName == "" { t.Errorf("could not get CPU info: %v", vv) } - if vv.Mhz <= 0 { + if vv.Mhz <= 0 && os.Getenv("CI") != "true" { t.Errorf("could not get frequency of: %s", vv.ModelName) } if vv.Mhz > 6000 {