childprocess 0.3.0 → 0.3.1

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.
@@ -11,7 +11,7 @@ module ChildProcess
11
11
  class << self
12
12
  def new(*args)
13
13
  case os
14
- when :macosx, :linux, :unix, :cygwin
14
+ when :macosx, :linux, :solaris, :bsd, :cygwin
15
15
  if posix_spawn?
16
16
  Unix::PosixSpawnProcess.new(args)
17
17
  elsif jruby?
@@ -22,7 +22,7 @@ module ChildProcess
22
22
  when :windows
23
23
  Windows::Process.new(args)
24
24
  else
25
- raise Error, "unsupported platform #{platform.inspect}"
25
+ raise Error, "unsupported platform #{platform_name.inspect}"
26
26
  end
27
27
  end
28
28
  alias_method :build, :new
@@ -101,8 +101,10 @@ module ChildProcess
101
101
  :windows
102
102
  when /cygwin/
103
103
  :cygwin
104
- when /solaris|bsd/
105
- :unix
104
+ when /solaris|sunos/
105
+ :solaris
106
+ when /bsd/
107
+ :bsd
106
108
  else
107
109
  raise Error, "unknown os: #{host_os.inspect}"
108
110
  end
@@ -144,7 +146,7 @@ module ChildProcess
144
146
  elsif windows?
145
147
  Windows::Lib.dont_inherit file
146
148
  else
147
- raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform.inspect}"
149
+ raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}"
148
150
  end
149
151
  end
150
152
 
@@ -8,9 +8,9 @@ end
8
8
  class Java::JavaIo::FileDescriptor
9
9
  if ChildProcess.os == :windows
10
10
  field_reader :handle
11
- else
12
- field_reader :fd
13
11
  end
12
+
13
+ field_reader :fd
14
14
  end
15
15
 
16
16
  module ChildProcess
@@ -30,6 +30,7 @@ module ChildProcess
30
30
 
31
31
  while read != -1
32
32
  avail = [@input.available, 1].max
33
+ avail = BUFFER_SIZE if avail > BUFFER_SIZE
33
34
  read = @input.read(buffer, 0, avail)
34
35
 
35
36
  if read > 0
@@ -1,4 +1,3 @@
1
- require 'ffi'
2
1
  require 'fileutils'
3
2
 
4
3
  module ChildProcess
@@ -120,8 +119,8 @@ int main() {
120
119
  end
121
120
 
122
121
  def result
123
- if @sizeof.empty?
124
- raise "no sizes collected, nothing to do"
122
+ if @sizeof.empty? && @constants.empty?
123
+ raise "no data collected, nothing to do"
125
124
  end
126
125
 
127
126
  out = ['module ChildProcess::Unix::Platform']
@@ -0,0 +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,3 +1,3 @@
1
1
  module ChildProcess
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -138,12 +138,12 @@ module ChildProcess
138
138
  attach_function :terminate_process, :TerminateProcess, [:pointer, :uint], :bool
139
139
 
140
140
  #
141
- # long _get_osfhandle(
141
+ # intptr_t _get_osfhandle(
142
142
  # int fd
143
143
  # );
144
144
  #
145
145
 
146
- attach_function :get_osfhandle, :_get_osfhandle, [:int], :long
146
+ attach_function :get_osfhandle, :_get_osfhandle, [:int], :intptr_t
147
147
 
148
148
  #
149
149
  # int _open_osfhandle (
@@ -72,7 +72,7 @@ module ChildProcess
72
72
  @inherit, # inherit handles
73
73
  @flags, # creation flags
74
74
  @env_ptr, # environment
75
- nil, # current directory
75
+ cwd, # current directory
76
76
  startup_info, # startup info
77
77
  process_info # process info
78
78
  )
@@ -94,6 +94,10 @@ module ChildProcess
94
94
  @flags |= DETACHED_PROCESS if @detach
95
95
  end
96
96
 
97
+ def cwd
98
+ @cwd ||= FFI::MemoryPointer.from_string(Dir.pwd)
99
+ end
100
+
97
101
  def setup_io
98
102
  if @stdout || @stderr
99
103
  startup_info[:dwFlags] ||= 0
@@ -138,14 +138,16 @@ describe ChildProcess do
138
138
  process = ruby("print Dir.pwd")
139
139
  process.io.stdout = process.io.stderr = file
140
140
 
141
+ expected_dir = nil
141
142
  Dir.chdir(Dir.tmpdir) do
143
+ expected_dir = Dir.pwd
142
144
  process.start
143
145
  end
144
146
 
145
147
  process.wait
146
148
 
147
149
  file.rewind
148
- file.read.should == Dir.tmpdir
150
+ file.read.should == expected_dir
149
151
  end
150
152
  end
151
153
 
@@ -128,4 +128,25 @@ describe ChildProcess do
128
128
 
129
129
  wait_until { can_bind? "127.0.0.1", port }
130
130
  end
131
+
132
+ it "handles long output" do
133
+ process = ruby <<-CODE
134
+ print 'a'*3000
135
+ CODE
136
+
137
+ out = Tempfile.new("long-output")
138
+ out.sync = true
139
+
140
+ begin
141
+ process.io.stdout = out
142
+
143
+ process.start
144
+ process.wait
145
+
146
+ out.rewind
147
+ out.read.size.should == 3000
148
+ ensure
149
+ out.close
150
+ end
151
+ end
131
152
  end
@@ -151,7 +151,7 @@ RSpec.configure do |c|
151
151
  @process && @process.alive? && @process.stop
152
152
  }
153
153
 
154
- if ChildProcess.jruby? && !ChildProcess.posix_spawn?
154
+ if ChildProcess.jruby? && ChildProcess.new("true").instance_of?(ChildProcess::JRuby::Process)
155
155
  c.filter_run_excluding :process_builder => false
156
156
  end
157
157
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: childprocess
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jari Bakken
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-13 00:00:00 Z
18
+ date: 2012-02-05 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -112,6 +112,7 @@ files:
112
112
  - lib/childprocess/unix/io.rb
113
113
  - lib/childprocess/unix/lib.rb
114
114
  - lib/childprocess/unix/platform/i386-linux.rb
115
+ - lib/childprocess/unix/platform/i386-solaris.rb
115
116
  - lib/childprocess/unix/platform/x86_64-linux.rb
116
117
  - lib/childprocess/unix/platform/x86_64-macosx.rb
117
118
  - lib/childprocess/unix/posix_spawn_process.rb
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
162
  requirements: []
162
163
 
163
164
  rubyforge_project: childprocess
164
- rubygems_version: 1.8.10
165
+ rubygems_version: 1.8.15
165
166
  signing_key:
166
167
  specification_version: 3
167
168
  summary: This gem aims at being a simple and reliable solution for controlling external programs running in the background on any Ruby / OS combination.