childprocess 0.8.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) 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 +42 -36
  6. data/CHANGELOG.md +67 -44
  7. data/Gemfile +18 -15
  8. data/LICENSE +20 -20
  9. data/README.md +216 -192
  10. data/Rakefile +61 -61
  11. data/appveyor.yml +42 -43
  12. data/childprocess.gemspec +32 -30
  13. data/ext/mkrf_conf.rb +24 -0
  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/io.rb +16 -16
  18. data/lib/childprocess/jruby/process.rb +184 -159
  19. data/lib/childprocess/jruby/pump.rb +53 -53
  20. data/lib/childprocess/jruby.rb +56 -56
  21. data/lib/childprocess/tools/generator.rb +145 -145
  22. data/lib/childprocess/unix/fork_exec_process.rb +78 -70
  23. data/lib/childprocess/unix/io.rb +21 -21
  24. data/lib/childprocess/unix/lib.rb +186 -186
  25. data/lib/childprocess/unix/platform/i386-linux.rb +12 -12
  26. data/lib/childprocess/unix/platform/i386-solaris.rb +11 -11
  27. data/lib/childprocess/unix/platform/x86_64-linux.rb +12 -12
  28. data/lib/childprocess/unix/platform/x86_64-macosx.rb +11 -11
  29. data/lib/childprocess/unix/posix_spawn_process.rb +134 -134
  30. data/lib/childprocess/unix/process.rb +90 -89
  31. data/lib/childprocess/unix.rb +9 -9
  32. data/lib/childprocess/version.rb +3 -3
  33. data/lib/childprocess/windows/handle.rb +91 -91
  34. data/lib/childprocess/windows/io.rb +25 -25
  35. data/lib/childprocess/windows/lib.rb +416 -416
  36. data/lib/childprocess/windows/process.rb +130 -130
  37. data/lib/childprocess/windows/process_builder.rb +178 -175
  38. data/lib/childprocess/windows/structs.rb +148 -148
  39. data/lib/childprocess/windows.rb +33 -33
  40. data/lib/childprocess.rb +210 -205
  41. data/spec/abstract_io_spec.rb +12 -12
  42. data/spec/childprocess_spec.rb +447 -391
  43. data/spec/get_env.ps1 +13 -0
  44. data/spec/io_spec.rb +228 -228
  45. data/spec/jruby_spec.rb +24 -24
  46. data/spec/pid_behavior.rb +12 -12
  47. data/spec/platform_detection_spec.rb +86 -86
  48. data/spec/spec_helper.rb +270 -261
  49. data/spec/unix_spec.rb +57 -57
  50. data/spec/windows_spec.rb +23 -23
  51. metadata +18 -33
@@ -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
@@ -1,12 +1,12 @@
1
- module ChildProcess::Unix::Platform
2
- SIZEOF = {
3
- :posix_spawn_file_actions_t => 80,
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 => 80,
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 => 8,
4
- :posix_spawnattr_t => 8,
5
- :sigset_t => 4
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 => 8,
4
+ :posix_spawnattr_t => 8,
5
+ :sigset_t => 4
6
+ }
7
+ POSIX_SPAWN_RESETIDS = 1
8
+ POSIX_SPAWN_SETPGROUP = 2
9
+ POSIX_SPAWN_SETSIGDEF = 4
10
+ POSIX_SPAWN_SETSIGMASK = 8
11
+ end