more_core_extensions 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -0
- data/README.md +7 -0
- data/lib/more_core_extensions/all.rb +1 -0
- data/lib/more_core_extensions/core_ext/process.rb +1 -0
- data/lib/more_core_extensions/core_ext/process/pause_resume.rb +110 -0
- data/lib/more_core_extensions/version.rb +1 -1
- data/more_core_extensions.gemspec +2 -0
- metadata +33 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b68065b7aadc9963519eeb642c21a30fd9d1e9dc36d382d1a3be6f9c38f1b499
|
4
|
+
data.tar.gz: 7928ae1d052c0848bc9f30c8e2b70f503033d636948303b032c479526c140747
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2cb37b00b2a1b9d8109d2527b6cc84010ff7ae39701419ff10ebbeaf6fd4afbb740a4e1abe3d6643e21943b8a2afa49f290a2fb9092c4add4338d5101d34ac9
|
7
|
+
data.tar.gz: 7e4521d99ffea1646088357448bf3da5009eed637c8c3e53a2fdb5554fea66bfc28baf4de06851f1efc2b6034bf9304c60b6d09f0bcd37be18da3ec37f18e049
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
5
5
|
## [Unreleased]
|
6
6
|
|
7
|
+
## [4.1.0] - 2020-04-30
|
8
|
+
### Added
|
9
|
+
- Added Ruby 2.7 support [[#79](https://github.com/ManageIQ/more_core_extensions/pull/79)]
|
10
|
+
- Added Process#pause, Process#resume, and Process#alive? [[#73](https://github.com/ManageIQ/more_core_extensions/pull/73)]
|
11
|
+
|
7
12
|
## [4.0.0] - 2020-01-31
|
8
13
|
### Changed
|
9
14
|
- **BREAKING**: Moved Object#descendant_get to Class#descendant_get [[#75](https://github.com/ManageIQ/more_core_extensions/pull/75)]
|
data/README.md
CHANGED
@@ -90,6 +90,13 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS
|
|
90
90
|
* core_ext/module/namespace.rb
|
91
91
|
* `#in_namespace?` - Returns whether or not the object is in the given namespace
|
92
92
|
|
93
|
+
#### Process
|
94
|
+
|
95
|
+
* core_ext/process/pause_resume.rb
|
96
|
+
* `.pause` - Pauses a process
|
97
|
+
* `.resume` - Resumes a paused process
|
98
|
+
* `.alive?` - Returns whether or not a process is running
|
99
|
+
|
93
100
|
#### Range
|
94
101
|
|
95
102
|
* core_ext/range/step_value.rb
|
@@ -8,6 +8,7 @@ require 'more_core_extensions/core_ext/math'
|
|
8
8
|
require 'more_core_extensions/core_ext/module'
|
9
9
|
require 'more_core_extensions/core_ext/numeric'
|
10
10
|
require 'more_core_extensions/core_ext/object'
|
11
|
+
require 'more_core_extensions/core_ext/process'
|
11
12
|
require 'more_core_extensions/core_ext/range'
|
12
13
|
require 'more_core_extensions/core_ext/string'
|
13
14
|
require 'more_core_extensions/core_ext/symbol'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'more_core_extensions/core_ext/process/pause_resume'
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module MoreCoreExtensions
|
2
|
+
module ProcessPauseResume
|
3
|
+
if Gem.win_platform?
|
4
|
+
require 'fiddle'
|
5
|
+
ntdll = Fiddle.dlopen('ntdll')
|
6
|
+
kernel32 = Fiddle.dlopen('kernel32')
|
7
|
+
|
8
|
+
NtSuspendProcess = Fiddle::Function.new(
|
9
|
+
ntdll['NtSuspendProcess'],
|
10
|
+
[Fiddle::TYPE_UINTPTR_T],
|
11
|
+
Fiddle::TYPE_INT
|
12
|
+
)
|
13
|
+
|
14
|
+
private_constant :NtSuspendProcess
|
15
|
+
|
16
|
+
NtResumeProcess = Fiddle::Function.new(
|
17
|
+
ntdll['NtResumeProcess'],
|
18
|
+
[Fiddle::TYPE_UINTPTR_T],
|
19
|
+
Fiddle::TYPE_INT
|
20
|
+
)
|
21
|
+
|
22
|
+
private_constant :NtResumeProcess
|
23
|
+
|
24
|
+
OpenProcess = Fiddle::Function.new(
|
25
|
+
kernel32['OpenProcess'],
|
26
|
+
[Fiddle::TYPE_LONG, Fiddle::TYPE_INT, Fiddle::TYPE_LONG],
|
27
|
+
Fiddle::TYPE_UINTPTR_T
|
28
|
+
)
|
29
|
+
|
30
|
+
private_constant :OpenProcess
|
31
|
+
|
32
|
+
CloseHandle = Fiddle::Function.new(
|
33
|
+
kernel32['CloseHandle'],
|
34
|
+
[Fiddle::TYPE_UINTPTR_T],
|
35
|
+
Fiddle::TYPE_INT
|
36
|
+
)
|
37
|
+
|
38
|
+
private_constant :CloseHandle
|
39
|
+
|
40
|
+
PROCESS_SUSPEND_RESUME = 0x00000800
|
41
|
+
|
42
|
+
private_constant :PROCESS_SUSPEND_RESUME
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns whether or not the given process is running.
|
46
|
+
#
|
47
|
+
def alive?(pid)
|
48
|
+
Process.kill(0, pid)
|
49
|
+
true
|
50
|
+
rescue Errno::ESRCH
|
51
|
+
false
|
52
|
+
end
|
53
|
+
|
54
|
+
# Suspend the process +pid+. If the process isn't running then this is no-op.
|
55
|
+
#
|
56
|
+
if Gem.win_platform?
|
57
|
+
def pause(pid)
|
58
|
+
return unless alive?(pid)
|
59
|
+
|
60
|
+
begin
|
61
|
+
handle = OpenProcess.call(PROCESS_SUSPEND_RESUME, 0, pid)
|
62
|
+
|
63
|
+
if handle == 0
|
64
|
+
raise SystemCallError, Fiddle.win32_last_error, "OpenProcess"
|
65
|
+
end
|
66
|
+
|
67
|
+
if NtSuspendProcess.call(handle) != 0
|
68
|
+
raise SystemCallError, Fiddle.win32_last_error, "NtSuspendProcess"
|
69
|
+
end
|
70
|
+
ensure
|
71
|
+
CloseHandle.call(handle) if handle
|
72
|
+
end
|
73
|
+
1 # For cross-platform compatibility
|
74
|
+
end
|
75
|
+
else
|
76
|
+
def pause(pid)
|
77
|
+
Process.kill('STOP', pid) if alive?(pid)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Resume the process +pid+. If the process isn't running then this is a no-op.
|
82
|
+
#
|
83
|
+
if Gem.win_platform?
|
84
|
+
def resume(pid)
|
85
|
+
return unless alive?(pid)
|
86
|
+
|
87
|
+
begin
|
88
|
+
handle = OpenProcess.call(PROCESS_SUSPEND_RESUME, 0, pid)
|
89
|
+
|
90
|
+
if handle == 0
|
91
|
+
raise SystemCallError, Fiddle.win32_last_error, "OpenProcess"
|
92
|
+
end
|
93
|
+
|
94
|
+
if NtResumeProcess.call(handle) != 0
|
95
|
+
raise SystemCallError, Fiddle.win32_last_error, "NtResumeProcess"
|
96
|
+
end
|
97
|
+
ensure
|
98
|
+
CloseHandle.call(handle) if handle
|
99
|
+
end
|
100
|
+
1 # For cross-platform compatibility
|
101
|
+
end
|
102
|
+
else
|
103
|
+
def resume(pid)
|
104
|
+
Process.kill('CONT', pid) if alive?(pid)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Process.send(:extend, MoreCoreExtensions::ProcessPauseResume)
|
@@ -27,7 +27,9 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rake"
|
28
28
|
spec.add_development_dependency "rspec", ">= 3.0"
|
29
29
|
spec.add_development_dependency "simplecov"
|
30
|
+
spec.add_development_dependency "sys-proctable", "~> 1.2.2"
|
30
31
|
spec.add_development_dependency "timecop"
|
31
32
|
|
32
33
|
spec.add_runtime_dependency "activesupport"
|
34
|
+
spec.add_runtime_dependency "sync"
|
33
35
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: more_core_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Frey
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: sys-proctable
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.2.2
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.2.2
|
84
98
|
- !ruby/object:Gem::Dependency
|
85
99
|
name: timecop
|
86
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,6 +123,20 @@ dependencies:
|
|
109
123
|
- - ">="
|
110
124
|
- !ruby/object:Gem::Version
|
111
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: sync
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :runtime
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
112
140
|
description: MoreCoreExtensions are a set of core extensions beyond those provided
|
113
141
|
by ActiveSupport.
|
114
142
|
email:
|
@@ -163,6 +191,8 @@ files:
|
|
163
191
|
- lib/more_core_extensions/core_ext/numeric/rounding.rb
|
164
192
|
- lib/more_core_extensions/core_ext/object.rb
|
165
193
|
- lib/more_core_extensions/core_ext/object/namespace.rb
|
194
|
+
- lib/more_core_extensions/core_ext/process.rb
|
195
|
+
- lib/more_core_extensions/core_ext/process/pause_resume.rb
|
166
196
|
- lib/more_core_extensions/core_ext/range.rb
|
167
197
|
- lib/more_core_extensions/core_ext/range/step_value.rb
|
168
198
|
- lib/more_core_extensions/core_ext/shared/nested.rb
|
@@ -194,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
224
|
- !ruby/object:Gem::Version
|
195
225
|
version: '0'
|
196
226
|
requirements: []
|
197
|
-
rubygems_version: 3.
|
227
|
+
rubygems_version: 3.1.2
|
198
228
|
signing_key:
|
199
229
|
specification_version: 4
|
200
230
|
summary: MoreCoreExtensions are a set of core extensions beyond those provided by
|