1
0
mirror of https://github.com/shirou/gopsutil.git synced 2025-04-28 13:48:49 +08:00

Merge pull request #1145 from shirou/feature/update_x_sys

[v3] update x/sys version and fix v2 process kill
This commit is contained in:
shirou 2021-10-17 19:11:57 +09:00 committed by GitHub
commit 9ba4650578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 50 deletions

26
Gopkg.lock generated
View File

@ -2,12 +2,12 @@
[[projects]] [[projects]]
digest = "1:9909e0a06cff3bd88841c9d2e0cc91b0a431676009018c74c3315f33b49b0046" digest = "1:3a991e1f8ab48d1445b5106b628609285cecb1bfe5abdd078b4320d32ec0f3ee"
name = "github.com/StackExchange/wmi" name = "github.com/StackExchange/wmi"
packages = ["."] packages = ["."]
pruneopts = "UT" pruneopts = "UT"
revision = "cbe66965904dbe8a6cd589e2298e5d8b986bd7dd" revision = "441642c1665945335b93778e496324884ce569e7"
version = "1.1.0" version = "v1.2.1"
[[projects]] [[projects]]
digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec"
@ -18,15 +18,15 @@
version = "v1.1.1" version = "v1.1.1"
[[projects]] [[projects]]
digest = "1:440028f55cb322d8cb5b9d5ebec298a00b7d74690a658fe6b1c0c0b44341bfae" digest = "1:fa413ac44630f9ca77bf7bb629804106a50cd5af351f89ed1e23e08e6173c5d0"
name = "github.com/go-ole/go-ole" name = "github.com/go-ole/go-ole"
packages = [ packages = [
".", ".",
"oleutil", "oleutil",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "97b6244175ae18ea6eef668034fd6565847501c9" revision = "8b1f7f90f6b1728609c9694f2cff140d34fd91f8"
version = "v1.2.4" version = "v1.2.6"
[[projects]] [[projects]]
digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe"
@ -37,15 +37,15 @@
version = "v1.0.0" version = "v1.0.0"
[[projects]] [[projects]]
digest = "1:efd3a1c83607945eb57cb6cf9c5a87f1c709fb9fdfbd3d8f729ff03943275465" digest = "1:5c7b4a9fefe5b7b160d2cf0ec8457de81db92038c45c88d7d59493568308cc5d"
name = "github.com/stretchr/testify" name = "github.com/stretchr/testify"
packages = [ packages = [
"assert", "assert",
"require", "require",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "004e3cb72213e5e727e4e08f668ee6c8f27e5d32" revision = "acba37e5db06f0093b465a7d47822bf13644b66c"
version = "v1.6.0" version = "v1.7.0"
[[projects]] [[projects]]
digest = "1:dc2f804edbbcc4e7c5385791b8703da9b6bc6e22e698233f919c19da6286cf11" digest = "1:dc2f804edbbcc4e7c5385791b8703da9b6bc6e22e698233f919c19da6286cf11"
@ -65,7 +65,7 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:1672d2eb5799465379f6016fa509eadd72c69e3eb2bf3cdfea9222e64e163b94" digest = "1:cded1795a2d143aa9940244639afeaeecc5cfb9bb2a01bdcaa4087e9beb989c0"
name = "golang.org/x/sys" name = "golang.org/x/sys"
packages = [ packages = [
"internal/unsafeheader", "internal/unsafeheader",
@ -75,15 +75,15 @@
"windows/svc/mgr", "windows/svc/mgr",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "134d130e1a049f4194ae9920ac9f96455cde360d" revision = "69063c4bb744bc56492b1a0533d73a23406b0bc2"
[[projects]] [[projects]]
branch = "v3" branch = "v3"
digest = "1:f87d6c8edf5e57ae4a355abc05aca1dbf38b073068bba96c1fbbff852a1e2fd3" digest = "1:107a619d3c3bcca214b2b7db810a5dffcd74b5d0262813cb2986e063fae2722f"
name = "gopkg.in/yaml.v3" name = "gopkg.in/yaml.v3"
packages = ["."] packages = ["."]
pruneopts = "UT" pruneopts = "UT"
revision = "2ff61e1afc866138abf1a8adf3cc89721090ac31" revision = "496545a6307b2a7d7a710fd516e5e16e8ab62dbc"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"

View File

@ -116,51 +116,51 @@ type processBasicInformation64 struct {
} }
type processEnvironmentBlock32 struct { type processEnvironmentBlock32 struct {
Reserved1 [2]uint8 Reserved1 [2]uint8
BeingDebugged uint8 BeingDebugged uint8
Reserved2 uint8 Reserved2 uint8
Reserved3 [2]uint32 Reserved3 [2]uint32
Ldr uint32 Ldr uint32
ProcessParameters uint32 ProcessParameters uint32
// More fields which we don't use so far // More fields which we don't use so far
} }
type processEnvironmentBlock64 struct { type processEnvironmentBlock64 struct {
Reserved1 [2]uint8 Reserved1 [2]uint8
BeingDebugged uint8 BeingDebugged uint8
Reserved2 uint8 Reserved2 uint8
_ [4]uint8 // padding, since we are 64 bit, the next pointer is 64 bit aligned (when compiling for 32 bit, this is not the case without manual padding) _ [4]uint8 // padding, since we are 64 bit, the next pointer is 64 bit aligned (when compiling for 32 bit, this is not the case without manual padding)
Reserved3 [2]uint64 Reserved3 [2]uint64
Ldr uint64 Ldr uint64
ProcessParameters uint64 ProcessParameters uint64
// More fields which we don't use so far // More fields which we don't use so far
} }
type rtlUserProcessParameters32 struct { type rtlUserProcessParameters32 struct {
Reserved1 [16]uint8 Reserved1 [16]uint8
Reserved2 [10]uint32 Reserved2 [10]uint32
ImagePathNameLength uint16 ImagePathNameLength uint16
_ uint16 _ uint16
ImagePathAddress uint32 ImagePathAddress uint32
CommandLineLength uint16 CommandLineLength uint16
_ uint16 _ uint16
CommandLineAddress uint32 CommandLineAddress uint32
EnvironmentAddress uint32 EnvironmentAddress uint32
// More fields which we don't use so far // More fields which we don't use so far
} }
type rtlUserProcessParameters64 struct { type rtlUserProcessParameters64 struct {
Reserved1 [16]uint8 Reserved1 [16]uint8
Reserved2 [10]uint64 Reserved2 [10]uint64
ImagePathNameLength uint16 ImagePathNameLength uint16
_ uint16 // Max Length _ uint16 // Max Length
_ uint32 // Padding _ uint32 // Padding
ImagePathAddress uint64 ImagePathAddress uint64
CommandLineLength uint16 CommandLineLength uint16
_ uint16 // Max Length _ uint16 // Max Length
_ uint32 // Padding _ uint32 // Padding
CommandLineAddress uint64 CommandLineAddress uint64
EnvironmentAddress uint64 EnvironmentAddress uint64
// More fields which we don't use so far // More fields which we don't use so far
} }
@ -669,7 +669,10 @@ func (p *Process) TerminateWithContext(ctx context.Context) error {
} }
func (p *Process) KillWithContext(ctx context.Context) error { func (p *Process) KillWithContext(ctx context.Context) error {
process := os.Process{Pid: int(p.Pid)} process, err := os.FindProcess(int(p.Pid))
if err != nil {
return err
}
return process.Kill() return process.Kill()
} }
@ -928,14 +931,14 @@ func getProcessEnvironmentVariables(pid int32, ctx context.Context) ([]string, e
is32BitProcess: procIs32Bits, is32BitProcess: procIs32Bits,
offset: processParameterBlockAddress, offset: processParameterBlockAddress,
}) })
envvarScanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error){ envvarScanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
if atEOF && len(data) == 0 { if atEOF && len(data) == 0 {
return 0, nil, nil return 0, nil, nil
} }
// Check for UTF-16 zero character // Check for UTF-16 zero character
for i := 0; i < len(data) - 1; i+=2 { for i := 0; i < len(data)-1; i += 2 {
if data[i] == 0 && data[i+1] == 0 { if data[i] == 0 && data[i+1] == 0 {
return i+2, data[0:i], nil return i + 2, data[0:i], nil
} }
} }
if atEOF { if atEOF {
@ -965,9 +968,9 @@ func getProcessEnvironmentVariables(pid int32, ctx context.Context) ([]string, e
} }
type processReader struct { type processReader struct {
processHandle windows.Handle processHandle windows.Handle
is32BitProcess bool is32BitProcess bool
offset uint64 offset uint64
} }
func (p *processReader) Read(buf []byte) (int, error) { func (p *processReader) Read(buf []byte) (int, error) {

View File

@ -7,5 +7,5 @@ require (
github.com/lufia/plan9stats v0.0.0-20211008203909-9b7c2b47d7c3 github.com/lufia/plan9stats v0.0.0-20211008203909-9b7c2b47d7c3
github.com/stretchr/testify v1.7.0 github.com/stretchr/testify v1.7.0
github.com/tklauser/go-sysconf v0.3.9 github.com/tklauser/go-sysconf v0.3.9
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71 golang.org/x/sys v0.0.0-20211013075003-97ac67df715c
) )

View File

@ -18,8 +18,9 @@ github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ
github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ= github.com/tklauser/numcpus v0.3.0 h1:ILuRUQBtssgnxw0XXIjKUC56fgnOrFoQQ/4+DeU2biQ=
github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8= github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71 h1:ikCpsnYR+Ew0vu99XlDp55lGgDJdIMx3f4a18jfse/s=
golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c h1:taxlMj0D/1sOAuv/CbSD+MMDof2vbyPTqz5FNYKpXt8=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=