Erlang/OTP Forums

Author Message

<  Erlang patches mailing list  ~  Patch for erl shell (unix/ttsl_drv.c) SIGWINCH handling (R12

Guest
Posted: Mon Dec 31, 2007 7:29 pm Reply with quote
Guest
This is an attempt to fix the problem described by Matthew
Dempsky:
http://erlang.org/pipermail/erlang-questions/2007-December/031962.html

The erl shell in Unix does not properly handle terminal
resize events which can result in a misplaced cursor and
other confusion.

This patch adds two functions to the file
erts/emulator/drivers/unix/ttsl_drv.c

winch() is registered as the handler for SIGWINCH which is
received on terminal resize events. winch() sets a global
flag "cols_needs_update = TRUE".

update_cols() is run at the start of each function that uses
the COL() or LINE() macros for calculating cursor positions,
namely the del_chars(), write_buf(), and move_cursor()
functions. It checks the "cols_needs_update" flag, and sets
the "cols" global var to the number returned by
ttysl_get_widow_size().

If the terminal is resized after update_cols() but before
use of the COL() macro, then we'll have the same incorrect
cursor problems during that function.

We don't run ttysl_get_window_size() from the SIGWINCH
handler because it uses ioctl() which is not listed as a
"safe" function for use in signal handlers in the signal(7)
man page.

That said, the solution would be more elegant if we did call
ttysl_get_window_size() from the signal handler, avoiding
the polling done by update_cols(). The ncurses source
includes a simple test/view.c program that does use ioctl()
in its SIGWINCH handler. It states "This uses functions
that are 'unsafe', but it seems to work on SunOS and Linux."
Doing this in erl works for me on Linux, but I have no idea
on which platforms if may fail.

I've only tested this with R12B-1 on Linux 2.6.22.

--
Patrick Mahoney <pat@polycrystal.org>


Post recived from mailinglist
mdempsky
Posted: Tue Jan 01, 2008 2:41 am Reply with quote
User Joined: 24 Sep 2007 Posts: 118
On 12/31/07, Patrick Mahoney <pat@polycrystal.org> wrote:
> I've only tested this with R12B-1 on Linux 2.6.22.

I verified that this patch fixes the problem I reported for both
Terminal.app and xterm on OS X. If it's merged, I'll award the $100
bounty to Patrick.
_______________________________________________
erlang-patches mailing list
erlang-patches@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-patches
Post recived from mailinglist
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum