From 59053f84228b27ecf28f2de31b4a45074b2d04c9 Mon Sep 17 00:00:00 2001 From: Stefan Zegenhagen Date: Mon, 6 May 2013 14:33:46 +0200 Subject: Make ssh_cli.erl handle +C Dear all, I've found that ssh_cli.erl does not scan the input received from the remote for occurrences of +C to signal the user's interrupt requests to the group_leader of the CLI session. The patch attached to this e-mail fixes the issue. Kind regards, -- Dr. Stefan Zegenhagen arcutronix GmbH Garbsener Landstr. 10 30419 Hannover Germany Tel: +49 511 277-2734 Fax: +49 511 277-2709 Email: stefan.zegenhagen@arcutronix.com Web: www.arcutronix.com *Synchronize the Ethernet* General Managers: Dipl. Ing. Juergen Schroeder, Dr. Josef Gfrerer - Legal Form: GmbH, Registered office: Hannover, HRB 202442, Amtsgericht Hannover; Ust-Id: DE257551767. Please consider the environment before printing this message. >From f1d056ed1bf419677098cdc57bc7ce8a327e6b43 Mon Sep 17 00:00:00 2001 From: Stefan Zegenhagen Date: Mon, 6 May 2013 14:29:45 +0200 Subject: [PATCH] [SSH-CLI] properly handle +C as shell interrupt In ssh_cli.erl, check for the presence of +C in data received from the remote. If detected, use the established mechanism (send an 'interrupt' exit signal to the group_leader) to signal an interrupt to the shell. --- lib/ssh/src/ssh_cli.erl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/ssh/src/ssh_cli.erl b/lib/ssh/src/ssh_cli.erl index 69b1ab186f..54911e757c 100644 --- a/lib/ssh/src/ssh_cli.erl +++ b/lib/ssh/src/ssh_cli.erl @@ -68,7 +68,8 @@ init([Shell]) -> handle_ssh_msg({ssh_cm, _ConnectionManager, {data, _ChannelId, _Type, Data}}, #state{group = Group} = State) -> - Group ! {self(), {data, binary_to_list(Data)}}, + List = binary_to_list(Data), + to_group(List, Group), {ok, State}; handle_ssh_msg({ssh_cm, ConnectionManager, @@ -188,6 +189,22 @@ terminate(_Reason, _State) -> %%% Internal functions %%-------------------------------------------------------------------- +to_group([], _Group) -> + ok; +to_group([$\^C | Tail], Group) -> + exit(Group, interrupt), + to_group(Tail, Group); +to_group(Data, Group) -> + Func = fun(C) -> C /= $\^C end, + Tail = case lists:splitwith(Func, Data) of + {[], Right} -> + Right; + {Left, Right} -> + Group ! {self(), {data, Left}}, + Right + end, + to_group(Tail, Group). + exec(Cmd) -> case eval(parse(scan(Cmd))) of {error, _} -> -- cgit v1.2.3