Merge pull request #11990 from sullivan-sean/sandbox-pty-fix
Restore original TTY state after Sandbox
This commit is contained in:
		
						commit
						4b68787740
					
				@ -113,11 +113,12 @@ class Sandbox
 | 
				
			|||||||
            [Utils.popen_read("tput", "lines").to_i, Utils.popen_read("tput", "cols").to_i]
 | 
					            [Utils.popen_read("tput", "lines").to_i, Utils.popen_read("tput", "cols").to_i]
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        write_to_pty = proc do
 | 
				
			||||||
          # Update the window size whenever the parent terminal's window size changes.
 | 
					          # Update the window size whenever the parent terminal's window size changes.
 | 
				
			||||||
          old_winch = trap(:WINCH, &winch)
 | 
					          old_winch = trap(:WINCH, &winch)
 | 
				
			||||||
          winch.call(nil)
 | 
					          winch.call(nil)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $stdin.raw! if $stdin.tty?
 | 
					 | 
				
			||||||
          stdin_thread = Thread.new { IO.copy_stream($stdin, w) }
 | 
					          stdin_thread = Thread.new { IO.copy_stream($stdin, w) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          r.each_char { |c| print(c) }
 | 
					          r.each_char { |c| print(c) }
 | 
				
			||||||
@ -125,9 +126,19 @@ class Sandbox
 | 
				
			|||||||
          Process.wait(pid)
 | 
					          Process.wait(pid)
 | 
				
			||||||
        ensure
 | 
					        ensure
 | 
				
			||||||
          stdin_thread&.kill
 | 
					          stdin_thread&.kill
 | 
				
			||||||
        $stdin.cooked! if $stdin.tty?
 | 
					 | 
				
			||||||
          trap(:WINCH, old_winch)
 | 
					          trap(:WINCH, old_winch)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if $stdin.tty?
 | 
				
			||||||
 | 
					          # If stdin is a TTY, use io.raw to set stdin to a raw, passthrough
 | 
				
			||||||
 | 
					          # mode while we copy the input/output of the process spawned in the
 | 
				
			||||||
 | 
					          # PTY. After we've finished copying to/from the PTY process, io.raw
 | 
				
			||||||
 | 
					          # will restore the stdin TTY to its original state.
 | 
				
			||||||
 | 
					          $stdin.raw(&write_to_pty)
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					          write_to_pty.call
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
      raise ErrorDuringExecution.new(command, status: $CHILD_STATUS) unless $CHILD_STATUS.success?
 | 
					      raise ErrorDuringExecution.new(command, status: $CHILD_STATUS) unless $CHILD_STATUS.success?
 | 
				
			||||||
    rescue
 | 
					    rescue
 | 
				
			||||||
      @failed = true
 | 
					      @failed = true
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user