tty issue with drip #511

Closed
nirvdrum opened this Issue Jan 24, 2013 · 11 comments

Projects

None yet

1 participant

@nirvdrum
Contributor

I'm unable to exit a Rails console I start up with JRuby 1.7.2 on Ubuntu 12.10 when using drip.

nirvdrum@melchior ~/dev/workspaces/mogotest $ ./script/rails c
+ ./script/rails c
Loading development environment (Rails 3.2.11)
[1] pry(main)> exit
Errno::ENOTTY: Inappropriate ioctl for device - ioctl(TOCGWINSZ)
from /home/nirvdrum/.rbenv/versions/jruby-1.7.2/lib/ruby/1.9/io/console.rb:117:in `winsize'
@ghost
ghost commented Jan 24, 2013

This doesn't happen when not running via drip, correct?

You might want to set a breakpoint on that line in io/console.rb and see what fileno is. If drip is using pipes or something else that is not a tty, then it will be a problem.

@nirvdrum
Contributor

Correct, not an issue outside of drip. I'll try to dig up more info.

@ghost
ghost commented Jan 24, 2013

It might be an idea to embellish the error message with the value of fileno. I suspect there may be a problem the the fake fileno mechanism, and the way drip is launching jruby - basically when run normally, $stdin.fileno == 0, $stdout.fileno == 1, $stderr.fileno == 2 (its hardcoded for those 3) - but if you open a file, IO#fileno will be >= 3, and not reflect the actual native file descriptor value at all.

Fixing that is .. bigger than a point release. It would probably be easier to change drip.

it could also be something else that drip isn't doing or is doing differently.

@nirvdrum
Contributor

The fileno is 1. Of course, without looking at the code I have no idea what it's supposed to be.

@ghost
ghost commented Jan 24, 2013

Map in a couple of extra functions, and call then against the fileno
e.g.

diff --git a/lib/ruby/1.9/io/linux_console.rb b/lib/ruby/1.9/io/linux_console.rb
index 76741ef..2f44621 100644
--- a/lib/ruby/1.9/io/linux_console.rb
+++ b/lib/ruby/1.9/io/linux_console.rb
@@ -197,4 +197,6 @@ module IO::LibC
   attach_function :cfmakeraw, [ Termios ], :int
   attach_function :tcflush, [ :int, :int ], :int
   attach_function :ioctl, [ :int, :ulong, :varargs ], :int
+  attach_function :ttyname, [ :int ], :string
+  attach_function :isatty, [ :int ], :int
 end

Then just print out LibC.ttyname(fileno), and LibC.isatty(fileno)

@nirvdrum
Contributor

Here's the output the first time (before drip starts up):

nirvdrum@melchior ~/dev/workspaces/mogotest $ ./script/rails c
+ ./script/rails c
Loading development environment (Rails 3.2.11)
[1] pry(main)> exit
Fileno: 1
ttyname: /dev/pts/6
[1] pry(main)> exit

And here it is when running through drip:

nirvdrum@melchior ~/dev/workspaces/mogotest $ ./script/rails c
+ ./script/rails c
Loading development environment (Rails 3.2.11)
[1] pry(main)> exit
Fileno: 1
ttyname: 
isatty: 0
Errno::ENOTTY: Inappropriate ioctl for device - ioctl(TOCGWINSZ)
from /home/nirvdrum/.rbenv/versions/jruby-1.7.2/lib/ruby/1.9/io/console.rb:120:in `winsize'

In the success case, I can only either get the ttyname or check if it's a tty. Making a call to either seems to prevent any other STDOUT operations.

@ghost
ghost commented Jan 26, 2013

That looks like drip is not starting JRuby with a valid tty on fd 1. It doesn't look like it is a problem with JRuby.

@nirvdrum
Contributor

Interesting. Any idea why it'd be able to start the console but not exit it?

@ghost
ghost commented Jan 26, 2013

That, I do not know - it isn't calling any io/console methods during startup, otherwise it would fail.

@ghost
ghost commented Feb 5, 2013

Can you retry with jruby-head? Commit fc2d4e6 should fix this and similar console issues, as it now gets the real native fd from the IO instance.

@nirvdrum
Contributor
nirvdrum commented Feb 6, 2013

Great. This did fix the issue. I was about to bug the drip guys, but now I won't need to. Thanks for persevering.

@nirvdrum nirvdrum closed this Feb 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment