Commit Graph

393 Commits (30aa851d39042d02f6972b27b6c02e9f596dc5ae)

Author SHA1 Message Date
Max Altgelt d07af877ef
chore: Drop PROCESS_QUERY_INFORMATION support
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.
shirou b27be3812b [v2][process][linux] port 1112 to v2.
This port includes only code. test is not included.
Max Altgelt 9ad6c64727
fix: Remove superfluous EnvironWithContext definitions
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>
Max Altgelt 5f61473ffd
fix: Correct UNICODE_STRING64 definition
Correct the UNICODE_STRING64 definition. The length is only
16 bits, followed by 16 bit max length and 32 bit padding.
Max Altgelt 73fee847e6
chore: add tests
Add simple tests to verify that environment variables are read.
Max Altgelt b02b92e16b
feat: Add support for environment variable read
Add support (for Linux and Windows for now) for reading the
environment variables of a process, with a similar syntax to
os.Environ().
For Windows, this includes some refactoring for clean access to the
RTL_USER_PROCESS_PARAMETERS structure which points to the command
line and the environment variables.
shirou d87e955d79
Merge pull request #1090 from MyaLongmire/windows_name_fix
simplify mutex usage
shirou daec167ba2
Merge pull request #1087 from ivandeex/openbsd-process-nocgo
process, v3/process (openbsd):  remove remaining CGO bits from CmdlineSliceWithContext
Mya cb512c8500 simplify mutex usage
shirou 7ea8062810
Merge pull request #1083 from elmeyer/fix-processes-smartos
process, v3/process (Linux): fix Processes in SmartOS lx containers
Ivan Andreev d6e0932b96 Remove CGO bits from process_openbsd.go (also v3)
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>
Lars Meyer e42c52cb35 [process][linux] add test for missing iotime in SmartOS lx containers
Lars Meyer 0ab3954dc4 [process][linux] fix Processes in SmartOS lx containers
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.
Tobias Klauser 611c8b576e process, v3/process: use SC_CLK_TCK sysconf value instead of hard-coding clock ticks
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.
shirou 9bd4bc70ae [process][linux] fix 1056 test and copy to v2
shirou 7ffa844cd5
Merge pull request #1075 from scop/feat/improve-solaris-exe
[process][solaris] improve Exe portability
Lomanic 8775def991
Merge pull request #1072 from djs55/externproc-arm64
process: fix ExternProc on Apple Silicon / Darwin arm64
David Scott 0a281012db process: change all pointers to uint64 in ExternProc for darwin arm64
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>
Ville Skyttä f43138a3ff [process][solaris] improve Exe portability
Resolving from path/a.out seems more portable than from execname.
shirou 9a5f86a30e
Merge pull request #1065 from scop/feat/solaris-process-some
Basic Solaris process support
Ville Skyttä e35ae34dce [process][solaris] process basics
Ville Skyttä b7d717ba80 [process][posix] use os.Lstat for symlink check
unix.DT_LNK is not portable; per glibc docs it's a BSD extension. It is
not available e.g. in Solaris.
https://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html#index-DT_005fLNK

As a side effect, fixes incorrect equality comparison against
Stat_t.Mode, a bitmask.
shirou 2fa855f295 add MockEnv as more generic function.
shirou abacce2177 [process][linux] add test to parse fillFromStatus
shirou 008b5a41ef
Merge pull request #1060 from heptalium/master
Fix fillFromStatusWithContext() on systems with 128 bit signal masks.
Lomanic c7a38de76e
Merge pull request #1052 from gballet/openbsd-arm-support
add support for OpenBSD arm64
Jens Meißner fc074343f8
[process][linux] Fix fillFromStatusWithContext() on systems with 128 bit signal masks.
shirou 79048ccbfa
Merge pull request #1035 from jblesener/fixmacosspaces
Fix spaces on long process names for MacOS
John Blesener 07797b12d3
Make cmdNameWithContext lower-case to avoid exporting it
Signed-off-by: John Blesener <jblesener@reactivelabs.com>
Guillaume Ballet 992d17af94 add support for OpenBSD arm64
Lomanic 0881c11a9a [process][posix] Fix #1049 check if procfs is mounted before checking if pid exists there
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
Lomanic 62d8920abb [process][windows] Fix #714 call OpenProcess with PROCESS_QUERY_INFORMATION on WinXP
shirou a5834f48c4
Merge pull request #1033 from eriknordmark/erik-reduce-memory
Avoid returning slice into buffer from Readfile
John Blesener e8b2bea47f
Fix spaces on long process names for MacOS
eriknordmark 0e13743b77 Avoid returning slice into buffer from Readfile
Signed-off-by: eriknordmark <erik@zededa.com>
Paweł Zuzelski 17c03b3b2d Clarify the godoc of the Children function.
The previous godoc string was slightly confusing and only described information that can be deduced from the function signature.
shirou a9a6146c93 [process] fix MemoryInfo comment. remove Swap
fixes #1012
Rishabh Arya 5b1d8ecae7 fix smap parser
Lomanic 995610e109 [process][windows] Fix Nice() test expecting Unix values
Lomanic 5641beec4c [process][darwin] Fix Parent() when lsof returns warnings
Same as #867, the error being:
error strconv.Atoi: parsing "      Output information may be incomplete.": invalid syntax
Lomanic 148a662b06 [process][darwin] Remove Groups() as it's non-functional
Lomanic f810d518bb
Merge pull request #962 from AtakanColak/fix-ppid-race-961
Fix Windows Ppid Cache Race Condition
Antoine Jacoutot 013cd610f5 process: unbreak build on OpenBSD
Match FreeBSD code to prevent:
process_openbsd.go:230:10: cannot use k.Groups (type [16]uint32) as type []int32 in return argument
AtakanColak 13602a3824 fix ppid cache race condition #964
Sergey Vinogradov 065e609cbf Refactor "process" package
* All context-less wrapping functions (the ones without WithContext
suffix) were moved into process.go since they all are the same.
* Call context is now passed to all underlying functions in
*WithContext() functions.
* All common *BSD bits were moved to process_bsd.go.
* Process.Tgid() method lacked a WithContext counterpart, so
Process.TgidWithContext() was added for uniformity.
* NewProcessWithContext() function was added since NewProcess() is
used a lot throughout the module, and there is no way to pass a
context to it.

This is a part of #761 effort.
shirou b94f262e7d
Merge pull request #949 from boogie-byte/vet-target
Add "vet" target to the Makefile
shirou fe68b86b08
Merge pull request #948 from AtakanColak/windows-cache-ppid
Cache Process Parent ID in Windows
Sergey Vinogradov 8ff2ab3187 Add "vet" target to the Makefile
Making the "vet" target will run "go vet ./..." for each supported
GOOS.

Also, some of the warnings produced by go 1.15 vet were mitigated.
Lomanic eaa34817d0 [process] Add benchmarks for New(), Name() Ppid()
run only them with: go test -bench=. -run=xxx github.com/shirou/gopsutil/process
Atakan Çolak 7cc8d3f711 cache ppid in windows
Lomanic 64ba9d03cd [process] Properly test Ppid() against known value
Lomanic c9c40215f5 [process][darwin] Fix #925 properly with unix.SysctlRaw("kern.proc.pid", PID)
Lomanic 8784f48735
Merge pull request #940 from Lomanic/issue985
[process][darwin] Fix #925 remove references to removed const unix.SYS___SYSCTL from x/sys/unix
Lomanic e1082dabb6 [process][darwin] Fix #925 remove references to removed const unix.SYS___SYSCTL from x/sys/unix
More like a workaround, wanted to port process.getKProcWithContext() to use unix.SysctlRaw() to get rid of exec calls to ps
in the same time but didn't have time.
Lomanic 8a625ec054 [host][process][darwin] Go-fmt code from mktypes.sh from #917
Lomanic 2e4fcbb8c4
Merge pull request #917 from amdprophet/darwin-arm64
Add support for Darwin/ARM64
ninedraft 34df4904f6 use cancelable sleep in cpu.PercentWithContext and process.Process.PercentWithContext
Lomanic e1925b853e
Merge pull request #935 from Lomanic/issue900
[linux] Fix #900, skip or fix failing tests in docker
Lomanic 1b3e0c6643 [linux] Fix #900, skip or fix failing tests in docker
TestGetProcInodesAll: create a server so there are some opened inodes
TestUsers: skip if Users is empty, because of an empty /var/run/utmp
Test_Process_Groups: skip if Groups is empty
TestConnectionsMax: skip on CI, not only CircleCI
Lomanic 84afaae670 [host][mem][process][openbsd] Add 386 const and types definitions
Continuation of #721, this type using mktypes.sh that I didn't know at the time.
Weirdly, `go tool cgo -godefs` doesn't produce propery go-fmt-ed code, had to do run go-fmt manually afterwards.
Simon Thoby 04a6f81e9f fix an invalid shift in windows processes name UTF16 conversion
Justin Kolberg 53ffb0cece Add support for Darwin/ARM64
Signed-off-by: Justin Kolberg <amd.prophet@gmail.com>
shirou 7e94bb8bcd
Merge pull request #775 from TakayukiBGoto/add_additional_gids_support
[Process] Implement Groups() to get additional gids.
shirou bbcb80cd3f
Merge pull request #891 from tribes/master
[process][windows] implement suspending and resuming with ntdll library
Tyler Davis 8d28f1b305 Clean up boolean condition
Tyler Davis 9473d01f0f Fix MemoryMaps on ARM
ARM has some tab characters in smaps instead of spaces, hence switching to strings.Fields instead of strings.Split which handles splitting on all whitespace instead of just spaces.
Merwan Ouddane f459195bc0 [process][windows] implement suspending and resuming with ntdll library
Lomanic 8f969117ab [process][darwin][nocgo] Fix #867 iterate on every lines returned by lsof to handle potential warnings
Mauro Leggieri 7783e1d58e Added retrieval of OS platform to determine better a process platform.
Mauro Leggieri 00957cfedc Fixed slow command line retrieval on Windows
JuanLeon Lahoz 426b5148e3 Provide an estimation of Iowait metric per process
Lomanic 27358e8a2f
Merge pull request #840 from devopsext/correct_exit_code_pid_existence
[process][linux] make process.IsRunning() return nil error if process does not exist
Ilya Prudnikov f3598686cb Correct returned error (set to nil) in case process is not exist
shirou a9d510e7e5
Merge pull request #821 from devopsext/process_check_pid_exnistense_fix
Fix check pid existence when running in different process namespace (container)
Ilya Prudnikov 8dec3d81f3 Fix check pid existence when running in different process namespace (container)
Lomanic 1c8ddacaf7 [process][windows] Use win32 API in process.IOCounters() instead of slow WMI call #250
MashaSamoylova 88d9e38aca Change access right in GetProcessTimes call
shirou 61b5bf8cef
Merge branch 'master' into use-x-sys-windows
Dmitri Goutnik 270f6afc22
Add support for freebsd/arm64
Lomanic f586a57353
Merge pull request #796 from Lomanic/issue795
[process][darwin][openbsd][freebsd] Fix #795 don't truncate process names to 16 characters
Lomanic 8e4dde660a [process][darwin] Fix Test_Process_Status and Status returning more than status letter
TakayukiB Goto 7306b38ac6 [Process] Remove Groups() from process_openbsd
Lomanic e7090ba9fc [process] Fix Test_Children test regression because of some other running test
Lomanic 1fcea92f73 [process] Skip if not implemented Test_IsRunning (for openbsd)
Lomanic e4f087a4af [process] Test process.Name() with long names #795
Lomanic 4f0e679e35 [process][darwin][openbsd][freebsd] Fix #795 don't truncate process names to 16 characters
Lomanic e34a731c69 [process] Fix #773 remove data race in NewProcess
Reproduction case https://github.com/shirou/gopsutil/issues/773#issuecomment-554723678
Tobias Klauser a61c905252 Use golang.org/x/windows functions instead of github.com/shirou/w32
All functions used from github.com/shirou/w32 are also available from
golang.org/x/sys/windows which is already used in other places. Convert
the remaining usages to use the functions from x/sys/windows.
TakayukiB Goto 9c6cedb822 [Process] Fix typo
TakayukiB Goto a93796494b [Process] Define the Groups() only once
Laurent Sesques b3cfb9abc3 Revert "[process] Fix #599 cap percent values returned by *Percent() between 0 and 100"
This reverts commit f4e23559a2.
Fixes #755
TakayukiB Goto f55f202e81 [Process] Implement Groups() to get additional gids.
Lomanic 547679f88e [process] Fix #760 implement IsRunning by checking process with same PID has same CreateTime as current process
shirou 84e6215770
Merge pull request #759 from Lomanic/windows-process-connections
[process][windows] Implement Connections() using net.ConnectionsPid()
shirou 56ed89e0cf
Merge pull request #758 from Lomanic/process-cleanup
[process] Propagate context internally on linux and improve tests
Lomanic f5131dc333 [process][windows] Implement Connections() using net.ConnectionsPid()
Lomanic f09ba75b25 [process] Skip tests on non-implemented platforms #446 and fix Kill/Children tests on windows
Lomanic 6f5b1dbee7 [darwin][process] Add cgo implementation of Exe() from PR #243
Original from ppanyukov 4473014098
Lomanic f49203762b [process] Fix Connections() test with goroutines listening/connecting on TCP
Lomanic 36aa63bdd1 [process][linux] Propagate context internally