Project

General

Profile

Bug #2235

Segmentation fault with PTY.spawn

Added by vr.sundar (Sundar Vasan) almost 10 years ago. Updated about 2 months ago.

Status:
Closed
Priority:
Normal
ruby -v:
ruby 1.9.1p281 (2009-08-09 revision 24476) [i386-darwin9.8.0]
[ruby-core:26168]

Description

=begin
Running (on ruby 1.9.1 branch) this script :

*** Begin script ***
#!/usr/bin/env ruby
require 'pty'

r, w, pid = PTY.spawn("echo 'hello world'; sleep 1")

puts "sleeping"
sleep 5
puts "done"

***** End script *****

causes this segmentation fault (run it a few times if it doesn't at first try):

*** Begin output ****
[BUG] Segmentation fault
ruby 1.9.1p281 (2009-08-09 revision 24476) [i386-darwin9.8.0]

-- control frame ----------
c:0001 p:---- s:0002 b:0002 l:000001 d:000001 TOP


-- Ruby level backtrace information-----------------------------------------

-- C level backtrace information -------------------------------------------
0x1179d2 0 ruby 0x001179d2 rb_vm_bugreport + 82
0x2c46c 1 ruby 0x0002c46c rb_warning + 444
0x2c4cb 2 ruby 0x0002c4cb rb_bug + 43
0xbdcd8 3 ruby 0x000bdcd8 rb_enable_interrupt + 232
0x90e042bb 4 libSystem.B.dylib 0x90e042bb _sigtramp + 43
0xffffffff 5 ??? 0xffffffff 0x0 + 4294967295
0x103986 6 ruby 0x00103986 rb_get_method_body + 38
0x107615 7 ruby 0x00107615 rb_funcall + 229
0x4235ab 8 pty.bundle 0x004235ab 0x0 + 4339115
0x423686 9 pty.bundle 0x00423686 0x0 + 4339334
0x11d556 10 ruby 0x0011d556 rb_exec_recursive + 1030
0x11d591 11 ruby 0x0011d591 rb_exec_recursive + 1089
0x90dc9155 12 libSystem.B.dylib 0x90dc9155 _pthread_start + 321
0x90dc9012 13 libSystem.B.dylib 0x90dc9012 thread_start + 34

[NOTE]
You may encounter a bug of Ruby interpreter. Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap

***** End output ***

The problem is caused by the fact that pty_getpty allocates pty info struct on the stack (line 453) and then passes them to pty_syswait which is run on a new thread. One fix would be to just xcalloc them. But there is also a secondary design problem in that when this is fixed, PTY throws a asynchronous exception when the process finishes. That the process finished in not an exception and making it async means the exception could happen anywhere in my main code which is hard to handle. Both of these are fixed on trunk. The segfault by itself should definitely be fixed but it would be great if the changes on trunk were merged into 1.9.1 branch. (I personally think both should be fixed). Any chances of that?
=end


Files

pty_test.rb (126 Bytes) pty_test.rb vr.sundar (Sundar Vasan), 10/20/2009 04:12 AM

History

#1

Updated by naruse (Yui NARUSE) almost 10 years ago

  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)

=begin
This still happens in p376.
=end

#2

Updated by jeremyevans0 (Jeremy Evans) about 2 months ago

  • Status changed from Assigned to Closed
  • Description updated (diff)

Also available in: Atom PDF