Commit Graph

350 Commits

Author SHA1 Message Date
shirou 703175c3fb [v2][process][windows] fix Kill causes DuplicateHandle error 2021-10-17 09:59:20 +00:00
shirou 7be7e7807f [process] extend maxElapsedTime on process_test 2021-09-30 07:47:05 +00:00
shirou 0d0659af18
Merge pull request #1122 from secDre4mer/master
chore: Drop PROCESS_QUERY_INFORMATION support
2021-08-28 12:33:15 +09:00
Tom Barker 9248140c98 Wait for server connection to be established before checking
connections.
2021-08-23 16:30:51 -04:00
Tom Barker bc4661937d Minor cleanups motivated by staticcheck warnings. 2021-08-19 10:43:06 -04:00
Tom Barker 5ce887df8f Make sure that Test_AllProcesses_cmdLine doesn't ignore failures. 2021-08-19 10:43:06 -04:00
Tom Barker 34cdfa258b Test_Connections currently fails intermittently on Linux (and maybe
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.
2021-08-19 10:40:27 -04:00
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.
2021-08-19 15:41:50 +02:00
shirou b27be3812b [v2][process][linux] port 1112 to v2.
This port includes only code. test is not included.
2021-08-14 08:22:57 +00:00
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>
2021-07-19 09:22:20 +02:00
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.
2021-07-19 07:34:42 +02:00
Max Altgelt 73fee847e6
chore: add tests
Add simple tests to verify that environment variables are read.
2021-07-13 16:38:49 +02:00
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.
2021-07-13 15:11:29 +02:00
shirou d87e955d79
Merge pull request #1090 from MyaLongmire/windows_name_fix
simplify mutex usage
2021-06-29 20:59:19 +09:00
shirou daec167ba2
Merge pull request #1087 from ivandeex/openbsd-process-nocgo
process, v3/process (openbsd):  remove remaining CGO bits from CmdlineSliceWithContext
2021-06-28 22:38:03 +09:00
Mya cb512c8500 simplify mutex usage 2021-06-24 15:18:00 -07:00
shirou 7ea8062810
Merge pull request #1083 from elmeyer/fix-processes-smartos
process, v3/process (Linux): fix Processes in SmartOS lx containers
2021-06-20 00:30:09 +09:00
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>
2021-06-11 03:38:46 +03:00
Lars Meyer e42c52cb35 [process][linux] add test for missing iotime in SmartOS lx containers 2021-06-04 10:38:28 +02:00
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.
2021-06-04 10:15:21 +02:00
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.
2021-06-02 14:11:11 +02:00
shirou 9bd4bc70ae [process][linux] fix 1056 test and copy to v2 2021-05-29 21:31:50 +09:00
shirou 7ffa844cd5
Merge pull request #1075 from scop/feat/improve-solaris-exe
[process][solaris] improve Exe portability
2021-05-29 13:27:54 +09:00
Lomanic 8775def991
Merge pull request #1072 from djs55/externproc-arm64
process: fix ExternProc on Apple Silicon / Darwin arm64
2021-05-27 20:57:52 +02:00
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>
2021-05-24 11:04:41 +01:00
Ville Skyttä f43138a3ff [process][solaris] improve Exe portability
Resolving from path/a.out seems more portable than from execname.
2021-05-19 22:29:21 +03:00
shirou 9a5f86a30e
Merge pull request #1065 from scop/feat/solaris-process-some
Basic Solaris process support
2021-05-19 22:08:00 +09:00
Ville Skyttä e35ae34dce [process][solaris] process basics 2021-05-08 16:54:12 +03:00
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.
2021-05-08 16:46:56 +03:00
shirou 2fa855f295 add MockEnv as more generic function. 2021-05-08 21:18:46 +09:00
shirou abacce2177 [process][linux] add test to parse fillFromStatus 2021-05-08 20:56:46 +09:00
shirou 008b5a41ef
Merge pull request #1060 from heptalium/master
Fix fillFromStatusWithContext() on systems with 128 bit signal masks.
2021-05-08 18:52:36 +09:00
Lomanic c7a38de76e
Merge pull request #1052 from gballet/openbsd-arm-support
add support for OpenBSD arm64
2021-04-19 02:08:35 +02:00
Jens Meißner fc074343f8
[process][linux] Fix fillFromStatusWithContext() on systems with 128 bit signal masks. 2021-04-13 21:24:39 +02:00
shirou 79048ccbfa
Merge pull request #1035 from jblesener/fixmacosspaces
Fix spaces on long process names for MacOS
2021-04-01 20:21:38 +09:00
John Blesener 07797b12d3
Make cmdNameWithContext lower-case to avoid exporting it
Signed-off-by: John Blesener <jblesener@reactivelabs.com>
2021-03-27 17:14:18 +09:00
Guillaume Ballet 992d17af94 add support for OpenBSD arm64 2021-03-23 15:29:27 +01:00
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
2021-03-18 23:55:59 +01:00
Lomanic 62d8920abb [process][windows] Fix #714 call OpenProcess with PROCESS_QUERY_INFORMATION on WinXP 2021-03-06 22:53:54 +01:00
shirou a5834f48c4
Merge pull request #1033 from eriknordmark/erik-reduce-memory
Avoid returning slice into buffer from Readfile
2021-02-26 23:12:05 +09:00
John Blesener e8b2bea47f
Fix spaces on long process names for MacOS 2021-02-16 14:51:44 +09:00
eriknordmark 0e13743b77 Avoid returning slice into buffer from Readfile
Signed-off-by: eriknordmark <erik@zededa.com>
2021-02-08 19:21:22 +01:00
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.
2021-02-04 18:03:52 +01:00
shirou a9a6146c93 [process] fix MemoryInfo comment. remove Swap
fixes #1012
2021-01-14 19:00:55 +09:00
Rishabh Arya 5b1d8ecae7 fix smap parser 2021-01-03 21:06:54 +05:30
Lomanic 995610e109 [process][windows] Fix Nice() test expecting Unix values 2020-11-08 17:13:56 +01:00
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
2020-11-08 17:13:56 +01:00
Lomanic 148a662b06 [process][darwin] Remove Groups() as it's non-functional 2020-11-08 17:13:56 +01:00
Lomanic f810d518bb
Merge pull request #962 from AtakanColak/fix-ppid-race-961
Fix Windows Ppid Cache Race Condition
2020-10-29 20:52:08 +01:00
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
2020-10-24 15:35:19 +02:00