Skip to content

Commit e65df80

Browse files
author
redanthrax
committed
Merge remote-tracking branch 'upstream/main' into FreeBSD
2 parents 43114f7 + 438814e commit e65df80

38 files changed

+300
-197
lines changed

CHANGELOG.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Replace pkg/errors with Go 1.13 native errors #123.
13+
1214
### Changed
1315

1416
### Deprecated
@@ -17,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1719

1820
### Fixed
1921

22+
## [1.8.1]
23+
24+
### Fixed
25+
26+
- Report OS name as Windows 11 when version is >= 10.0.22000. [#118](https://github.com/elastic/go-sysinfo/issues/118) [#121](https://github.com/elastic/go-sysinfo/pull/121)
27+
2028
## [1.8.0]
2129

2230
### Added
@@ -100,8 +108,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
100108

101109
### Fixed
102110

103-
- Fixed a leak when calling the CommandLineToArgv function. [#51](https://github.com/redanthrax/go-sysinfo/pull/51)
104-
- Fixed a crash when calling the CommandLineToArgv function. [#58](https://github.com/redanthrax/go-sysinfo/pull/58)
111+
- Fixed a leak when calling the CommandLineToArgv function. [#51](https://github.com/elastic/go-sysinfo/pull/51)
112+
- Fixed a crash when calling the CommandLineToArgv function. [#58](https://github.com/elastic/go-sysinfo/pull/58)
105113

106114
## [1.0.1] - 2019-05-08
107115

@@ -129,18 +137,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
129137

130138
- Changed the host containerized check to reduce false positives. [#42](https://github.com/redanthrax/go-sysinfo/pull/42) [#43](https://github.com/redanthrax/go-sysinfo/pull/43)
131139

132-
[Unreleased]: https://github.com/redanthrax/go-sysinfo/compare/v1.8.0...HEAD
133-
[1.8.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.8.0
134-
[1.7.1]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.7.1
135-
[1.7.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.7.0
136-
[1.6.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.6.0
137-
[1.5.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.5.0
138-
[1.4.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.4.0
139-
[1.3.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.3.0
140-
[1.2.1]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.2.1
141-
[1.2.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.2.0
142-
[1.1.1]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.1.0
143-
[1.1.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.1.0
144-
[1.0.2]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.0.2
145-
[1.0.1]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.0.1
146-
[1.0.0]: https://github.com/redanthrax/go-sysinfo/releases/tag/v1.0.0
140+
[Unreleased]: https://github.com/elastic/go-sysinfo/compare/v1.8.1...HEAD
141+
[1.8.1]: https://github.com/elastic/go-sysinfo/releases/tag/v1.8.1
142+
[1.8.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.8.0
143+
[1.7.1]: https://github.com/elastic/go-sysinfo/releases/tag/v1.7.1
144+
[1.7.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.7.0
145+
[1.6.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.6.0
146+
[1.5.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.5.0
147+
[1.4.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.4.0
148+
[1.3.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.3.0
149+
[1.2.1]: https://github.com/elastic/go-sysinfo/releases/tag/v1.2.1
150+
[1.2.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.2.0
151+
[1.1.1]: https://github.com/elastic/go-sysinfo/releases/tag/v1.1.0
152+
[1.1.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.1.0
153+
[1.0.2]: https://github.com/elastic/go-sysinfo/releases/tag/v1.0.2
154+
[1.0.1]: https://github.com/elastic/go-sysinfo/releases/tag/v1.0.1
155+
[1.0.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.0.0

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Elastic go-sysinfo
2-
Copyright 2017-2020 Elasticsearch B.V.
2+
Copyright 2017-2022 Elasticsearch B.V.
33

44
This product includes software developed at
55
Elasticsearch, B.V. (https://www.elastic.co/).

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ go 1.18
55
require (
66
github.com/elastic/go-windows v1.0.1
77
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
8-
github.com/pkg/errors v0.9.1
9-
github.com/prometheus/procfs v0.7.3
10-
github.com/stretchr/testify v1.8.0
11-
golang.org/x/sys v0.0.0-20220627191245-f75cf1eec38b
12-
howett.net/plist v1.0.0
8+
github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0
9+
github.com/stretchr/testify v1.3.0
10+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
11+
howett.net/plist v0.0.0-20181124034731-591f970eefbb
1312
)
1413

1514
require (
16-
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/davecgh/go-spew v1.1.0 // indirect
16+
github.com/pkg/errors v0.8.1 // indirect
1717
github.com/pmezard/go-difflib v1.0.0 // indirect
1818
gopkg.in/yaml.v3 v3.0.1 // indirect
1919
)

internal/registry/registry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package registry
1919

2020
import (
21-
"github.com/pkg/errors"
21+
"fmt"
2222

2323
"github.com/redanthrax/go-sysinfo/types"
2424
)
@@ -41,14 +41,14 @@ type ProcessProvider interface {
4141
func Register(provider interface{}) {
4242
if h, ok := provider.(HostProvider); ok {
4343
if hostProvider != nil {
44-
panic(errors.Errorf("HostProvider already registered: %v", hostProvider))
44+
panic(fmt.Sprintf("HostProvider already registered: %v", hostProvider))
4545
}
4646
hostProvider = h
4747
}
4848

4949
if p, ok := provider.(ProcessProvider); ok {
5050
if processProvider != nil {
51-
panic(errors.Errorf("ProcessProvider already registered: %v", processProvider))
51+
panic(fmt.Sprintf("ProcessProvider already registered: %v", processProvider))
5252
}
5353
processProvider = p
5454
}

providers/aix/boottime_aix_ppc64.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ package aix
2222

2323
import (
2424
"encoding/binary"
25+
"fmt"
2526
"os"
2627
"time"
27-
28-
"github.com/pkg/errors"
2928
)
3029

3130
// utmp can't be used by "encoding/binary" if generated by cgo,
@@ -60,7 +59,7 @@ func bootTime(filename string) (time.Time, error) {
6059
// Get boot time from /etc/utmp
6160
file, err := os.Open(filename)
6261
if err != nil {
63-
return time.Time{}, errors.Wrap(err, "failed to get host uptime: cannot open /etc/utmp")
62+
return time.Time{}, fmt.Errorf("failed to get host uptime: cannot open /etc/utmp: %w", err)
6463
}
6564

6665
defer file.Close()
@@ -76,5 +75,5 @@ func bootTime(filename string) (time.Time, error) {
7675
}
7776
}
7877

79-
return time.Time{}, errors.Wrap(err, "failed to get host uptime: no utmp record")
78+
return time.Time{}, fmt.Errorf("failed to get host uptime: no utmp record: %w", err)
8079
}

providers/aix/host_aix_ppc64.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ package aix
3131
import "C"
3232

3333
import (
34+
"errors"
35+
"fmt"
3436
"os"
3537
"time"
3638

3739
"github.com/joeshaw/multierror"
38-
"github.com/pkg/errors"
3940

4041
"github.com/redanthrax/go-sysinfo/internal/registry"
4142
"github.com/redanthrax/go-sysinfo/providers/shared"
@@ -80,7 +81,7 @@ func (*host) CPUTime() (types.CPUTimes, error) {
8081
cpudata := C.perfstat_cpu_total_t{}
8182

8283
if _, err := C.perfstat_cpu_total(nil, &cpudata, C.sizeof_perfstat_cpu_total_t, 1); err != nil {
83-
return types.CPUTimes{}, errors.Wrap(err, "error while callin perfstat_cpu_total")
84+
return types.CPUTimes{}, fmt.Errorf("error while callin perfstat_cpu_total: %w", err)
8485
}
8586

8687
return types.CPUTimes{
@@ -100,7 +101,7 @@ func (*host) Memory() (*types.HostMemoryInfo, error) {
100101
meminfo := C.perfstat_memory_total_t{}
101102
_, err := C.perfstat_memory_total(nil, &meminfo, C.sizeof_perfstat_memory_total_t, 1)
102103
if err != nil {
103-
return nil, errors.Wrap(err, "perfstat_memory_total failed")
104+
return nil, fmt.Errorf("perfstat_memory_total failed: %w", err)
104105
}
105106

106107
mem.Total = uint64(meminfo.real_total) * pagesize
@@ -137,7 +138,7 @@ type reader struct {
137138

138139
func (r *reader) addErr(err error) bool {
139140
if err != nil {
140-
if errors.Cause(err) != types.ErrNotImplemented {
141+
if !errors.Is(err, types.ErrNotImplemented) {
141142
r.errs = append(r.errs, err)
142143
}
143144
return true

providers/aix/kernel_aix_ppc64.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,26 @@ package aix
2626
import "C"
2727

2828
import (
29+
"fmt"
2930
"strconv"
30-
31-
"github.com/pkg/errors"
3231
)
3332

3433
var oslevel string
3534

3635
func getKernelVersion() (int, int, error) {
3736
name := C.struct_utsname{}
3837
if _, err := C.uname(&name); err != nil {
39-
return 0, 0, errors.Wrap(err, "kernel version: uname")
38+
return 0, 0, fmt.Errorf("kernel version: uname: %w", err)
4039
}
4140

4241
version, err := strconv.Atoi(C.GoString(&name.version[0]))
4342
if err != nil {
44-
return 0, 0, errors.Wrap(err, "parsing kernel version")
43+
return 0, 0, fmt.Errorf("parsing kernel version: %w", err)
4544
}
4645

4746
release, err := strconv.Atoi(C.GoString(&name.release[0]))
4847
if err != nil {
49-
return 0, 0, errors.Wrap(err, "parsing kernel release")
48+
return 0, 0, fmt.Errorf("parsing kernel release: %w", err)
5049
}
5150
return version, release, nil
5251
}

providers/aix/machineid_aix_ppc64.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ package aix
2525
*/
2626
import "C"
2727

28-
import (
29-
"github.com/pkg/errors"
30-
)
28+
import "fmt"
3129

3230
// MachineID returns the id of the machine
3331
func MachineID() (string, error) {
3432
name := C.struct_utsname{}
3533
if _, err := C.uname(&name); err != nil {
36-
return "", errors.Wrap(err, "machine id")
34+
return "", fmt.Errorf("machine id: %w", err)
3735
}
3836
return C.GoString(&name.machine[0]), nil
3937
}

providers/aix/os_aix_ppc64.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
package aix
2222

2323
import (
24+
"fmt"
2425
"io/ioutil"
2526
"strconv"
2627
"strings"
2728

28-
"github.com/pkg/errors"
29-
30-
"github.com/redanthrax/go-sysinfo/types"
29+
"github.com/elastic/go-sysinfo/types"
3130
)
3231

3332
// OperatingSystem returns information of the host operating system
@@ -44,7 +43,7 @@ func getOSInfo() (*types.OSInfo, error) {
4443
// Retrieve build version from "/proc/version".
4544
procVersion, err := ioutil.ReadFile("/proc/version")
4645
if err != nil {
47-
return nil, errors.Wrap(err, "failed to get OS info: cannot open /proc/version")
46+
return nil, fmt.Errorf("failed to get OS info: cannot open /proc/version: %w", err)
4847
}
4948
build := strings.SplitN(string(procVersion), "\n", 4)[2]
5049

providers/aix/process_aix_ppc64.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import "C"
3333
import (
3434
"bytes"
3535
"encoding/binary"
36+
"errors"
37+
"fmt"
3638
"io"
3739
"io/ioutil"
3840
"os"
@@ -43,9 +45,7 @@ import (
4345
"time"
4446
"unsafe"
4547

46-
"github.com/pkg/errors"
47-
48-
"github.com/redanthrax/go-sysinfo/types"
48+
"github.com/elastic/go-sysinfo/types"
4949
)
5050

5151
// Processes returns a list of all actives processes.
@@ -54,7 +54,7 @@ func (aixSystem) Processes() ([]types.Process, error) {
5454
// getprocs which will also retrieve kernel threads.
5555
files, err := ioutil.ReadDir("/proc")
5656
if err != nil {
57-
return nil, errors.Wrap(err, "error while reading /proc")
57+
return nil, fmt.Errorf("error while reading /proc: %w", err)
5858
}
5959

6060
processes := make([]types.Process, 0, len(files))
@@ -121,7 +121,7 @@ func (p *process) Info() (types.ProcessInfo, error) {
121121
err = syscall.ESRCH
122122
}
123123
if err != nil {
124-
return types.ProcessInfo{}, errors.Wrap(err, "error while calling getprocs")
124+
return types.ProcessInfo{}, fmt.Errorf("error while calling getprocs: %w", err)
125125
}
126126

127127
p.info.PPID = int(info.pi_ppid)
@@ -133,7 +133,7 @@ func (p *process) Info() (types.ProcessInfo, error) {
133133
buf := make([]byte, 8192)
134134
var args []string
135135
if _, err := C.getargs(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, (*C.char)(&buf[0]), 8192); err != nil {
136-
return types.ProcessInfo{}, errors.Wrap(err, "error while calling getargs")
136+
return types.ProcessInfo{}, fmt.Errorf("error while calling getargs: %w", err)
137137
}
138138

139139
bbuf := bytes.NewBuffer(buf)
@@ -143,7 +143,7 @@ func (p *process) Info() (types.ProcessInfo, error) {
143143
break
144144
}
145145
if err != nil {
146-
return types.ProcessInfo{}, errors.Wrap(err, "error while reading arguments")
146+
return types.ProcessInfo{}, fmt.Errorf("error while reading arguments: %w", err)
147147
}
148148

149149
args = append(args, string(chop(arg)))
@@ -183,7 +183,7 @@ func (p *process) Info() (types.ProcessInfo, error) {
183183
cwd, err := os.Readlink("/proc/" + strconv.Itoa(p.pid) + "/cwd")
184184
if err != nil {
185185
if !os.IsNotExist(err) {
186-
return types.ProcessInfo{}, errors.Wrapf(err, "error while reading /proc/%s/cwd", strconv.Itoa(p.pid))
186+
return types.ProcessInfo{}, fmt.Errorf("error while reading /proc/%s/cwd: %w", strconv.Itoa(p.pid), err)
187187
}
188188
}
189189

@@ -205,7 +205,7 @@ func (p *process) Environment() (map[string]string, error) {
205205
info.pi_pid = C.pid_t(p.pid)
206206

207207
if _, err := C.getevars(unsafe.Pointer(&info), C.sizeof_struct_procsinfo64, (*C.char)(&buf[0]), 8192); err != nil {
208-
return nil, errors.Wrap(err, "error while calling getevars")
208+
return nil, fmt.Errorf("error while calling getevars: %w", err)
209209
}
210210

211211
bbuf := bytes.NewBuffer(buf)
@@ -218,12 +218,12 @@ func (p *process) Environment() (map[string]string, error) {
218218
break
219219
}
220220
if err != nil {
221-
return nil, errors.Wrap(err, "error while calling getevars")
221+
return nil, fmt.Errorf("error while calling getevars: %w", err)
222222
}
223223

224224
pair := bytes.SplitN(chop(line), delim, 2)
225225
if len(pair) != 2 {
226-
return nil, errors.Wrap(err, "error reading process environment")
226+
return nil, errors.New("error reading process environment")
227227
}
228228
p.env[string(pair[0])] = string(pair[1])
229229
}
@@ -260,7 +260,7 @@ func (p *process) Memory() (types.MemoryInfo, error) {
260260
err = syscall.ESRCH
261261
}
262262
if err != nil {
263-
return types.MemoryInfo{}, errors.Wrap(err, "error while calling getprocs")
263+
return types.MemoryInfo{}, fmt.Errorf("error while calling getprocs: %w", err)
264264
}
265265

266266
mem.Resident = uint64(info.pi_drss+info.pi_trss) * pagesize
@@ -286,12 +286,12 @@ func (p *process) decodeProcfsFile(name string, data interface{}) error {
286286

287287
file, err := os.Open(fileName)
288288
if err != nil {
289-
return errors.Wrapf(err, "error while opening %s", fileName)
289+
return fmt.Errorf("error while opening %s: %w", fileName, err)
290290
}
291291
defer file.Close()
292292

293293
if err := binary.Read(file, binary.BigEndian, data); err != nil {
294-
return errors.Wrapf(err, "error while decoding %s", fileName)
294+
return fmt.Errorf("error while decoding %s: %w", fileName, err)
295295
}
296296

297297
return nil

0 commit comments

Comments
 (0)