other OSs), and fails consistently if run with `go test -times=N`
On inspection, Go closes TCP connections when they go out of scope and
are garbage collected. I've re-written Test_Connections() to explicitly
close connectections once the test has finished. This has the other
benefit of closing gracefully, which means the -times argument should
work.
I've also removed the t.Skip() calls inside goroutines as they are
unsupported.
PROCESS_QUERY_INFORMATION was used for compatibility reasons with
Windows XP / Server 2003. Both are no longer supported in Golang
and haven't been for a while (since Go 1.11). It should be safe
to drop this flag. PROCESS_QUERY_LIMITED_INFORMATION supports
PPL process such as LSASS, which are not queryable without this
change.
Since Darwin / FreeBSD / OpenBSD all use process_bsd.go, remove
the duplicated "not implemented" EnvironWithContext definitions
from their custom go files.
Signed-off-by: Max Altgelt <max.altgelt@nextron-systems.com>
Prior to this commit CGO was used in OpenBSD implementation of
Process.CmdlineSliceWithContext() for parsing the "kern.proc.args"
sysctl output. It requires some pointer arithmetics and raw pointer
dereferencing.
Having CGO in the "process" module prevents it from being go vet'ted
on any platform other than OpenBSD. In order to overcome this
limitation, the sysctl output parsing was reimplemented without raw
pointer deferencing. The resulting code might be slightly slower
than the original one, but it is cleaner and safer.
Since this fix allows go vet with GOOS=openbsd to run without any
issues on all platforms, openbsd entries were also added to the "vet"
Makefile target.
Co-authored-by: Sergey Vinogradov <cbrpnk@gmail.com>
In Linux containers running in LX Branded Zones on SmartOS (potentially
other Solaris-based OSes with LX Branded Zones),
fillFromTIDStatWithContext panics as the delayacct_blkio_ticks field is
not present and thus results in an out-of-bounds slice access.
Check the slice length before and only attempt to parse the
delayacct_blkio_ticks field if there is an appropriate number of fields.
The github.com/tklauser/go-sysconf package is already a dependency used
in the cpu and v3/cpu packages to determine clock ticks using
`sysconf.Sysconf(sysconf.SC_CLK_TCK)`, see #1036. Use the same in
packages process and v3/process as well instead of hard-coding clock
ticks to 100.
This is the arm64 version of the change in
20c3ddbfe5
Before this patch:
```
dave@m1 process % GO111MODULE=off CGO_ENABLED=0 go test
--- FAIL: Test_Process_Name (0.00s)
process_test.go:312: invalid Exe
--- FAIL: Test_Process_Long_Name_With_Spaces (0.22s)
process_test.go:357: loooong name with spaces.go.exe !=
--- FAIL: Test_Process_Long_Name (0.22s)
process_test.go:402: looooooooooooooooooooong.go.exe !=
--- FAIL: Test_Username (0.00s)
process_test.go:593:
Error Trace: process_test.go:593
Error: Not equal:
expected: "dave"
actual : "root"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-dave
+root
Test: Test_Username
process_test.go:595: root
FAIL
exit status 1
FAIL github.com/shirou/gopsutil/process 9.955s
```
After this patch:
```
dave@m1 process % GO111MODULE=off CGO_ENABLED=0 go test
PASS
ok github.com/shirou/gopsutil/process 9.784s
dave@m1 process % GO111MODULE=off CGO_ENABLED=1 go test
PASS
ok github.com/shirou/gopsutil/process 3.180s
```
Signed-off-by: David Scott <dave@recoil.org>
Benchmark before this change (process.NewProcess() calls process.PidExistsWithContext()
internally)
go test -bench=BenchmarkNewProcess github.com/shirou/gopsutil/process
goos: linux
goarch: amd64
pkg: github.com/shirou/gopsutil/process
BenchmarkNewProcess-4 14722 78751 ns/op
PASS
ok github.com/shirou/gopsutil/process 3.685s
Benchmark with this change applied
go test -bench=BenchmarkNewProcess github.com/shirou/gopsutil/process
goos: linux
goarch: amd64
pkg: github.com/shirou/gopsutil/process
BenchmarkNewProcess-4 14835 80180 ns/op
PASS
ok github.com/shirou/gopsutil/process 3.761s