childprocess 0.9.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/.document +6 -6
  3. data/.gitignore +28 -28
  4. data/.rspec +1 -1
  5. data/.travis.yml +40 -44
  6. data/CHANGELOG.md +73 -49
  7. data/Gemfile +21 -15
  8. data/LICENSE +20 -20
  9. data/README.md +218 -196
  10. data/Rakefile +61 -61
  11. data/appveyor.yml +42 -60
  12. data/childprocess.gemspec +26 -30
  13. data/lib/childprocess.rb +210 -205
  14. data/lib/childprocess/abstract_io.rb +36 -36
  15. data/lib/childprocess/abstract_process.rb +192 -192
  16. data/lib/childprocess/errors.rb +37 -26
  17. data/lib/childprocess/jruby.rb +56 -56
  18. data/lib/childprocess/jruby/io.rb +16 -16
  19. data/lib/childprocess/jruby/process.rb +184 -159
  20. data/lib/childprocess/jruby/pump.rb +53 -53
  21. data/lib/childprocess/tools/generator.rb +145 -145
  22. data/lib/childprocess/unix.rb +9 -9
  23. data/lib/childprocess/unix/fork_exec_process.rb +78 -70
  24. data/lib/childprocess/unix/io.rb +21 -21
  25. data/lib/childprocess/unix/lib.rb +186 -186
  26. data/lib/childprocess/unix/platform/i386-linux.rb +12 -12
  27. data/lib/childprocess/unix/platform/i386-solaris.rb +11 -11
  28. data/lib/childprocess/unix/platform/x86_64-linux.rb +12 -12
  29. data/lib/childprocess/unix/platform/x86_64-macosx.rb +11 -11
  30. data/lib/childprocess/unix/posix_spawn_process.rb +134 -134
  31. data/lib/childprocess/unix/process.rb +90 -89
  32. data/lib/childprocess/version.rb +3 -3
  33. data/lib/childprocess/windows.rb +38 -33
  34. data/lib/childprocess/windows/handle.rb +91 -91
  35. data/lib/childprocess/windows/io.rb +25 -25
  36. data/lib/childprocess/windows/lib.rb +416 -416
  37. data/lib/childprocess/windows/process.rb +130 -130
  38. data/lib/childprocess/windows/process_builder.rb +178 -175
  39. data/lib/childprocess/windows/structs.rb +148 -148
  40. data/spec/abstract_io_spec.rb +12 -12
  41. data/spec/childprocess_spec.rb +447 -422
  42. data/spec/get_env.ps1 +13 -0
  43. data/spec/io_spec.rb +228 -228
  44. data/spec/jruby_spec.rb +24 -24
  45. data/spec/pid_behavior.rb +12 -12
  46. data/spec/platform_detection_spec.rb +86 -86
  47. data/spec/spec_helper.rb +270 -261
  48. data/spec/unix_spec.rb +57 -57
  49. data/spec/windows_spec.rb +23 -23
  50. metadata +8 -39
@@ -1,21 +1,21 @@
1
- module ChildProcess
2
- module Unix
3
- class IO < AbstractIO
4
- private
5
-
6
- def check_type(io)
7
- unless io.respond_to? :to_io
8
- raise ArgumentError, "expected #{io.inspect} to respond to :to_io"
9
- end
10
-
11
- result = io.to_io
12
- unless result && result.kind_of?(::IO)
13
- raise TypeError, "expected IO, got #{result.inspect}:#{result.class}"
14
- end
15
- end
16
-
17
- end # IO
18
- end # Unix
19
- end # ChildProcess
20
-
21
-
1
+ module ChildProcess
2
+ module Unix
3
+ class IO < AbstractIO
4
+ private
5
+
6
+ def check_type(io)
7
+ unless io.respond_to? :to_io
8
+ raise ArgumentError, "expected #{io.inspect} to respond to :to_io"
9
+ end
10
+
11
+ result = io.to_io
12
+ unless result && result.kind_of?(::IO)
13
+ raise TypeError, "expected IO, got #{result.inspect}:#{result.class}"
14
+ end
15
+ end
16
+
17
+ end # IO
18
+ end # Unix
19
+ end # ChildProcess
20
+
21
+
@@ -1,186 +1,186 @@
1
- module ChildProcess
2
- module Unix
3
- module Lib
4
- extend FFI::Library
5
- ffi_lib FFI::Library::LIBC
6
-
7
- if ChildProcess.os == :macosx
8
- attach_function :_NSGetEnviron, [], :pointer
9
- def self.environ
10
- _NSGetEnviron().read_pointer
11
- end
12
- elsif respond_to? :attach_variable
13
- attach_variable :environ, :pointer
14
- end
15
-
16
- attach_function :strerror, [:int], :string
17
- attach_function :chdir, [:string], :int
18
- attach_function :fcntl, [:int, :int, :int], :int # fcntl actually takes varags, but we only need this version.
19
-
20
- # int posix_spawnp(
21
- # pid_t *restrict pid,
22
- # const char *restrict file,
23
- # const posix_spawn_file_actions_t *file_actions,
24
- # const posix_spawnattr_t *restrict attrp,
25
- # char *const argv[restrict],
26
- # char *const envp[restrict]
27
- # );
28
-
29
- attach_function :posix_spawnp, [
30
- :pointer,
31
- :string,
32
- :pointer,
33
- :pointer,
34
- :pointer,
35
- :pointer
36
- ], :int
37
-
38
- # int posix_spawn_file_actions_init(posix_spawn_file_actions_t *file_actions);
39
- attach_function :posix_spawn_file_actions_init, [:pointer], :int
40
-
41
- # int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *file_actions);
42
- attach_function :posix_spawn_file_actions_destroy, [:pointer], :int
43
-
44
- # int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *file_actions, int filedes);
45
- attach_function :posix_spawn_file_actions_addclose, [:pointer, :int], :int
46
-
47
- # int posix_spawn_file_actions_addopen(
48
- # posix_spawn_file_actions_t *restrict file_actions,
49
- # int filedes,
50
- # const char *restrict path,
51
- # int oflag,
52
- # mode_t mode
53
- # );
54
- attach_function :posix_spawn_file_actions_addopen, [:pointer, :int, :string, :int, :mode_t], :int
55
-
56
- # int posix_spawn_file_actions_adddup2(
57
- # posix_spawn_file_actions_t *file_actions,
58
- # int filedes,
59
- # int newfiledes
60
- # );
61
- attach_function :posix_spawn_file_actions_adddup2, [:pointer, :int, :int], :int
62
-
63
- # int posix_spawnattr_init(posix_spawnattr_t *attr);
64
- attach_function :posix_spawnattr_init, [:pointer], :int
65
-
66
- # int posix_spawnattr_destroy(posix_spawnattr_t *attr);
67
- attach_function :posix_spawnattr_destroy, [:pointer], :int
68
-
69
- # int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags);
70
- attach_function :posix_spawnattr_setflags, [:pointer, :short], :int
71
-
72
- # int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags);
73
- attach_function :posix_spawnattr_getflags, [:pointer, :pointer], :int
74
-
75
- # int posix_spawnattr_setpgroup(posix_spawnattr_t *attr, pid_t pgroup);
76
- attach_function :posix_spawnattr_setpgroup, [:pointer, :pid_t], :int
77
-
78
- # int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict attr, pid_t *restrict pgroup);
79
- attach_function :posix_spawnattr_getpgroup, [:pointer, :pointer], :int
80
-
81
- # int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict attr, const sigset_t *restrict sigdefault);
82
- attach_function :posix_spawnattr_setsigdefault, [:pointer, :pointer], :int
83
-
84
- # int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict attr, sigset_t *restrict sigdefault);
85
- attach_function :posix_spawnattr_getsigdefault, [:pointer, :pointer], :int
86
-
87
- # int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict attr, const sigset_t *restrict sigmask);
88
- attach_function :posix_spawnattr_setsigmask, [:pointer, :pointer], :int
89
-
90
- # int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict attr, sigset_t *restrict sigmask);
91
- attach_function :posix_spawnattr_getsigmask, [:pointer, :pointer], :int
92
-
93
- def self.check(errno)
94
- if errno != 0
95
- raise Error, Lib.strerror(FFI.errno)
96
- end
97
- end
98
-
99
- class FileActions
100
- def initialize
101
- @ptr = FFI::MemoryPointer.new(1, Platform::SIZEOF.fetch(:posix_spawn_file_actions_t), false)
102
- Lib.check Lib.posix_spawn_file_actions_init(@ptr)
103
- end
104
-
105
- def add_close(fileno)
106
- Lib.check Lib.posix_spawn_file_actions_addclose(
107
- @ptr,
108
- fileno
109
- )
110
- end
111
-
112
- def add_open(fileno, path, oflag, mode)
113
- Lib.check Lib.posix_spawn_file_actions_addopen(
114
- @ptr,
115
- fileno,
116
- path,
117
- oflag,
118
- mode
119
- )
120
- end
121
-
122
- def add_dup(fileno, new_fileno)
123
- Lib.check Lib.posix_spawn_file_actions_adddup2(
124
- @ptr,
125
- fileno,
126
- new_fileno
127
- )
128
- end
129
-
130
- def free
131
- Lib.check Lib.posix_spawn_file_actions_destroy(@ptr)
132
- @ptr = nil
133
- end
134
-
135
- def to_ptr
136
- @ptr
137
- end
138
- end # FileActions
139
-
140
- class Attrs
141
- def initialize
142
- @ptr = FFI::MemoryPointer.new(1, Platform::SIZEOF.fetch(:posix_spawnattr_t), false)
143
- Lib.check Lib.posix_spawnattr_init(@ptr)
144
- end
145
-
146
- def free
147
- Lib.check Lib.posix_spawnattr_destroy(@ptr)
148
- @ptr = nil
149
- end
150
-
151
- def flags=(flags)
152
- Lib.check Lib.posix_spawnattr_setflags(@ptr, flags)
153
- end
154
-
155
- def flags
156
- ptr = FFI::MemoryPointer.new(:short)
157
- Lib.check Lib.posix_spawnattr_getflags(@ptr, ptr)
158
-
159
- ptr.read_short
160
- end
161
-
162
- def pgroup=(pid)
163
- self.flags |= Platform::POSIX_SPAWN_SETPGROUP
164
- Lib.check Lib.posix_spawnattr_setpgroup(@ptr, pid)
165
- end
166
-
167
- def to_ptr
168
- @ptr
169
- end
170
- end # Attrs
171
-
172
- end
173
- end
174
- end
175
-
176
- # missing on rubinius
177
- class FFI::MemoryPointer
178
- unless method_defined?(:from_string)
179
- def self.from_string(str)
180
- ptr = new(1, str.bytesize + 1)
181
- ptr.write_string("#{str}\0")
182
-
183
- ptr
184
- end
185
- end
186
- end
1
+ module ChildProcess
2
+ module Unix
3
+ module Lib
4
+ extend FFI::Library
5
+ ffi_lib FFI::Library::LIBC
6
+
7
+ if ChildProcess.os == :macosx
8
+ attach_function :_NSGetEnviron, [], :pointer
9
+ def self.environ
10
+ _NSGetEnviron().read_pointer
11
+ end
12
+ elsif respond_to? :attach_variable
13
+ attach_variable :environ, :pointer
14
+ end
15
+
16
+ attach_function :strerror, [:int], :string
17
+ attach_function :chdir, [:string], :int
18
+ attach_function :fcntl, [:int, :int, :int], :int # fcntl actually takes varags, but we only need this version.
19
+
20
+ # int posix_spawnp(
21
+ # pid_t *restrict pid,
22
+ # const char *restrict file,
23
+ # const posix_spawn_file_actions_t *file_actions,
24
+ # const posix_spawnattr_t *restrict attrp,
25
+ # char *const argv[restrict],
26
+ # char *const envp[restrict]
27
+ # );
28
+
29
+ attach_function :posix_spawnp, [
30
+ :pointer,
31
+ :string,
32
+ :pointer,
33
+ :pointer,
34
+ :pointer,
35
+ :pointer
36
+ ], :int
37
+
38
+ # int posix_spawn_file_actions_init(posix_spawn_file_actions_t *file_actions);
39
+ attach_function :posix_spawn_file_actions_init, [:pointer], :int
40
+
41
+ # int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *file_actions);
42
+ attach_function :posix_spawn_file_actions_destroy, [:pointer], :int
43
+
44
+ # int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *file_actions, int filedes);
45
+ attach_function :posix_spawn_file_actions_addclose, [:pointer, :int], :int
46
+
47
+ # int posix_spawn_file_actions_addopen(
48
+ # posix_spawn_file_actions_t *restrict file_actions,
49
+ # int filedes,
50
+ # const char *restrict path,
51
+ # int oflag,
52
+ # mode_t mode
53
+ # );
54
+ attach_function :posix_spawn_file_actions_addopen, [:pointer, :int, :string, :int, :mode_t], :int
55
+
56
+ # int posix_spawn_file_actions_adddup2(
57
+ # posix_spawn_file_actions_t *file_actions,
58
+ # int filedes,
59
+ # int newfiledes
60
+ # );
61
+ attach_function :posix_spawn_file_actions_adddup2, [:pointer, :int, :int], :int
62
+
63
+ # int posix_spawnattr_init(posix_spawnattr_t *attr);
64
+ attach_function :posix_spawnattr_init, [:pointer], :int
65
+
66
+ # int posix_spawnattr_destroy(posix_spawnattr_t *attr);
67
+ attach_function :posix_spawnattr_destroy, [:pointer], :int
68
+
69
+ # int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags);
70
+ attach_function :posix_spawnattr_setflags, [:pointer, :short], :int
71
+
72
+ # int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags);
73
+ attach_function :posix_spawnattr_getflags, [:pointer, :pointer], :int
74
+
75
+ # int posix_spawnattr_setpgroup(posix_spawnattr_t *attr, pid_t pgroup);
76
+ attach_function :posix_spawnattr_setpgroup, [:pointer, :pid_t], :int
77
+
78
+ # int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict attr, pid_t *restrict pgroup);
79
+ attach_function :posix_spawnattr_getpgroup, [:pointer, :pointer], :int
80
+
81
+ # int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict attr, const sigset_t *restrict sigdefault);
82
+ attach_function :posix_spawnattr_setsigdefault, [:pointer, :pointer], :int
83
+
84
+ # int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict attr, sigset_t *restrict sigdefault);
85
+ attach_function :posix_spawnattr_getsigdefault, [:pointer, :pointer], :int
86
+
87
+ # int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict attr, const sigset_t *restrict sigmask);
88
+ attach_function :posix_spawnattr_setsigmask, [:pointer, :pointer], :int
89
+
90
+ # int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict attr, sigset_t *restrict sigmask);
91
+ attach_function :posix_spawnattr_getsigmask, [:pointer, :pointer], :int
92
+
93
+ def self.check(errno)
94
+ if errno != 0
95
+ raise Error, Lib.strerror(FFI.errno)
96
+ end
97
+ end
98
+
99
+ class FileActions
100
+ def initialize
101
+ @ptr = FFI::MemoryPointer.new(1, Platform::SIZEOF.fetch(:posix_spawn_file_actions_t), false)
102
+ Lib.check Lib.posix_spawn_file_actions_init(@ptr)
103
+ end
104
+
105
+ def add_close(fileno)
106
+ Lib.check Lib.posix_spawn_file_actions_addclose(
107
+ @ptr,
108
+ fileno
109
+ )
110
+ end
111
+
112
+ def add_open(fileno, path, oflag, mode)
113
+ Lib.check Lib.posix_spawn_file_actions_addopen(
114
+ @ptr,
115
+ fileno,
116
+ path,
117
+ oflag,
118
+ mode
119
+ )
120
+ end
121
+
122
+ def add_dup(fileno, new_fileno)
123
+ Lib.check Lib.posix_spawn_file_actions_adddup2(
124
+ @ptr,
125
+ fileno,
126
+ new_fileno
127
+ )
128
+ end
129
+
130
+ def free
131
+ Lib.check Lib.posix_spawn_file_actions_destroy(@ptr)
132
+ @ptr = nil
133
+ end
134
+
135
+ def to_ptr
136
+ @ptr
137
+ end
138
+ end # FileActions
139
+
140
+ class Attrs
141
+ def initialize
142
+ @ptr = FFI::MemoryPointer.new(1, Platform::SIZEOF.fetch(:posix_spawnattr_t), false)
143
+ Lib.check Lib.posix_spawnattr_init(@ptr)
144
+ end
145
+
146
+ def free
147
+ Lib.check Lib.posix_spawnattr_destroy(@ptr)
148
+ @ptr = nil
149
+ end
150
+
151
+ def flags=(flags)
152
+ Lib.check Lib.posix_spawnattr_setflags(@ptr, flags)
153
+ end
154
+
155
+ def flags
156
+ ptr = FFI::MemoryPointer.new(:short)
157
+ Lib.check Lib.posix_spawnattr_getflags(@ptr, ptr)
158
+
159
+ ptr.read_short
160
+ end
161
+
162
+ def pgroup=(pid)
163
+ self.flags |= Platform::POSIX_SPAWN_SETPGROUP
164
+ Lib.check Lib.posix_spawnattr_setpgroup(@ptr, pid)
165
+ end
166
+
167
+ def to_ptr
168
+ @ptr
169
+ end
170
+ end # Attrs
171
+
172
+ end
173
+ end
174
+ end
175
+
176
+ # missing on rubinius
177
+ class FFI::MemoryPointer
178
+ unless method_defined?(:from_string)
179
+ def self.from_string(str)
180
+ ptr = new(1, str.bytesize + 1)
181
+ ptr.write_string("#{str}\0")
182
+
183
+ ptr
184
+ end
185
+ end
186
+ end
@@ -1,12 +1,12 @@
1
- module ChildProcess::Unix::Platform
2
- SIZEOF = {
3
- :posix_spawn_file_actions_t => 76,
4
- :posix_spawnattr_t => 336,
5
- :sigset_t => 128
6
- }
7
- POSIX_SPAWN_RESETIDS = 1
8
- POSIX_SPAWN_SETPGROUP = 2
9
- POSIX_SPAWN_SETSIGDEF = 4
10
- POSIX_SPAWN_SETSIGMASK = 8
11
- POSIX_SPAWN_USEVFORK = 64
12
- end
1
+ module ChildProcess::Unix::Platform
2
+ SIZEOF = {
3
+ :posix_spawn_file_actions_t => 76,
4
+ :posix_spawnattr_t => 336,
5
+ :sigset_t => 128
6
+ }
7
+ POSIX_SPAWN_RESETIDS = 1
8
+ POSIX_SPAWN_SETPGROUP = 2
9
+ POSIX_SPAWN_SETSIGDEF = 4
10
+ POSIX_SPAWN_SETSIGMASK = 8
11
+ POSIX_SPAWN_USEVFORK = 64
12
+ end
@@ -1,11 +1,11 @@
1
- module ChildProcess::Unix::Platform
2
- SIZEOF = {
3
- :posix_spawn_file_actions_t => 4,
4
- :posix_spawnattr_t => 4,
5
- :sigset_t => 16
6
- }
7
- POSIX_SPAWN_RESETIDS = 1
8
- POSIX_SPAWN_SETPGROUP = 2
9
- POSIX_SPAWN_SETSIGDEF = 4
10
- POSIX_SPAWN_SETSIGMASK = 8
11
- end
1
+ module ChildProcess::Unix::Platform
2
+ SIZEOF = {
3
+ :posix_spawn_file_actions_t => 4,
4
+ :posix_spawnattr_t => 4,
5
+ :sigset_t => 16
6
+ }
7
+ POSIX_SPAWN_RESETIDS = 1
8
+ POSIX_SPAWN_SETPGROUP = 2
9
+ POSIX_SPAWN_SETSIGDEF = 4
10
+ POSIX_SPAWN_SETSIGMASK = 8
11
+ end