rexec 1.4.0 → 1.4.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.
- data/lib/rexec/connection.rb +10 -1
- data/lib/rexec/server.rb +5 -5
- data/lib/rexec/task.rb +14 -1
- data/lib/rexec/version.rb +1 -1
- data/test/interrupt.rb +7 -0
- data/test/server_test.rb +3 -3
- metadata +5 -4
    
        data/lib/rexec/connection.rb
    CHANGED
    
    | @@ -39,7 +39,9 @@ module RExec | |
| 39 39 | 
             
            		def initialize(input, output, error = nil)
         | 
| 40 40 | 
             
            			@input = input
         | 
| 41 41 | 
             
            			@output = output
         | 
| 42 | 
            +
             | 
| 42 43 | 
             
            			@running = true
         | 
| 44 | 
            +
            			@exceptions = :send
         | 
| 43 45 |  | 
| 44 46 | 
             
            			@error = error
         | 
| 45 47 |  | 
| @@ -50,6 +52,9 @@ module RExec | |
| 50 52 | 
             
            		# The object that will handle remote proxy invocations.
         | 
| 51 53 | 
             
            		attr :handler, true
         | 
| 52 54 |  | 
| 55 | 
            +
            		# Whether to send exceptions across the wire, or handle normally (e.g. print to stdout):
         | 
| 56 | 
            +
            		attr :exceptions, true
         | 
| 57 | 
            +
            		
         | 
| 53 58 | 
             
            		# The proxy object that will dispatch RPCs.
         | 
| 54 59 | 
             
            		attr :proxy
         | 
| 55 60 |  | 
| @@ -98,7 +103,11 @@ module RExec | |
| 98 103 | 
             
            					begin
         | 
| 99 104 | 
             
            						yield object
         | 
| 100 105 | 
             
            					rescue Exception => ex
         | 
| 101 | 
            -
            						 | 
| 106 | 
            +
            						if @exceptions == :send
         | 
| 107 | 
            +
            							send_object(ex)
         | 
| 108 | 
            +
            						else
         | 
| 109 | 
            +
            							raise
         | 
| 110 | 
            +
            						end
         | 
| 102 111 | 
             
            					end
         | 
| 103 112 | 
             
            				end
         | 
| 104 113 | 
             
            			end
         | 
    
        data/lib/rexec/server.rb
    CHANGED
    
    | @@ -84,11 +84,11 @@ module RExec | |
| 84 84 | 
             
            			Task.open(command, options) do |task|
         | 
| 85 85 | 
             
            				conn = Connection.build(task, options, &send_code)
         | 
| 86 86 |  | 
| 87 | 
            -
            				 | 
| 88 | 
            -
             | 
| 89 | 
            -
            				 | 
| 90 | 
            -
             | 
| 91 | 
            -
            				 | 
| 87 | 
            +
            				begin
         | 
| 88 | 
            +
            					yield conn, task
         | 
| 89 | 
            +
            				ensure
         | 
| 90 | 
            +
            					conn.stop
         | 
| 91 | 
            +
            				end
         | 
| 92 92 | 
             
            			end
         | 
| 93 93 | 
             
            		else
         | 
| 94 94 | 
             
            			task = Task.open(command, options)
         | 
    
        data/lib/rexec/task.rb
    CHANGED
    
    | @@ -287,12 +287,17 @@ module RExec | |
| 287 287 | 
             
            				if command.respond_to? :call
         | 
| 288 288 | 
             
            					command.call
         | 
| 289 289 | 
             
            				elsif Array === command
         | 
| 290 | 
            +
            					command = command.dup
         | 
| 291 | 
            +
            					
         | 
| 290 292 | 
             
            					# If command is a Pathname, we need to convert it to an absolute path if possible,
         | 
| 291 293 | 
             
            					# otherwise if it is relative it might cause problems.
         | 
| 292 294 | 
             
            					if command[0].respond_to? :realpath
         | 
| 293 295 | 
             
            						command[0] = command[0].realpath
         | 
| 294 296 | 
             
            					end
         | 
| 295 297 |  | 
| 298 | 
            +
            					# exec expects an array of Strings:
         | 
| 299 | 
            +
            					command.collect! { |item| item.to_s }
         | 
| 300 | 
            +
            					
         | 
| 296 301 | 
             
            					exec *command
         | 
| 297 302 | 
             
            				else
         | 
| 298 303 | 
             
            					if command.respond_to? :realpath
         | 
| @@ -310,9 +315,17 @@ module RExec | |
| 310 315 | 
             
            			if block_given?
         | 
| 311 316 | 
             
            				begin
         | 
| 312 317 | 
             
            					yield task
         | 
| 318 | 
            +
            					
         | 
| 319 | 
            +
            					# Close all input pipes if not done already.
         | 
| 313 320 | 
             
            					task.close_input
         | 
| 321 | 
            +
            					
         | 
| 322 | 
            +
            					# The task has stopped if task.wait returns correctly.
         | 
| 314 323 | 
             
            					return task.wait
         | 
| 324 | 
            +
            				rescue Interrupt
         | 
| 325 | 
            +
            					# If task.wait is interrupted, we should also interrupt the child process
         | 
| 326 | 
            +
            					task.kill
         | 
| 315 327 | 
             
            				ensure
         | 
| 328 | 
            +
            					# Print out any remaining data from @output or @error
         | 
| 316 329 | 
             
            					task.close
         | 
| 317 330 | 
             
            				end
         | 
| 318 331 | 
             
            			else
         | 
| @@ -320,7 +333,7 @@ module RExec | |
| 320 333 | 
             
            			end
         | 
| 321 334 | 
             
            		end
         | 
| 322 335 |  | 
| 323 | 
            -
            		def initialize(input, output, error, pid) | 
| 336 | 
            +
            		def initialize(input, output, error, pid)
         | 
| 324 337 | 
             
            			@input = input
         | 
| 325 338 | 
             
            			@output = output
         | 
| 326 339 | 
             
            			@error = error
         | 
    
        data/lib/rexec/version.rb
    CHANGED
    
    
    
        data/test/interrupt.rb
    ADDED
    
    
    
        data/test/server_test.rb
    CHANGED
    
    | @@ -35,7 +35,7 @@ class ServerTest < Test::Unit::TestCase | |
| 35 35 | 
             
                connection_started = false
         | 
| 36 36 | 
             
                object_received = false
         | 
| 37 37 |  | 
| 38 | 
            -
                RExec::start_server(code.read, "ruby", :passthrough => []) do |conn,  | 
| 38 | 
            +
                RExec::start_server(code.read, "ruby", :passthrough => []) do |conn, task|
         | 
| 39 39 | 
             
                  connection_started = true
         | 
| 40 40 | 
             
                  conn.send_object([:bounce, sobj])
         | 
| 41 41 |  | 
| @@ -66,7 +66,7 @@ class ServerTest < Test::Unit::TestCase | |
| 66 66 |  | 
| 67 67 | 
             
                test_obj = [1, 2, 3, 4, "five"]
         | 
| 68 68 |  | 
| 69 | 
            -
                RExec::start_server(code.read, "/bin/sh -c ruby", :passthrough => []) do |conn,  | 
| 69 | 
            +
                RExec::start_server(code.read, "/bin/sh -c ruby", :passthrough => []) do |conn, task|
         | 
| 70 70 | 
             
                  connection_started = true
         | 
| 71 71 | 
             
                  conn.send_object([:bounce, test_obj])
         | 
| 72 72 |  | 
| @@ -84,7 +84,7 @@ class ServerTest < Test::Unit::TestCase | |
| 84 84 |  | 
| 85 85 | 
             
                test_obj = [1, 2, 3, 4, "five"]
         | 
| 86 86 |  | 
| 87 | 
            -
                conn,  | 
| 87 | 
            +
                conn, task = RExec::start_server(code.read, "/bin/sh -c ruby", :passthrough => [])
         | 
| 88 88 | 
             
                conn.send_object([:bounce, test_obj])
         | 
| 89 89 |  | 
| 90 90 | 
             
                assert_equal test_obj, conn.receive_object
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: rexec
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 5
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 1
         | 
| 8 8 | 
             
              - 4
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 1.4. | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 1.4.1
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Samuel Williams
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011-08- | 
| 18 | 
            +
            date: 2011-08-09 00:00:00 Z
         | 
| 19 19 | 
             
            dependencies: []
         | 
| 20 20 |  | 
| 21 21 | 
             
            description: 
         | 
| @@ -45,6 +45,7 @@ files: | |
| 45 45 | 
             
            - test/client.rb
         | 
| 46 46 | 
             
            - test/daemon.rb
         | 
| 47 47 | 
             
            - test/daemon_test.rb
         | 
| 48 | 
            +
            - test/interrupt.rb
         | 
| 48 49 | 
             
            - test/listing_example.rb
         | 
| 49 50 | 
             
            - test/remote_server_test.rb
         | 
| 50 51 | 
             
            - test/server_test.rb
         |