From fc130e699774228f396dc6f4fef4b654edc00451 Mon Sep 17 00:00:00 2001 From: Jonas Falkevik Date: Fri, 4 Apr 2014 22:17:34 +0200 Subject: Fix shell crash when in switch command mode The user_drv process can crash if ctrl-y is pressed when in switch command mode (ctrl-g). This is due to switch mode using edlin to parse the input. And edlin uses the process dictionary to store the kill_buffer. However the kill_buffer is undefined if not initialized by edlin:init/0 which makes the user_drv process crash since edlin is calling list:reverse/2 with undefined. Fix calles edlin:init/0 once before server_loop is entered. --- lib/kernel/src/user_drv.erl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib') diff --git a/lib/kernel/src/user_drv.erl b/lib/kernel/src/user_drv.erl index e6ce85c379..f7b2be1ca3 100644 --- a/lib/kernel/src/user_drv.erl +++ b/lib/kernel/src/user_drv.erl @@ -133,6 +133,10 @@ server1(Iport, Oport, Shell) -> flatten(io_lib:format("~ts\n", [erlang:system_info(system_version)]))}, Iport, Oport), + + %% Init edlin used by switch command + edlin:init(), + %% Enter the server loop. server_loop(Iport, Oport, Curr, User, Gr, queue:new()). -- cgit v1.2.3 From d756777e731fe7a8d63690ca0246c9cbd53dea75 Mon Sep 17 00:00:00 2001 From: Peter Andersson Date: Wed, 22 Apr 2015 14:09:48 +0200 Subject: Fix problem with unitialized edlin text buffer Also make it possible to copy text buffer from current group process to the JCL mode --- lib/kernel/src/user_drv.erl | 6 +++--- lib/stdlib/src/edlin.erl | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/kernel/src/user_drv.erl b/lib/kernel/src/user_drv.erl index f7b2be1ca3..380c685869 100644 --- a/lib/kernel/src/user_drv.erl +++ b/lib/kernel/src/user_drv.erl @@ -134,9 +134,6 @@ server1(Iport, Oport, Shell) -> [erlang:system_info(system_version)]))}, Iport, Oport), - %% Init edlin used by switch command - edlin:init(), - %% Enter the server loop. server_loop(Iport, Oport, Curr, User, Gr, queue:new()). @@ -319,6 +316,9 @@ handle_escape(Iport, Oport, User, Gr, IOQueue) -> _ -> % {ok,jcl} | undefined io_request({put_chars,unicode,"\nUser switch command\n"}, Iport, Oport), + %% init edlin used by switch command and have it copy the + %% text buffer from current group process + edlin:init(gr_cur_pid(Gr)), server_loop(Iport, Oport, User, switch_loop(Iport, Oport, Gr), IOQueue) end. diff --git a/lib/stdlib/src/edlin.erl b/lib/stdlib/src/edlin.erl index b3bc5f6d92..362669545e 100644 --- a/lib/stdlib/src/edlin.erl +++ b/lib/stdlib/src/edlin.erl @@ -21,7 +21,7 @@ %% A simple Emacs-like line editor. %% About Latin-1 characters: see the beginning of erl_scan.erl. --export([init/0,start/1,start/2,edit_line/2,prefix_arg/1]). +-export([init/0,init/1,start/1,start/2,edit_line/2,prefix_arg/1]). -export([erase_line/1,erase_inp/1,redraw_line/1]). -export([length_before/1,length_after/1,prompt/1]). -export([current_line/1, current_chars/1]). @@ -44,6 +44,20 @@ init() -> put(kill_buffer, []). +init(Pid) -> + %% copy the kill_buffer from the process Pid + CopiedKillBuf = + case erlang:process_info(Pid, dictionary) of + {dictionary,Dict} -> + case proplists:get_value(kill_buffer, Dict) of + undefined -> []; + Buf -> Buf + end; + undefined -> + [] + end, + put(kill_buffer, CopiedKillBuf). + %% start(Prompt) %% edit(Characters, Continuation) %% Return -- cgit v1.2.3