childprocess 0.8.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.document +6 -6
- data/.gitignore +28 -28
- data/.rspec +1 -1
- data/.travis.yml +42 -36
- data/CHANGELOG.md +67 -44
- data/Gemfile +18 -15
- data/LICENSE +20 -20
- data/README.md +216 -192
- data/Rakefile +61 -61
- data/appveyor.yml +42 -43
- data/childprocess.gemspec +32 -30
- data/ext/mkrf_conf.rb +24 -0
- data/lib/childprocess/abstract_io.rb +36 -36
- data/lib/childprocess/abstract_process.rb +192 -192
- data/lib/childprocess/errors.rb +37 -26
- data/lib/childprocess/jruby/io.rb +16 -16
- data/lib/childprocess/jruby/process.rb +184 -159
- data/lib/childprocess/jruby/pump.rb +53 -53
- data/lib/childprocess/jruby.rb +56 -56
- data/lib/childprocess/tools/generator.rb +145 -145
- data/lib/childprocess/unix/fork_exec_process.rb +78 -70
- data/lib/childprocess/unix/io.rb +21 -21
- data/lib/childprocess/unix/lib.rb +186 -186
- data/lib/childprocess/unix/platform/i386-linux.rb +12 -12
- data/lib/childprocess/unix/platform/i386-solaris.rb +11 -11
- data/lib/childprocess/unix/platform/x86_64-linux.rb +12 -12
- data/lib/childprocess/unix/platform/x86_64-macosx.rb +11 -11
- data/lib/childprocess/unix/posix_spawn_process.rb +134 -134
- data/lib/childprocess/unix/process.rb +90 -89
- data/lib/childprocess/unix.rb +9 -9
- data/lib/childprocess/version.rb +3 -3
- data/lib/childprocess/windows/handle.rb +91 -91
- data/lib/childprocess/windows/io.rb +25 -25
- data/lib/childprocess/windows/lib.rb +416 -416
- data/lib/childprocess/windows/process.rb +130 -130
- data/lib/childprocess/windows/process_builder.rb +178 -175
- data/lib/childprocess/windows/structs.rb +148 -148
- data/lib/childprocess/windows.rb +33 -33
- data/lib/childprocess.rb +210 -205
- data/spec/abstract_io_spec.rb +12 -12
- data/spec/childprocess_spec.rb +447 -391
- data/spec/get_env.ps1 +13 -0
- data/spec/io_spec.rb +228 -228
- data/spec/jruby_spec.rb +24 -24
- data/spec/pid_behavior.rb +12 -12
- data/spec/platform_detection_spec.rb +86 -86
- data/spec/spec_helper.rb +270 -261
- data/spec/unix_spec.rb +57 -57
- data/spec/windows_spec.rb +23 -23
- metadata +18 -33
@@ -1,149 +1,149 @@
|
|
1
|
-
module ChildProcess
|
2
|
-
module Windows
|
3
|
-
# typedef struct _STARTUPINFO {
|
4
|
-
# DWORD cb;
|
5
|
-
# LPTSTR lpReserved;
|
6
|
-
# LPTSTR lpDesktop;
|
7
|
-
# LPTSTR lpTitle;
|
8
|
-
# DWORD dwX;
|
9
|
-
# DWORD dwY;
|
10
|
-
# DWORD dwXSize;
|
11
|
-
# DWORD dwYSize;
|
12
|
-
# DWORD dwXCountChars;
|
13
|
-
# DWORD dwYCountChars;
|
14
|
-
# DWORD dwFillAttribute;
|
15
|
-
# DWORD dwFlags;
|
16
|
-
# WORD wShowWindow;
|
17
|
-
# WORD cbReserved2;
|
18
|
-
# LPBYTE lpReserved2;
|
19
|
-
# HANDLE hStdInput;
|
20
|
-
# HANDLE hStdOutput;
|
21
|
-
# HANDLE hStdError;
|
22
|
-
# } STARTUPINFO, *LPSTARTUPINFO;
|
23
|
-
|
24
|
-
class StartupInfo < FFI::Struct
|
25
|
-
layout :cb, :ulong,
|
26
|
-
:lpReserved, :pointer,
|
27
|
-
:lpDesktop, :pointer,
|
28
|
-
:lpTitle, :pointer,
|
29
|
-
:dwX, :ulong,
|
30
|
-
:dwY, :ulong,
|
31
|
-
:dwXSize, :ulong,
|
32
|
-
:dwYSize, :ulong,
|
33
|
-
:dwXCountChars, :ulong,
|
34
|
-
:dwYCountChars, :ulong,
|
35
|
-
:dwFillAttribute, :ulong,
|
36
|
-
:dwFlags, :ulong,
|
37
|
-
:wShowWindow, :ushort,
|
38
|
-
:cbReserved2, :ushort,
|
39
|
-
:lpReserved2, :pointer,
|
40
|
-
:hStdInput, :pointer, # void ptr
|
41
|
-
:hStdOutput, :pointer, # void ptr
|
42
|
-
:hStdError, :pointer # void ptr
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
# typedef struct _PROCESS_INFORMATION {
|
47
|
-
# HANDLE hProcess;
|
48
|
-
# HANDLE hThread;
|
49
|
-
# DWORD dwProcessId;
|
50
|
-
# DWORD dwThreadId;
|
51
|
-
# } PROCESS_INFORMATION, *LPPROCESS_INFORMATION;
|
52
|
-
#
|
53
|
-
|
54
|
-
class ProcessInfo < FFI::Struct
|
55
|
-
layout :hProcess, :pointer, # void ptr
|
56
|
-
:hThread, :pointer, # void ptr
|
57
|
-
:dwProcessId, :ulong,
|
58
|
-
:dwThreadId, :ulong
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# typedef struct _SECURITY_ATTRIBUTES {
|
63
|
-
# DWORD nLength;
|
64
|
-
# LPVOID lpSecurityDescriptor;
|
65
|
-
# BOOL bInheritHandle;
|
66
|
-
# } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
|
67
|
-
#
|
68
|
-
|
69
|
-
class SecurityAttributes < FFI::Struct
|
70
|
-
layout :nLength, :ulong,
|
71
|
-
:lpSecurityDescriptor, :pointer, # void ptr
|
72
|
-
:bInheritHandle, :int
|
73
|
-
|
74
|
-
def initialize(opts = {})
|
75
|
-
super()
|
76
|
-
|
77
|
-
self[:nLength] = self.class.size
|
78
|
-
self[:lpSecurityDescriptor] = nil
|
79
|
-
self[:bInheritHandle] = opts[:inherit] ? 1 : 0
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION {
|
85
|
-
# LARGE_INTEGER PerProcessUserTimeLimit;
|
86
|
-
# LARGE_INTEGER PerJobUserTimeLimit;
|
87
|
-
# DWORD LimitFlags;
|
88
|
-
# SIZE_T MinimumWorkingSetSize;
|
89
|
-
# SIZE_T MaximumWorkingSetSize;
|
90
|
-
# DWORD ActiveProcessLimit;
|
91
|
-
# ULONG_PTR Affinity;
|
92
|
-
# DWORD PriorityClass;
|
93
|
-
# DWORD SchedulingClass;
|
94
|
-
# } JOBOBJECT_BASIC_LIMIT_INFORMATION, *PJOBOBJECT_BASIC_LIMIT_INFORMATION;
|
95
|
-
#
|
96
|
-
class JobObjectBasicLimitInformation < FFI::Struct
|
97
|
-
layout :PerProcessUserTimeLimit, :int64,
|
98
|
-
:PerJobUserTimeLimit, :int64,
|
99
|
-
:LimitFlags, :ulong,
|
100
|
-
:MinimumWorkingSetSize, :size_t,
|
101
|
-
:MaximumWorkingSetSize, :size_t,
|
102
|
-
:ActiveProcessLimit, :ulong,
|
103
|
-
:Affinity, :pointer,
|
104
|
-
:PriorityClass, :ulong,
|
105
|
-
:SchedulingClass, :ulong
|
106
|
-
end
|
107
|
-
|
108
|
-
#
|
109
|
-
# typedef struct _IO_COUNTERS {
|
110
|
-
# ULONGLONG ReadOperationCount;
|
111
|
-
# ULONGLONG WriteOperationCount;
|
112
|
-
# ULONGLONG OtherOperationCount;
|
113
|
-
# ULONGLONG ReadTransferCount;
|
114
|
-
# ULONGLONG WriteTransferCount;
|
115
|
-
# ULONGLONG OtherTransferCount;
|
116
|
-
# } IO_COUNTERS, *PIO_COUNTERS;
|
117
|
-
#
|
118
|
-
|
119
|
-
class IoCounters < FFI::Struct
|
120
|
-
layout :ReadOperationCount, :ulong_long,
|
121
|
-
:WriteOperationCount, :ulong_long,
|
122
|
-
:OtherOperationCount, :ulong_long,
|
123
|
-
:ReadTransferCount, :ulong_long,
|
124
|
-
:WriteTransferCount, :ulong_long,
|
125
|
-
:OtherTransferCount, :ulong_long
|
126
|
-
end
|
127
|
-
#
|
128
|
-
# typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
|
129
|
-
# JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
|
130
|
-
# IO_COUNTERS IoInfo;
|
131
|
-
# SIZE_T ProcessMemoryLimit;
|
132
|
-
# SIZE_T JobMemoryLimit;
|
133
|
-
# SIZE_T PeakProcessMemoryUsed;
|
134
|
-
# SIZE_T PeakJobMemoryUsed;
|
135
|
-
# } JOBOBJECT_EXTENDED_LIMIT_INFORMATION, *PJOBOBJECT_EXTENDED_LIMIT_INFORMATION;
|
136
|
-
#
|
137
|
-
|
138
|
-
class JobObjectExtendedLimitInformation < FFI::Struct
|
139
|
-
layout :BasicLimitInformation, JobObjectBasicLimitInformation,
|
140
|
-
:IoInfo, IoCounters,
|
141
|
-
:ProcessMemoryLimit, :size_t,
|
142
|
-
:JobMemoryLimit, :size_t,
|
143
|
-
:PeakProcessMemoryUsed, :size_t,
|
144
|
-
:PeakJobMemoryUsed, :size_t
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
end # Windows
|
1
|
+
module ChildProcess
|
2
|
+
module Windows
|
3
|
+
# typedef struct _STARTUPINFO {
|
4
|
+
# DWORD cb;
|
5
|
+
# LPTSTR lpReserved;
|
6
|
+
# LPTSTR lpDesktop;
|
7
|
+
# LPTSTR lpTitle;
|
8
|
+
# DWORD dwX;
|
9
|
+
# DWORD dwY;
|
10
|
+
# DWORD dwXSize;
|
11
|
+
# DWORD dwYSize;
|
12
|
+
# DWORD dwXCountChars;
|
13
|
+
# DWORD dwYCountChars;
|
14
|
+
# DWORD dwFillAttribute;
|
15
|
+
# DWORD dwFlags;
|
16
|
+
# WORD wShowWindow;
|
17
|
+
# WORD cbReserved2;
|
18
|
+
# LPBYTE lpReserved2;
|
19
|
+
# HANDLE hStdInput;
|
20
|
+
# HANDLE hStdOutput;
|
21
|
+
# HANDLE hStdError;
|
22
|
+
# } STARTUPINFO, *LPSTARTUPINFO;
|
23
|
+
|
24
|
+
class StartupInfo < FFI::Struct
|
25
|
+
layout :cb, :ulong,
|
26
|
+
:lpReserved, :pointer,
|
27
|
+
:lpDesktop, :pointer,
|
28
|
+
:lpTitle, :pointer,
|
29
|
+
:dwX, :ulong,
|
30
|
+
:dwY, :ulong,
|
31
|
+
:dwXSize, :ulong,
|
32
|
+
:dwYSize, :ulong,
|
33
|
+
:dwXCountChars, :ulong,
|
34
|
+
:dwYCountChars, :ulong,
|
35
|
+
:dwFillAttribute, :ulong,
|
36
|
+
:dwFlags, :ulong,
|
37
|
+
:wShowWindow, :ushort,
|
38
|
+
:cbReserved2, :ushort,
|
39
|
+
:lpReserved2, :pointer,
|
40
|
+
:hStdInput, :pointer, # void ptr
|
41
|
+
:hStdOutput, :pointer, # void ptr
|
42
|
+
:hStdError, :pointer # void ptr
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# typedef struct _PROCESS_INFORMATION {
|
47
|
+
# HANDLE hProcess;
|
48
|
+
# HANDLE hThread;
|
49
|
+
# DWORD dwProcessId;
|
50
|
+
# DWORD dwThreadId;
|
51
|
+
# } PROCESS_INFORMATION, *LPPROCESS_INFORMATION;
|
52
|
+
#
|
53
|
+
|
54
|
+
class ProcessInfo < FFI::Struct
|
55
|
+
layout :hProcess, :pointer, # void ptr
|
56
|
+
:hThread, :pointer, # void ptr
|
57
|
+
:dwProcessId, :ulong,
|
58
|
+
:dwThreadId, :ulong
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# typedef struct _SECURITY_ATTRIBUTES {
|
63
|
+
# DWORD nLength;
|
64
|
+
# LPVOID lpSecurityDescriptor;
|
65
|
+
# BOOL bInheritHandle;
|
66
|
+
# } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
|
67
|
+
#
|
68
|
+
|
69
|
+
class SecurityAttributes < FFI::Struct
|
70
|
+
layout :nLength, :ulong,
|
71
|
+
:lpSecurityDescriptor, :pointer, # void ptr
|
72
|
+
:bInheritHandle, :int
|
73
|
+
|
74
|
+
def initialize(opts = {})
|
75
|
+
super()
|
76
|
+
|
77
|
+
self[:nLength] = self.class.size
|
78
|
+
self[:lpSecurityDescriptor] = nil
|
79
|
+
self[:bInheritHandle] = opts[:inherit] ? 1 : 0
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# typedef struct _JOBOBJECT_BASIC_LIMIT_INFORMATION {
|
85
|
+
# LARGE_INTEGER PerProcessUserTimeLimit;
|
86
|
+
# LARGE_INTEGER PerJobUserTimeLimit;
|
87
|
+
# DWORD LimitFlags;
|
88
|
+
# SIZE_T MinimumWorkingSetSize;
|
89
|
+
# SIZE_T MaximumWorkingSetSize;
|
90
|
+
# DWORD ActiveProcessLimit;
|
91
|
+
# ULONG_PTR Affinity;
|
92
|
+
# DWORD PriorityClass;
|
93
|
+
# DWORD SchedulingClass;
|
94
|
+
# } JOBOBJECT_BASIC_LIMIT_INFORMATION, *PJOBOBJECT_BASIC_LIMIT_INFORMATION;
|
95
|
+
#
|
96
|
+
class JobObjectBasicLimitInformation < FFI::Struct
|
97
|
+
layout :PerProcessUserTimeLimit, :int64,
|
98
|
+
:PerJobUserTimeLimit, :int64,
|
99
|
+
:LimitFlags, :ulong,
|
100
|
+
:MinimumWorkingSetSize, :size_t,
|
101
|
+
:MaximumWorkingSetSize, :size_t,
|
102
|
+
:ActiveProcessLimit, :ulong,
|
103
|
+
:Affinity, :pointer,
|
104
|
+
:PriorityClass, :ulong,
|
105
|
+
:SchedulingClass, :ulong
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# typedef struct _IO_COUNTERS {
|
110
|
+
# ULONGLONG ReadOperationCount;
|
111
|
+
# ULONGLONG WriteOperationCount;
|
112
|
+
# ULONGLONG OtherOperationCount;
|
113
|
+
# ULONGLONG ReadTransferCount;
|
114
|
+
# ULONGLONG WriteTransferCount;
|
115
|
+
# ULONGLONG OtherTransferCount;
|
116
|
+
# } IO_COUNTERS, *PIO_COUNTERS;
|
117
|
+
#
|
118
|
+
|
119
|
+
class IoCounters < FFI::Struct
|
120
|
+
layout :ReadOperationCount, :ulong_long,
|
121
|
+
:WriteOperationCount, :ulong_long,
|
122
|
+
:OtherOperationCount, :ulong_long,
|
123
|
+
:ReadTransferCount, :ulong_long,
|
124
|
+
:WriteTransferCount, :ulong_long,
|
125
|
+
:OtherTransferCount, :ulong_long
|
126
|
+
end
|
127
|
+
#
|
128
|
+
# typedef struct _JOBOBJECT_EXTENDED_LIMIT_INFORMATION {
|
129
|
+
# JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation;
|
130
|
+
# IO_COUNTERS IoInfo;
|
131
|
+
# SIZE_T ProcessMemoryLimit;
|
132
|
+
# SIZE_T JobMemoryLimit;
|
133
|
+
# SIZE_T PeakProcessMemoryUsed;
|
134
|
+
# SIZE_T PeakJobMemoryUsed;
|
135
|
+
# } JOBOBJECT_EXTENDED_LIMIT_INFORMATION, *PJOBOBJECT_EXTENDED_LIMIT_INFORMATION;
|
136
|
+
#
|
137
|
+
|
138
|
+
class JobObjectExtendedLimitInformation < FFI::Struct
|
139
|
+
layout :BasicLimitInformation, JobObjectBasicLimitInformation,
|
140
|
+
:IoInfo, IoCounters,
|
141
|
+
:ProcessMemoryLimit, :size_t,
|
142
|
+
:JobMemoryLimit, :size_t,
|
143
|
+
:PeakProcessMemoryUsed, :size_t,
|
144
|
+
:PeakJobMemoryUsed, :size_t
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
end # Windows
|
149
149
|
end # ChildProcess
|
data/lib/childprocess/windows.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
require "ffi"
|
2
|
-
require "rbconfig"
|
3
|
-
|
4
|
-
module ChildProcess
|
5
|
-
module Windows
|
6
|
-
module Lib
|
7
|
-
extend FFI::Library
|
8
|
-
|
9
|
-
def self.msvcrt_name
|
10
|
-
host_part = RbConfig::CONFIG['host_os'].split("_")[1]
|
11
|
-
manifest = File.join(RbConfig::CONFIG['bindir'], 'ruby.exe.manifest')
|
12
|
-
|
13
|
-
if host_part && host_part.to_i > 80 && File.exists?(manifest)
|
14
|
-
"msvcr#{host_part}"
|
15
|
-
else
|
16
|
-
"msvcrt"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
ffi_lib "kernel32", msvcrt_name
|
21
|
-
ffi_convention :stdcall
|
22
|
-
|
23
|
-
|
24
|
-
end # Library
|
25
|
-
end # Windows
|
26
|
-
end # ChildProcess
|
27
|
-
|
28
|
-
require "childprocess/windows/lib"
|
29
|
-
require "childprocess/windows/structs"
|
30
|
-
require "childprocess/windows/handle"
|
31
|
-
require "childprocess/windows/io"
|
32
|
-
require "childprocess/windows/process_builder"
|
33
|
-
require "childprocess/windows/process"
|
1
|
+
require "ffi"
|
2
|
+
require "rbconfig"
|
3
|
+
|
4
|
+
module ChildProcess
|
5
|
+
module Windows
|
6
|
+
module Lib
|
7
|
+
extend FFI::Library
|
8
|
+
|
9
|
+
def self.msvcrt_name
|
10
|
+
host_part = RbConfig::CONFIG['host_os'].split("_")[1]
|
11
|
+
manifest = File.join(RbConfig::CONFIG['bindir'], 'ruby.exe.manifest')
|
12
|
+
|
13
|
+
if host_part && host_part.to_i > 80 && File.exists?(manifest)
|
14
|
+
"msvcr#{host_part}"
|
15
|
+
else
|
16
|
+
"msvcrt"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ffi_lib "kernel32", msvcrt_name
|
21
|
+
ffi_convention :stdcall
|
22
|
+
|
23
|
+
|
24
|
+
end # Library
|
25
|
+
end # Windows
|
26
|
+
end # ChildProcess
|
27
|
+
|
28
|
+
require "childprocess/windows/lib"
|
29
|
+
require "childprocess/windows/structs"
|
30
|
+
require "childprocess/windows/handle"
|
31
|
+
require "childprocess/windows/io"
|
32
|
+
require "childprocess/windows/process_builder"
|
33
|
+
require "childprocess/windows/process"
|