Commit Graph

415 Commits

Author SHA1 Message Date
Chris Gianelloni a8418dfd73 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 <wolf31o2@blinklabs.io>
2023-11-09 18:19:10 -05:00
shirou 83427f964f [process][darwin]: skip process.Nice test if darwin on GitHub Action
fix: https://github.com/shirou/gopsutil/issues/1532
2023-10-07 13:27:39 +00:00
Matthieu MOREL c806740b34
ci(lint): ensure io/ioutil replacement (#1525)
* ci(lint): enure ioutil replacement

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

* 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 <matthieu.morel35@gmail.com>
2023-09-12 21:14:04 +09:00
shirou 0665cafa1b chore: replace deprecated ioutil package to os and io 2023-09-08 17:05:14 +00:00
shirou febdeab871 chore: change CIRCLECI environment variable to CI. 2023-08-30 14:07:47 +00:00
Antoine Toulme 54c31d884d
Revert "test results"
This reverts commit ae119d36b8.
2023-08-27 10:01:46 -07:00
Antoine Toulme ae119d36b8 test results 2023-08-27 09:58:08 -07:00
Antoine Toulme 6fff1c0e99
proper benchmark 2023-08-27 09:42:51 -07:00
Antoine Toulme ca71a6db3c
lint 2023-08-25 14:38:11 -07:00
Antoine Toulme a48fd71137
Revert "send results"
This reverts commit a7a94986fb.
2023-08-25 14:33:37 -07:00
Antoine Toulme a7a94986fb send results 2023-08-25 14:18:48 -07:00
Antoine Toulme 4bc9e37b0f
faster file read 2023-08-25 13:54:26 -07:00
Lomanic 8b96d2e9e2 [process][posix] Realign process.Name() with python psutil to return same value on python3 scripts processes
e2c79a1 started to blindly set the process name to the full path (instead of the basename) of the cmdline exectuable
if the process name from the process comm was truncated on linux. Python psutil never did that, and this is just wrong
for python (or any executable interpreted script) where the process name is not the interpreter binary but the script
itself.

A new test to check process name value against psutil value is added here, which would hopefully catch any potential
future changes in psutil.

Reverts #542

Fixes #1485
2023-07-09 00:43:24 +02:00
Lomanic c0f3eb1dfb [process] Remove all noisy and useless Test_AllProcesses_X tests
These tests can't fail more than their invidiual counterparts and produce an incredibly verbose output
2023-07-01 14:44:04 +02:00
Antoine Toulme b712e59295 fix more linting reports 2023-06-03 14:17:16 -07:00
Antoine Toulme 38b94668ea allow to pass context values to override environment variables 2023-06-02 01:31:05 -07:00
cui fliter 9aa4e7a744 fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-05-09 16:42:07 +08:00
Eng Zer Jun 0439039205
refactor(process): compare error with `errors.Is`
Starting from Go 1.13, `errors.Is` is the preferable way to compare
error equality [1].

[1]: https://go.dev/blog/go1.13-errors

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-04-24 15:00:01 +08:00
Matthieu MOREL 1fb1e3e3e6 ci(lint): correct gci linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2023-04-04 18:07:22 +00:00
Donal Hurley cf25de7460 Add support for getting process exe in FreeBSD 2023-03-09 11:46:40 +00:00
shirou 852f455217 fix lint 2023-02-12 09:24:52 +00:00
Eng Zer Jun 37894e9b28
test: use `T.Setenv` to set env vars in tests
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-12-20 13:13:01 +08:00
Lomanic 980cc82c08 [process][windows] Retrieve process name as basename of executable
We align ourself with psutil
8e4099d9f0/psutil/_pswindows.py (L749-L759)

Benchmarks show vast improvements

    go test -run=BenchmarkProcessName -bench=BenchmarkProcessName ./process
    goos: windows
    goarch: amd64
    pkg: github.com/shirou/gopsutil/v3/process
    cpu: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
    BenchmarkProcessName-4               180           6564033 ns/op
    BenchmarkProcessNameViaExe-4       22111             51153 ns/op
    PASS
    ok      github.com/shirou/gopsutil/v3/process   3.914s

Fixes #1368
2022-10-22 21:43:23 +02:00
Lomanic bd4529a7cc [process][windows] Refator a tiny bit is32BitProcess() function to be more idiomatic Go 2022-10-22 19:09:36 +02:00
Brandon Duffany 38064605a8 Fix memory leaks in darwin_cgo 2022-10-04 14:35:52 -04:00
tienthanh1993 6bc339626b
fix(process,windows): compare len(cwd) to an incorrect value
process/process_windows.go#L411 len(cwd) need compare to userProcParams.CurrentDirectoryPathNameLength instead of userProcParams.CurrentDirectoryPathAddress
2022-08-25 20:09:21 +07:00
Tobias Klauser c76712b8da
host, process: delete darwin/386 code
The darwin/386 port was dropped in Go 1.15 and the imported version of
golang.org/x/sys also no longer supports the port. This module requires
at least Go 1.15 per go.mod, so it no longer builds on darwin/386
anyway.
2022-07-28 13:01:59 +02:00
shirou e2ae339eaf fix(process,linux): remove trailing multiple \x00 2022-07-12 09:49:23 +00:00
Lomanic 7501387fc1 [process][windows] Use WaitForSingleObject with a 0 delay in PidExistsWithContext
Reference https://stackoverflow.com/a/6493793

Fixes #1298
2022-05-16 23:33:53 +02:00
Martin Reindl 1d89235f34 host: add support for OpenBSD/armv7 2022-04-15 21:11:36 +02:00
shirou 7de7d48ef6
Merge pull request #1267 from easyops-cn/master
fix(process): fix OpenFilesWithContext panic problem
2022-03-05 11:22:21 +09:00
Ville Skyttä f7e1f36418 refactor: remove unnecessary exec.LookPath calls
Executing the command does the lookup if needed and returns the same
error when not found, no need to do it separately.
2022-03-04 18:56:33 +02:00
paul 3cd259698f fix(process): fix OpenFilesWithContext panic problem 2022-03-04 16:14:22 +08:00
shirou 9a667f1188
Merge pull request #1210 from mmorel-35/master
enable contextcheck linter
2022-02-24 20:44:35 +09:00
Rishabh Arya 0bf4299250 Add support for reading smaps_rollup 2022-02-17 20:12:19 +00:00
Sergey Kozlov 8ae037c8a1 Fix typing issues in createTimeWithContext on Freebsd/i386
Before change:
```
$ GOOS=freebsd GOARCH=386 go build ./process
process\process_freebsd.go:118:26: cannot use k.Start.Sec * 1000 + k.Start.Usec / 1000 (type int32) as type int64 in return argument
```
2022-02-08 21:03:48 +00:00
Matthieu MOREL b0469a470b
Merge branch 'master' into master 2022-02-01 19:28:26 +01:00
Ville Skyttä 1e56c6f421 Spelling and grammar fixes 2022-01-30 22:48:09 +02:00
shirou 50cad0760c
Merge branch 'master' into refactor/parentwithcontext-ppidwithcontext 2022-01-30 10:47:00 +09:00
shirou 34e74aaccb
Merge pull request #1229 from PierreF/darwin-drop-callps-step2
Darwin drop callps step2
2022-01-30 10:38:10 +09:00
Matthieu MOREL 8ba220d241 enable contextcheck linter 2022-01-24 09:26:50 +01:00
Ville Skyttä 0306525d78 [process] implement ParentWithContext using PpidWithContext
Removes need for redundant ParentWithContext implementations. It had led
to it being unsupported on FreeBSD and OpenBSD even though
PpidWithContext was available for them, and different implementations
for getting the parent info used in ParentWithContext and
PpidWithContext on Darwin and Linux.
2022-01-22 18:27:52 +02:00
shirou 35fbe38505 [process][linux] Fix error handling on Children.
If pgrep returns error, `CallPgrepWithContext` always returns empty pids. So this Children always returns ErrorNoChildren. This PR fixes that handling.
2022-01-15 14:09:57 +00:00
Pierre Fersing 43e50e1d7d Reduce call to ps for process package on darwin 2022-01-14 09:41:54 +01:00
Pierre Fersing 60eae48e6a Drop test for Darwin Pids() 2022-01-13 13:27:05 +01:00
Pierre Fersing b9b3dbe67a Avoid ps command and use KProc on MacOS 2022-01-13 11:57:04 +01:00
shirou dcac9d9b01 [process][windows] fix release handle 2022-01-06 22:16:57 +09:00
shirou fdfd273cf0
Merge pull request #1218 from scop/feat/freebsd-process-start
[process][freebsd] implement createTimeWithContext
2022-01-06 22:04:54 +09:00
Lomanic 01cf95a92d [process][windows] Fix #1216 fix compilation on arm/arm64
go build ./... with GOARCH=arm64 is otherwise failing with the following:

process\process_windows.go:412:11: undefined: readProcessMemory
process\process_windows.go:425:11: undefined: readProcessMemory
process\process_windows.go:896:32: undefined: PROCESS_MEMORY_COUNTERS
process\process_windows.go:897:10: undefined: PROCESS_MEMORY_COUNTERS
process\process_windows.go:910:50: undefined: PROCESS_MEMORY_COUNTERS
process\process_windows.go:950:21: undefined: queryPebAddress
process\process_windows.go:955:9: undefined: readProcessMemory
process\process_windows.go:961:8: undefined: readProcessMemory
process\process_windows.go:969:21: undefined: queryPebAddress
process\process_windows.go:974:9: undefined: readProcessMemory
process\process_windows.go:974:9: too many errors
2022-01-05 01:09:23 +01:00
Ville Skyttä 41e2595443 [process][freebsd] implement createTimeWithContext 2022-01-05 01:20:20 +02:00