← Back to team overview

ubuntu-phone team mailing list archive

adb, nano, SIGWINCH, and enter key

 

The problem: when using adb shell, applications don't receive SIGWINCH
so they don't resize when you resize the terminal window. Also, the
enter key does not work in some places, notably the place in nano
where you type the filename and press enter. I did a lot of research
to find out why and this is what I found.

Firstly, this isn't Ubuntu specific, as the problem has been reported
to Android AOSP:
http://code.google.com/p/android/issues/detail?id=35897

SIGWINCH: This is a Unix signal like SIGINT (ctrl-c) but unlike SIGINT
you can't send it with the keyboard. adb opens the keyboard in
non-canonical mode using termios. That means when you press ctrl-c it
doesn't get the signal, it just gets a ctrl-c character ('\x03') on
stdin. This is sent to the phone like all other input. Because
SIGWINCH isn't an ascii code, adb still receives it as a signal even
when the terminal is non-canonical. We can add a signal handler to adb
so that it traps SIGWINCH. This is what ssh does. The difference
between ssh and adb however is that ssh has out of band signalling,
where as adb simply streams the raw input to the device. That means
there is no simple way for adb to tell the phone that SIGWINCH
happened. It would be necessary to add escaping to the adb protocol
(which would break compatibility) or add an out of band connection for
signalling. Both of these are quite complex changes.

The enter key problem is no so bad though. Again, it is due to
non-canonical mode, and in this case it's about line endings, \n (aka
LF, '\x0a', ^J) vs \r (aka CR, '\x0d', ^M). When in non-canonical
mode, enter, ^M, ^J, all send line feed only. That's to be expected I
suppose since that's the line ending character on Unix. The trouble is
that nano (and probably others) want a \r to finish entering the
filename or search string. A very easy workaround for this is to have
adb replace all outgoing \n with \r - this makes nano work properly
but I worry about side effects. It's only done for interactive shells
and only for the user input, so maybe it's not so bad. However, I do
wonder if there's a less invasive way to fix this. I tried changing
the terminal settings in every place I could - changing the line
ending character to both \n and \r, but none of it seemed to make a
difference. It seems odd that nano requires a \r given that it is
probably using non-canonical mode itself to catch all those ctrl-keys.

-- 
Alistair Buxton
a.j.buxton@xxxxxxxxx


Follow ups