diff options
Diffstat (limited to 'lib')
95 files changed, 2213 insertions, 1503 deletions
diff --git a/lib/compiler/src/beam_ssa_lint.erl b/lib/compiler/src/beam_ssa_lint.erl index a003607dab..224095d4c4 100644 --- a/lib/compiler/src/beam_ssa_lint.erl +++ b/lib/compiler/src/beam_ssa_lint.erl @@ -65,13 +65,19 @@ format_error({{_M,F,A},{phi_inside_block, Name, Id}}) -> [F, A, format_var(Name), Id]); format_error({{_M,F,A},{undefined_label_in_phi, Label, I}}) -> io_lib:format("~p/~p: Unknown block label ~p in phi node ~ts", - [F, A, Label, format_instr(I)]). + [F, A, Label, format_instr(I)]); +format_error({{_M,F,A},{succeeded_not_preceded, I}}) -> + io_lib:format("~p/~p: ~ts does not reference the preceding instruction", + [F, A, format_instr(I)]); +format_error({{_M,F,A},{succeeded_not_last, I}}) -> + io_lib:format("~p/~p: ~ts is not the last instruction in its block", + [F, A, format_instr(I)]). format_instr(I) -> [$',beam_ssa_pp:format_instr(I),$']. format_var(V) -> - beam_ssa_pp:format_var(#b_var{name=V}). + beam_ssa_pp:format_var(V). validate_function(F) -> try @@ -86,34 +92,36 @@ validate_function(F) -> erlang:raise(Class, Error, Stack) end. --type defined_vars() :: gb_sets:set(beam_ssa:var_name()). +-type defined_vars() :: gb_sets:set(beam_ssa:argument()). -record(vvars, {blocks :: #{ beam_ssa:label() => beam_ssa:b_blk() }, branch_def_vars :: #{ - %% Describes the variable state at the time of this exact branch (phi - %% node validation). - {From :: beam_ssa:label(), To :: beam_ssa:label()} => defined_vars(), - %% Describes the variable state common to all branches leading to this - %% label (un/redefined variable validation). - beam_ssa:label() => defined_vars() }, + %% Describes the variable state at the time of + %% this exact branch (phi node validation). + {From :: beam_ssa:label(), + To :: beam_ssa:label()} => defined_vars(), + %% Describes the variable state common to all + %% branches leading to this label (un/redefined + %% variable validation). + beam_ssa:label() => defined_vars() }, defined_vars :: defined_vars()}). -spec validate_variables(beam_ssa:b_function()) -> ok. validate_variables(#b_function{ args = Args, bs = Blocks }) -> %% Prefill the mapping with function arguments. - ArgNames = vvars_get_varnames(Args), - DefVars = gb_sets:from_list(ArgNames), + Args = vvars_get_variables(Args), + DefVars = gb_sets:from_list(Args), Entry = 0, State = #vvars{blocks = Blocks, branch_def_vars = #{ Entry => DefVars }, defined_vars = DefVars}, - ok = vvars_assert_unique(Blocks, ArgNames), + ok = vvars_assert_unique(Blocks, Args), vvars_phi_nodes(vvars_block(Entry, State)). %% Checks the uniqueness of all variables across all blocks. --spec vvars_assert_unique(Blocks, [beam_ssa:var_name()]) -> ok when +-spec vvars_assert_unique(Blocks, [beam_ssa:b_var()]) -> ok when Blocks :: #{ beam_ssa:label() => beam_ssa:b_blk() }. vvars_assert_unique(Blocks, Args) -> BlockIs = [Is || #b_blk{is=Is} <- maps:values(Blocks)], @@ -124,12 +132,12 @@ vvars_assert_unique(Blocks, Args) -> ok. -spec vvars_assert_unique_1(Is, Defined) -> ok when - Is :: list(beam_ssa:b_set()), - Defined :: #{ beam_ssa:var_name() => beam_ssa:b_set() }. -vvars_assert_unique_1([#b_set{dst=#b_var{name=DstName}}=I|Is], Defined) -> + Is :: list(beam_ssa:b_set()), + Defined :: #{ beam_ssa:b_var() => beam_ssa:b_set() }. +vvars_assert_unique_1([#b_set{dst=Dst}=I|Is], Defined) -> case Defined of - #{DstName:=Old} -> throw({redefined_variable, DstName, Old, I}); - _ -> vvars_assert_unique_1(Is, Defined#{DstName=>I}) + #{Dst:=Old} -> throw({redefined_variable, Dst, Old, I}); + _ -> vvars_assert_unique_1(Is, Defined#{Dst=>I}) end; vvars_assert_unique_1([], Defined) -> Defined. @@ -141,17 +149,17 @@ vvars_phi_nodes(#vvars{ blocks = Blocks }=State) -> ok. -spec vvars_phi_nodes_1(Is, Id, State) -> ok when - Is :: list(beam_ssa:b_set()), - Id :: beam_ssa:label(), - State :: #vvars{}. + Is :: list(beam_ssa:b_set()), + Id :: beam_ssa:label(), + State :: #vvars{}. vvars_phi_nodes_1([#b_set{ op = phi, args = Phis }=I | Is], Id, State) -> ok = vvars_assert_phi_paths(Phis, I, Id, State), ok = vvars_assert_phi_vars(Phis, I, Id, State), vvars_phi_nodes_1(Is, Id, State); vvars_phi_nodes_1([_ | Is], Id, _State) -> - case [Dst || #b_set{op=phi,dst=#b_var{name=Dst}} <- Is] of - [Name|_] -> - throw({phi_inside_block, Name, Id}); + case [Dst || #b_set{op=phi,dst=Dst} <- Is] of + [Var|_] -> + throw({phi_inside_block, Var, Id}); [] -> ok end; @@ -161,10 +169,10 @@ vvars_phi_nodes_1([], _Id, _State) -> %% Checks whether all paths leading to this phi node are represented, and that %% it doesn't reference any non-existent paths. -spec vvars_assert_phi_paths(Phis, I, Id, State) -> ok when - Phis :: list({beam_ssa:argument(), beam_ssa:label()}), - Id :: beam_ssa:label(), - I :: beam_ssa:b_set(), - State :: #vvars{}. + Phis :: list({beam_ssa:argument(), beam_ssa:label()}), + Id :: beam_ssa:label(), + I :: beam_ssa:b_set(), + State :: #vvars{}. vvars_assert_phi_paths(Phis, I, Id, State) -> BranchKeys = maps:keys(State#vvars.branch_def_vars), RequiredPaths = ordsets:from_list([From || {From, To} <- BranchKeys, To =:= Id]), @@ -173,34 +181,34 @@ vvars_assert_phi_paths(Phis, I, Id, State) -> [_|_]=MissingPaths -> throw({missing_phi_paths, MissingPaths, I}); [] -> ok end. - %% %% The following test is sometimes useful to find missing optimizations. - %% %% It is commented out, though, because it can be triggered by - %% %% by weird but legal code. - %% case ordsets:subtract(ProvidedPaths, RequiredPaths) of - %% [_|_]=GarbagePaths -> throw({garbage_phi_paths, GarbagePaths, I}); - %% [] -> ok - %% end. +%% %% The following test is sometimes useful to find missing optimizations. +%% %% It is commented out, though, because it can be triggered by +%% %% by weird but legal code. +%% case ordsets:subtract(ProvidedPaths, RequiredPaths) of +%% [_|_]=GarbagePaths -> throw({garbage_phi_paths, GarbagePaths, I}); +%% [] -> ok +%% end. %% Checks whether all variables used in this phi node are defined in the branch %% they arrived on. -spec vvars_assert_phi_vars(Phis, I, Id, State) -> ok when - Phis :: list({beam_ssa:argument(), beam_ssa:label()}), - Id :: beam_ssa:label(), - I :: beam_ssa:b_set(), - State :: #vvars{}. + Phis :: list({beam_ssa:argument(), beam_ssa:label()}), + Id :: beam_ssa:label(), + I :: beam_ssa:b_set(), + State :: #vvars{}. vvars_assert_phi_vars(Phis, I, Id, #vvars{blocks=Blocks, branch_def_vars=BranchDefVars}) -> Vars = [{Var, From} || {#b_var{}=Var, From} <- Phis], - foreach(fun({#b_var{name=VarName}, From}) -> + foreach(fun({Var, From}) -> BranchKey = {From, Id}, case BranchDefVars of #{BranchKey:=DefVars} -> - case gb_sets:is_member(VarName, DefVars) of + case gb_sets:is_member(Var, DefVars) of true -> ok; - false -> throw({unknown_variable, VarName, I}) + false -> throw({unknown_variable, Var, I}) end; #{} -> - throw({unknown_phi_variable, VarName, BranchKey, I}) + throw({unknown_phi_variable, Var, BranchKey, I}) end end, Vars), Labels = [From || {#b_literal{},From} <- Phis], @@ -214,32 +222,44 @@ vvars_assert_phi_vars(Phis, I, Id, #vvars{blocks=Blocks, end, Labels). -spec vvars_block(Id, State) -> #vvars{} when - Id :: beam_ssa:label(), - State :: #vvars{}. + Id :: beam_ssa:label(), + State :: #vvars{}. vvars_block(Id, State0) -> #{ Id := #b_blk{ is = Is, last = Terminator} } = State0#vvars.blocks, #{ Id := DefVars } = State0#vvars.branch_def_vars, State = State0#vvars{ defined_vars = DefVars }, vvars_terminator(Terminator, Id, vvars_block_1(Is, State)). --spec vvars_block_1(Blocks, State) -> #vvars{} when - Blocks :: list(beam_ssa:b_blk()), - State :: #vvars{}. +-spec vvars_block_1(Is, State) -> #vvars{} when + Is :: list(#b_set{}), + State :: #vvars{}. vvars_block_1([], State) -> State; -vvars_block_1([#b_set{ dst = #b_var{ name = DstName }, op = phi } | Is], State0) -> +vvars_block_1([#b_set{dst=OpVar,args=OpArgs}=I, + #b_set{op=succeeded,args=[OpVar],dst=SuccVar}], State) -> + ok = vvars_assert_args(OpArgs, I, State), + vvars_save_var(SuccVar, vvars_save_var(OpVar, State)); +vvars_block_1([#b_set{op=succeeded,args=Args}=I | [_|_]], State) -> + ok = vvars_assert_args(Args, I, State), + %% 'succeeded' must be the last instruction in its block. + throw({succeeded_not_last, I}); +vvars_block_1([#b_set{op=succeeded,args=Args}=I], State)-> + ok = vvars_assert_args(Args, I, State), + %% 'succeeded' must be be directly preceded by the operation it checks. + throw({succeeded_not_preceded, I}); +vvars_block_1([#b_set{ dst = Dst, op = phi } | Is], State) -> %% We don't check phi node arguments at this point since we may not have %% visited their definition yet. They'll be handled later on in %% vvars_phi_nodes/1 after all blocks are processed. - vvars_block_1(Is, vvars_save_var(DstName, State0)); -vvars_block_1([#b_set{ dst = #b_var{ name = DstName }, args = Args }=I | Is], State0) -> - ok = vvars_assert_args(Args, I, State0), - vvars_block_1(Is, vvars_save_var(DstName, State0)). + vvars_block_1(Is, vvars_save_var(Dst, State)); +vvars_block_1([#b_set{ dst = Dst, args = Args }=I | Is], State) -> + ok = vvars_assert_args(Args, I, State), + vvars_block_1(Is, vvars_save_var(Dst, State)). -spec vvars_terminator(Terminator, From, State) -> #vvars{} when - Terminator :: beam_ssa:terminator(), - From :: beam_ssa:label(), - State :: #vvars{}. + Terminator :: beam_ssa:terminator(), + From :: beam_ssa:label(), + State :: #vvars{}. vvars_terminator(#b_ret{ arg = Arg }=I, _From, State) -> ok = vvars_assert_args([Arg], I, State), State; @@ -264,62 +284,62 @@ vvars_terminator(#b_br{ bool = Arg, succ = Succ, fail = Fail }=I, From, State) - vvars_terminator_1(Labels, From, State). -spec vvars_terminator_1(Labels, From, State) -> #vvars{} when - Labels :: list(beam_ssa:label()), - From :: beam_ssa:label(), - State :: #vvars{}. + Labels :: list(beam_ssa:label()), + From :: beam_ssa:label(), + State :: #vvars{}. vvars_terminator_1(Labels0, From, State0) -> %% Filter out all branches that have already been taken. This should result %% in either all of Labels0 or an empty list. Labels = [To || To <- Labels0, - not maps:is_key({From, To}, State0#vvars.branch_def_vars)], + not maps:is_key({From, To}, State0#vvars.branch_def_vars)], true = Labels =:= Labels0 orelse Labels =:= [], %Assertion State1 = foldl(fun(To, State) -> - vvars_save_branch(From, To, State) + vvars_save_branch(From, To, State) end, State0, Labels), foldl(fun(To, State) -> - vvars_block(To, State) + vvars_block(To, State) end, State1, Labels). %% Gets all variable names in args, ignoring literals etc --spec vvars_get_varnames(Args) -> list(beam_ssa:var_name()) when - Args :: list(beam_ssa:argument()). -vvars_get_varnames(Args) -> - [Name || #b_var{ name = Name } <- Args]. +-spec vvars_get_variables(Args) -> list(beam_ssa:b_var()) when + Args :: list(beam_ssa:argument()). +vvars_get_variables(Args) -> + [Var || #b_var{}=Var <- Args]. %% Checks that all variables in Args are defined in all paths leading to the %% current State. -spec vvars_assert_args(Args, I, State) -> ok when - Args :: list(beam_ssa:argument()), - I :: beam_ssa:terminator() | beam_ssa:b_set(), - State :: #vvars{}. + Args :: list(beam_ssa:argument()), + I :: beam_ssa:terminator() | beam_ssa:b_set(), + State :: #vvars{}. vvars_assert_args(Args, I, #vvars{defined_vars=DefVars}=State) -> foreach(fun(#b_remote{mod=Mod,name=Name}) -> vvars_assert_args([Mod,Name], I, State); - (#b_var{name=Name}) -> - case gb_sets:is_member(Name, DefVars) of + (#b_var{}=Var) -> + case gb_sets:is_member(Var, DefVars) of true -> ok; - false -> throw({unknown_variable,Name,I}) + false -> throw({unknown_variable,Var,I}) end; (_) -> ok end, Args). %% Checks that all given labels are defined in State. -spec vvars_assert_labels(Labels, I, State) -> ok when - Labels :: list(beam_ssa:label()), - I :: beam_ssa:terminator(), - State :: #vvars{}. + Labels :: list(beam_ssa:label()), + I :: beam_ssa:terminator(), + State :: #vvars{}. vvars_assert_labels(Labels, I, #vvars{blocks=Blocks}) -> foreach(fun(Label) -> - case maps:is_key(Label, Blocks) of - false -> throw({unknown_block, Label, I}); - true -> ok - end + case maps:is_key(Label, Blocks) of + false -> throw({unknown_block, Label, I}); + true -> ok + end end, Labels). -spec vvars_save_branch(From, To, State) -> #vvars{} when - From :: beam_ssa:label(), - To :: beam_ssa:label(), - State :: #vvars{}. + From :: beam_ssa:label(), + To :: beam_ssa:label(), + State :: #vvars{}. vvars_save_branch(From, To, State) -> DefVars = State#vvars.defined_vars, Branches0 = State#vvars.branch_def_vars, @@ -335,15 +355,15 @@ vvars_save_branch(From, To, State) -> end. -spec vvars_merge_branches(New, Existing) -> defined_vars() when - New :: defined_vars(), - Existing :: defined_vars(). + New :: defined_vars(), + Existing :: defined_vars(). vvars_merge_branches(New, Existing) -> gb_sets:intersection(New, Existing). --spec vvars_save_var(VarName, State) -> #vvars{} when - VarName :: beam_ssa:var_name(), - State :: #vvars{}. -vvars_save_var(VarName, State0) -> +-spec vvars_save_var(Var, State) -> #vvars{} when + Var :: #b_var{}, + State :: #vvars{}. +vvars_save_var(Var, State0) -> %% vvars_assert_unique guarantees that variables are never set twice. - DefVars = gb_sets:insert(VarName, State0#vvars.defined_vars), + DefVars = gb_sets:insert(Var, State0#vvars.defined_vars), State0#vvars{ defined_vars = DefVars }. diff --git a/lib/compiler/src/beam_ssa_pre_codegen.erl b/lib/compiler/src/beam_ssa_pre_codegen.erl index 9847b87b18..61c42fdb6d 100644 --- a/lib/compiler/src/beam_ssa_pre_codegen.erl +++ b/lib/compiler/src/beam_ssa_pre_codegen.erl @@ -603,6 +603,10 @@ bs_instrs([{L,#b_blk{is=Is0}=Blk}|Bs], CtxChain, Acc0) -> bs_instrs([], _, Acc) -> reverse(Acc). +bs_instrs_is([#b_set{op=succeeded}=I|Is], CtxChain, Acc) -> + %% This instruction refers to a specific operation, so we must not + %% substitute the context argument. + bs_instrs_is(Is, CtxChain, [I | Acc]); bs_instrs_is([#b_set{op=Op,args=Args0}=I0|Is], CtxChain, Acc) -> Args = [bs_subst_ctx(A, CtxChain) || A <- Args0], I1 = I0#b_set{args=Args}, @@ -1540,25 +1544,51 @@ fix_receive([], _Defs, Blocks, Count) -> {Blocks,Count}. %% find_loop_exit([Label], Blocks) -> Label | none. -%% Find the block to which control is transferred when the -%% the receive loop is exited. - -find_loop_exit([L1,L2|_Ls], Blocks) -> - Path1 = beam_ssa:rpo([L1], Blocks), - Path2 = beam_ssa:rpo([L2], Blocks), - find_loop_exit_1(Path1, cerl_sets:from_list(Path2)); -find_loop_exit(_, _) -> none. - -find_loop_exit_1([?EXCEPTION_BLOCK | T], OtherPath) -> - %% ?EXCEPTION_BLOCK is a marker and not an actual block, so we can't - %% consider it to be a common block even if both paths cross it. - find_loop_exit_1(T, OtherPath); -find_loop_exit_1([H|T], OtherPath) -> - case cerl_sets:is_element(H, OtherPath) of - true -> H; - false -> find_loop_exit_1(T, OtherPath) +%% Given the list of all blocks with the remove_message instructions +%% for this receive, find the block to which control is transferred +%% when the receive loop is exited (if any). + +find_loop_exit([_,_|_]=RmBlocks, Blocks) -> + %% We used to only analyze the path from two of the remove_message + %% blocks. That would fail to find a common block if one or both + %% of the blocks happened to raise an exception. To be sure that + %% we always find a common block if there is one (shared by at + %% least two clauses), we must analyze the path from all + %% remove_message blocks. + {Dominators,_} = beam_ssa:dominators(Blocks), + RmSet = cerl_sets:from_list(RmBlocks), + Rpo = beam_ssa:rpo(RmBlocks, Blocks), + find_loop_exit_1(Rpo, RmSet, Dominators); +find_loop_exit(_, _) -> + %% There is (at most) a single clause. There is no common + %% loop exit block. + none. + +find_loop_exit_1([?EXCEPTION_BLOCK|Ls], RmSet, Dominators) -> + %% ?EXCEPTION_BLOCK is a marker and not an actual block, so it is not + %% the block we are looking for. + find_loop_exit_1(Ls, RmSet, Dominators); +find_loop_exit_1([L|Ls], RmSet, Dominators) -> + DomBy = map_get(L, Dominators), + case any(fun(E) -> cerl_sets:is_element(E, RmSet) end, DomBy) of + true -> + %% This block is dominated by one of the remove_message blocks, + %% which means that the block is part of only one clause. + %% It is not the block we are looking for. + find_loop_exit_1(Ls, RmSet, Dominators); + false -> + %% This block is the first block that is not dominated by + %% any of the blocks with remove_message instructions, + %% which means that at least two of the receive clauses + %% will ultimately transfer control to it. It is the block + %% we are looking for. + L end; -find_loop_exit_1([], _) -> none. +find_loop_exit_1([], _, _) -> + %% None of clauses transfers control to a common block after the receive + %% statement. That means that the receive statement is a the end of a + %% function (or that all clauses raise exceptions). + none. %% find_rm_blocks(StartLabel, Blocks) -> [Label]. %% Find all blocks that start with remove_message within the receive diff --git a/lib/compiler/src/beam_ssa_type.erl b/lib/compiler/src/beam_ssa_type.erl index 364a87f67e..d93191c689 100644 --- a/lib/compiler/src/beam_ssa_type.erl +++ b/lib/compiler/src/beam_ssa_type.erl @@ -481,17 +481,12 @@ simplify(#b_set{op={bif,Op},args=Args}=I, Ts) -> eval_bif(beam_ssa:add_anno(float_op, AnnoArgs, I), Ts) end; simplify(#b_set{op=get_tuple_element,args=[Tuple,#b_literal{val=N}]}=I, Ts) -> - case normalized_type(Tuple, Ts) of - #t_tuple{size=Size,elements=Es} when Size > N -> - ElemType = beam_types:get_element_type(N + 1, Es), - case beam_types:get_singleton_value(ElemType) of - {ok, Val} -> #b_literal{val=Val}; - error -> I - end; - none -> - %% Will never be executed because of type conflict. - %% #b_literal{val=ignored}; - I + #t_tuple{size=Size,elements=Es} = normalized_type(Tuple, Ts), + true = Size > N, %Assertion. + ElemType = beam_types:get_element_type(N + 1, Es), + case beam_types:get_singleton_value(ElemType) of + {ok, Val} -> #b_literal{val=Val}; + error -> I end; simplify(#b_set{op=is_nonempty_list,args=[Src]}=I, Ts) -> case normalized_type(Src, Ts) of diff --git a/lib/compiler/src/v3_kernel.erl b/lib/compiler/src/v3_kernel.erl index 6fd1790c1a..49fb66126f 100644 --- a/lib/compiler/src/v3_kernel.erl +++ b/lib/compiler/src/v3_kernel.erl @@ -91,6 +91,7 @@ -include("core_parse.hrl"). -include("v3_kernel.hrl"). +-define(EXPAND_MAX_SIZE_SEGMENT, 1024). %% These are not defined in v3_kernel.hrl. get_kanno(Kthing) -> element(2, Kthing). @@ -1170,7 +1171,7 @@ validate_bin_element_size(#k_int{val=V}) when V >= 0 -> ok; validate_bin_element_size(#k_atom{val=all}) -> ok; validate_bin_element_size(#k_atom{val=undefined}) -> ok; validate_bin_element_size(_) -> throw(bad_element_size). - + %% atomic_list([Cexpr], Sub, State) -> {[Kexpr],[PreKexpr],State}. atomic_list(Ces, Sub, St) -> @@ -1296,14 +1297,63 @@ pattern_bin_1([#c_bitstr{anno=A,val=E0,size=S0,unit=U,type=T,flags=Fs}|Es0], _ -> Isub0 end, {Es,{Isub,Osub},St3} = pattern_bin_1(Es0, Isub1, Osub1, St2), - {#k_bin_seg{anno=A,size=S, - unit=U0, - type=cerl:concrete(T), - flags=Fs0, - seg=E,next=Es}, - {Isub,Osub},St3}; + {build_bin_seg(A, S, U0, cerl:concrete(T), Fs0, E, Es),{Isub,Osub},St3}; pattern_bin_1([], Isub, Osub, St) -> {#k_bin_end{},{Isub,Osub},St}. +%% build_bin_seg(Anno, Size, Unit, Type, Flags, Seg, Next) -> #k_bin_seg{}. +%% This function normalizes literal integers with size > 8 and literal +%% utf8 segments into integers with size = 8 (and potentially an integer +%% with size less than 8 at the end). This is so further optimizations +%% have a normalized view of literal integers, allowing us to generate +%% more literals and group more clauses. Those integers may be "squeezed" +%% later into the largest integer possible. +%% +build_bin_seg(A, #k_int{val=Bits} = Sz, U, integer=Type, [unsigned,big]=Flags, #k_literal{val=Int}=Seg, Next) -> + Size = Bits * U, + case integer_fits_and_is_expandable(Int, Size) of + true -> build_bin_seg_integer_recur(A, Size, Int, Next); + false -> #k_bin_seg{anno=A,size=Sz,unit=U,type=Type,flags=Flags,seg=Seg,next=Next} + end; +build_bin_seg(A, Sz, U, utf8=Type, [unsigned,big]=Flags, #k_literal{val=Utf8} = Seg, Next) -> + case utf8_fits(Utf8) of + {Int, Bits} -> build_bin_seg_integer_recur(A, Bits, Int, Next); + error -> #k_bin_seg{anno=A,size=Sz,unit=U,type=Type,flags=Flags,seg=Seg,next=Next} + end; +build_bin_seg(A, Sz, U, Type, Flags, Seg, Next) -> + #k_bin_seg{anno=A,size=Sz,unit=U,type=Type,flags=Flags,seg=Seg,next=Next}. + +build_bin_seg_integer_recur(A, Bits, Val, Next) when Bits > 8 -> + NextBits = Bits - 8, + NextVal = Val band ((1 bsl NextBits) - 1), + Last = build_bin_seg_integer_recur(A, NextBits, NextVal, Next), + build_bin_seg_integer(A, 8, Val bsr NextBits, Last); + +build_bin_seg_integer_recur(A, Bits, Val, Next) -> + build_bin_seg_integer(A, Bits, Val, Next). + +build_bin_seg_integer(A, Bits, Val, Next) -> + Sz = #k_int{anno=A,val=Bits}, + Seg = #k_literal{anno=A,val=Val}, + #k_bin_seg{anno=A,size=Sz,unit=1,type=integer,flags=[unsigned,big],seg=Seg,next=Next}. + +integer_fits_and_is_expandable(Int, Size) when 0 < Size, Size =< ?EXPAND_MAX_SIZE_SEGMENT -> + case <<Int:Size>> of + <<Int:Size>> -> true; + _ -> false + end; +integer_fits_and_is_expandable(_Int, _Size) -> + false. + +utf8_fits(Utf8) -> + try + Bin = <<Utf8/utf8>>, + Bits = bit_size(Bin), + <<Int:Bits>> = Bin, + {Int, Bits} + catch + _:_ -> error + end. + %% pattern_list([Cexpr], Sub, State) -> {[Kexpr],Sub,State}. pattern_list(Ces, Sub, St) -> @@ -1553,7 +1603,7 @@ maybe_add_warning(Ke, MatchAnno, St) -> get_line([Line|_]) when is_integer(Line) -> Line; get_line([_|T]) -> get_line(T); get_line([]) -> none. - + get_file([{file,File}|_]) -> File; get_file([_|T]) -> get_file(T); get_file([]) -> "no_file". % should not happen @@ -1761,27 +1811,10 @@ do_combine_lit_pat(#k_tuple{anno=A,es=Es0}) -> do_combine_lit_pat(_) -> throw(not_possible). -combine_bin_segs(#k_bin_seg{size=Size0,unit=Unit,type=integer, - flags=[unsigned,big],seg=Seg,next=Next}) -> - #k_literal{val=Size1} = do_combine_lit_pat(Size0), - #k_literal{val=Int} = do_combine_lit_pat(Seg), - Size = Size1 * Unit, - if - 0 < Size, Size < 64 -> - Bin = <<Int:Size>>, - case Bin of - <<Int:Size>> -> - NextBin = combine_bin_segs(Next), - <<Bin/bits,NextBin/bits>>; - _ -> - %% The integer Int does not fit in the segment, - %% thus it will not match. - throw(not_possible) - end; - true -> - %% Avoid creating huge binary literals. - throw(not_possible) - end; +combine_bin_segs(#k_bin_seg{size=#k_int{val=8},unit=1,type=integer, + flags=[unsigned,big],seg=#k_literal{val=Int},next=Next}) + when is_integer(Int), 0 =< Int, Int =< 255 -> + <<Int,(combine_bin_segs(Next))/bits>>; combine_bin_segs(#k_bin_end{}) -> <<>>; combine_bin_segs(_) -> @@ -1851,11 +1884,10 @@ handle_bin_con_not_possible([]) -> []. select_bin_int([#iclause{pats=[#k_bin_seg{anno=A,type=integer, size=#k_int{val=Bits0}=Sz,unit=U, flags=Fl,seg=#k_literal{val=Val}, - next=N}|Ps]}=C|Cs0]) - when is_integer(Val) -> + next=N}|Ps]}=C|Cs0]) -> Bits = U * Bits0, if - Bits > 1024 -> throw(not_possible); %Expands the code too much. + Bits > ?EXPAND_MAX_SIZE_SEGMENT -> throw(not_possible); %Expands the code too much. true -> ok end, select_assert_match_possible(Bits, Val, Fl), @@ -1866,16 +1898,6 @@ select_bin_int([#iclause{pats=[#k_bin_seg{anno=A,type=integer, end, Cs = select_bin_int_1(Cs0, Bits, Fl, Val), [{k_bin_int,[C#iclause{pats=[P|Ps]}|Cs]}]; -select_bin_int([#iclause{pats=[#k_bin_seg{anno=A,type=utf8, - flags=[unsigned,big]=Fl, - seg=#k_literal{val=Val0}, - next=N}|Ps]}=C|Cs0]) - when is_integer(Val0) -> - {Val,Bits} = select_utf8(Val0), - P = #k_bin_int{anno=A,size=#k_int{val=Bits},unit=1, - flags=Fl,val=Val,next=N}, - Cs = select_bin_int_1(Cs0, Bits, Fl, Val), - [{k_bin_int,[C#iclause{pats=[P|Ps]}|Cs]}]; select_bin_int(_) -> throw(not_possible). select_bin_int_1([#iclause{pats=[#k_bin_seg{anno=A,type=integer, @@ -1890,18 +1912,6 @@ select_bin_int_1([#iclause{pats=[#k_bin_seg{anno=A,type=integer, end, P = #k_bin_int{anno=A,size=Sz,unit=U,flags=Fl,val=Val,next=N}, [C#iclause{pats=[P|Ps]}|select_bin_int_1(Cs, Bits, Fl, Val)]; -select_bin_int_1([#iclause{pats=[#k_bin_seg{anno=A,type=utf8, - flags=Fl, - seg=#k_literal{val=Val0}, - next=N}|Ps]}=C|Cs], - Bits, Fl, Val) when is_integer(Val0) -> - case select_utf8(Val0) of - {Val,Bits} -> ok; - {_,_} -> throw(not_possible) - end, - P = #k_bin_int{anno=A,size=#k_int{val=Bits},unit=1, - flags=[unsigned,big],val=Val,next=N}, - [C#iclause{pats=[P|Ps]}|select_bin_int_1(Cs, Bits, Fl, Val)]; select_bin_int_1([], _, _, _) -> []; select_bin_int_1(_, _, _, _) -> throw(not_possible). @@ -1927,17 +1937,6 @@ match_fun(Val) -> {match,Bs} end. -select_utf8(Val0) -> - try - Bin = <<Val0/utf8>>, - Size = bit_size(Bin), - <<Val:Size>> = Bin, - {Val,Size} - catch - error:_ -> - throw(not_possible) - end. - %% match_value([Var], Con, [Clause], Default, State) -> {SelectExpr,State}. %% At this point all the clauses have the same constructor, we must %% now separate them according to value. @@ -2057,7 +2056,8 @@ match_clause([U|Us], [C|_]=Cs0, Def, St0) -> {Match0,Vs,St1} = get_match(get_con(Cs0), St0), Match = sub_size_var(Match0, Cs0), {Cs1,St2} = new_clauses(Cs0, U, St1), - {B,St3} = match(Vs ++ Us, Cs1, Def, St2), + Cs2 = squeeze_clauses_by_bin_integer_count(Cs1, []), + {B,St3} = match(Vs ++ Us, Cs2, Def, St2), {#k_val_clause{anno=Anno,val=Match,body=B},St3}. sub_size_var(#k_bin_seg{size=#k_var{name=Name}=Kvar}=BinSeg, [#iclause{isub=Sub}|_]) -> @@ -2127,6 +2127,102 @@ new_clauses(Cs0, U, St) -> end, Cs0), {Cs1,St}. +%% group and squeeze +%% The goal of those functions is to group subsequent integer k_bin_seg +%% literals by count so we can leverage bs_get_integer_16 whenever possible. +%% +%% The priority is to create large groups. So if we have three clauses matching +%% on 16-bits/16-bits/8-bits, we will first have a single 8-bits match for all +%% three clauses instead of clauses (one with 16 and another with 8). But note +%% the algorithm is recursive, so the remaining 8-bits for the first two clauses +%% will be grouped next. +%% +%% We also try to not create too large groups. If we have too many clauses, +%% it is preferrable to match on 8-bits, select a branch, then match on the +%% next 8-bits, rather than match on 16-bits which would force us to have +%% to select to many values at the same time, which would not be efficient. +%% +%% Another restriction is that we create groups only if the end of the +%% group is a variadic clause or the end of the binary. That's because +%% if we have 16-bits/16-bits/catch-all, breaking it into a 16-bits lookup +%% will make the catch-all more expensive. +%% +%% Clauses are grouped in reverse when squeezing and then flattened and +%% re-reversed at the end. +squeeze_clauses_by_bin_integer_count([Clause | Clauses], Acc) -> + case clause_count_bin_integer_segments(Clause) of + {literal, N} -> squeeze_clauses_by_bin_integer_count(Clauses, N, 1, [Clause], Acc); + _ -> squeeze_clauses_by_bin_integer_count(Clauses, [[Clause] | Acc]) + end; +squeeze_clauses_by_bin_integer_count(_, Acc) -> + flat_reverse(Acc, []). + +squeeze_clauses_by_bin_integer_count([], N, Count, GroupAcc, Acc) -> + Squeezed = squeeze_clauses(GroupAcc, fix_count_without_variadic_segment(N), Count), + flat_reverse([Squeezed | Acc], []); +squeeze_clauses_by_bin_integer_count([#iclause{pats=[#k_bin_end{} | _]} = Clause], N, Count, GroupAcc, Acc) -> + Squeezed = squeeze_clauses(GroupAcc, fix_count_without_variadic_segment(N), Count), + flat_reverse([[Clause | Squeezed] | Acc], []); +squeeze_clauses_by_bin_integer_count([Clause | Clauses], N, Count, GroupAcc, Acc) -> + case clause_count_bin_integer_segments(Clause) of + {literal, NewN} -> + squeeze_clauses_by_bin_integer_count(Clauses, min(N, NewN), Count + 1, [Clause | GroupAcc], Acc); + + {variadic, NewN} when NewN =< N -> + Squeezed = squeeze_clauses(GroupAcc, NewN, Count), + squeeze_clauses_by_bin_integer_count(Clauses, [[Clause | Squeezed] | Acc]); + + _ -> + squeeze_clauses_by_bin_integer_count(Clauses, [[Clause | GroupAcc] | Acc]) + end. + +clause_count_bin_integer_segments(#iclause{pats=[#k_bin_seg{seg=#k_literal{}} = BinSeg | _]}) -> + count_bin_integer_segments(BinSeg, 0); +clause_count_bin_integer_segments(#iclause{pats=[#k_bin_seg{size=#k_int{val=Size},unit=Unit, + type=integer,flags=[unsigned,big], seg=#k_var{}} | _]}) + when ((Size * Unit) rem 8) =:= 0 -> + {variadic, (Size * Unit) div 8}; +clause_count_bin_integer_segments(_) -> + error. + +count_bin_integer_segments(#k_bin_seg{size=#k_int{val=8},unit=1,type=integer,flags=[unsigned,big], + seg=#k_literal{val=Int},next=Next}, Count) when is_integer(Int), 0 =< Int, Int =< 255 -> + count_bin_integer_segments(Next, Count + 1); +count_bin_integer_segments(_, Count) when Count > 0 -> + {literal, Count}; +count_bin_integer_segments(_, _Count) -> + error. + +%% Since 4 bytes in on 32-bits systems are bignums, we convert +%% anything more than 3 into 2 bytes lookup. The goal is to convert +%% any multi-clause segment into 2-byte lookups with a potential +%% 3 byte lookup at the end. +fix_count_without_variadic_segment(N) when N > 3 -> 2; +fix_count_without_variadic_segment(N) -> N. + +%% If we have more than 16 clauses, then it is better +%% to branch multiple times than getting a large integer. +%% We also abort if we have nothing to squeeze. +squeeze_clauses(Clauses, Size, Count) when Count >= 16; Size == 1 -> Clauses; +squeeze_clauses(Clauses, Size, _Count) -> squeeze_clauses(Clauses, Size). + +squeeze_clauses([#iclause{pats=[#k_bin_seg{seg=#k_literal{}} = BinSeg | Pats]} = Clause | Clauses], Size) -> + [Clause#iclause{pats=[squeeze_segments(BinSeg, 0, 0, Size) | Pats]} | + squeeze_clauses(Clauses, Size)]; +squeeze_clauses([], _Size) -> + []. + +squeeze_segments(#k_bin_seg{size=Sz, seg=#k_literal{val=Val}=Lit} = BinSeg, Acc, Size, 1) -> + BinSeg#k_bin_seg{size=Sz#k_int{val=Size + 8}, seg=Lit#k_literal{val=(Acc bsl 8) bor Val}}; +squeeze_segments(#k_bin_seg{seg=#k_literal{val=Val},next=Next}, Acc, Size, Count) -> + squeeze_segments(Next, (Acc bsl 8) bor Val, Size + 8, Count - 1). + +flat_reverse([Head | Tail], Acc) -> flat_reverse(Tail, flat_reverse_1(Head, Acc)); +flat_reverse([], Acc) -> Acc. + +flat_reverse_1([Head | Tail], Acc) -> flat_reverse_1(Tail, [Head | Acc]); +flat_reverse_1([], Acc) -> Acc. + %% build_guard([GuardClause]) -> GuardExpr. build_guard([]) -> fail; diff --git a/lib/compiler/test/beam_except_SUITE.erl b/lib/compiler/test/beam_except_SUITE.erl index 67947dc292..f52239f2a8 100644 --- a/lib/compiler/test/beam_except_SUITE.erl +++ b/lib/compiler/test/beam_except_SUITE.erl @@ -72,11 +72,25 @@ bs_get_tail(Config) -> {function_clause, [{?MODULE,bs_get_tail_1,[<<>>,0,0,Config],_}|_]}} = (catch bs_get_tail_1(id(<<>>), 0, 0, Config)), + + ok = bs_get_tail_2(<<"W">>, <<"X">>, <<"Z">>), + ok = bs_get_tail_2(<<"M">>, <<"X">>, <<"Z">>), + {'EXIT', + {function_clause, + [{?MODULE,do_get_bs_tail_2,[<<"A">>,<<"B">>,[],<<"C">>],_}|_]}} = + (catch bs_get_tail_2(<<"A">>, <<"B">>, <<"C">>)), + ok. bs_get_tail_1(<<_:32, Rest/binary>>, Z1, Z2, F1) -> {Rest,Z1,Z2,F1}. +bs_get_tail_2(A, B, C) -> + do_get_bs_tail_2(A, B, [], C). + +do_get_bs_tail_2(<<"W">>, <<"X">>, _, <<"Z">>) -> ok; +do_get_bs_tail_2(<<"M">>, <<"X">>, _, <<"Z">>) -> ok. + coverage(_) -> File = {file,"fake.erl"}, ok = fc(a), diff --git a/lib/compiler/test/beam_ssa_SUITE.erl b/lib/compiler/test/beam_ssa_SUITE.erl index 72e55ae9ec..054f86731a 100644 --- a/lib/compiler/test/beam_ssa_SUITE.erl +++ b/lib/compiler/test/beam_ssa_SUITE.erl @@ -200,6 +200,8 @@ recv(_Config) -> %% tricky_recv_6/0 is a compile-time error. tricky_recv_6(), + recv_coverage(), + ok. sync_wait_mon({Pid, Ref}, Timeout) -> @@ -337,6 +339,69 @@ tricky_recv_6() -> ok end. +recv_coverage() -> + self() ! 1, + a = recv_coverage_1(), + self() ! 2, + b = recv_coverage_1(), + + self() ! 1, + a = recv_coverage_2(), + self() ! 2, + b = recv_coverage_2(), + + ok. + +%% Similar to tricky_recv_5/0, but provides test coverage for the #b_switch{} +%% terminator. +recv_coverage_1() -> + receive + X=1 -> + %% Jump to common exit block through #b_switch{list=L} + case id(0) of + 0 -> a; + 1 -> b; + 2 -> c; + 3 -> d + end; + X=2 -> + %% Jump to common exit block through #b_switch{fail=F} + case id(42) of + 0 -> exit(quit); + 1 -> exit(quit); + 2 -> exit(quit); + 3 -> exit(quit); + _ -> b + end + end, + case X of + 1 -> a; + 2 -> b + end. + +%% Similar to recv_coverage_1/0, providing test coverage for #b_br{}. +recv_coverage_2() -> + receive + X=1 -> + A = id(1), + %% Jump to common exit block through #b_br{succ=S}. + if + A =:= 1 -> a; + true -> exit(quit) + end; + X=2 -> + A = id(2), + %% Jump to common exit block through #b_br{fail=F}. + if + A =:= 1 -> exit(quit); + true -> a + end + end, + case X of + 1 -> a; + 2 -> b + end. + maps(_Config) -> {'EXIT',{{badmatch,#{}},_}} = (catch maps_1(any)), ok. diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl index 145a50f4ad..0dc1d64eeb 100644 --- a/lib/compiler/test/bs_match_SUITE.erl +++ b/lib/compiler/test/bs_match_SUITE.erl @@ -24,7 +24,7 @@ -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, init_per_testcase/2,end_per_testcase/2, - verify_highest_opcode/1, + verify_highest_opcode/1, expand_and_squeeze/1, size_shadow/1,int_float/1,otp_5269/1,null_fields/1,wiger/1, bin_tail/1,save_restore/1, partitioned_bs_match/1,function_clause/1, @@ -64,7 +64,7 @@ groups() -> [{p,[], [verify_highest_opcode, size_shadow,int_float,otp_5269,null_fields,wiger, - bin_tail,save_restore, + bin_tail,save_restore,expand_and_squeeze, partitioned_bs_match,function_clause,unit, shared_sub_bins,bin_and_float,dec_subidentifiers, skip_optional_tag,decode_integer,wfbm,degenerated_match,bs_sum, @@ -2021,3 +2021,161 @@ do_exceptions_after_match_failure(Other) -> ok. id(I) -> I. + +expand_and_squeeze(Config) when is_list(Config) -> + %% UTF8 literals are expanded and then squeezed into integer16 + [ + {test,bs_get_integer2,_,_,[_,{integer,16}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<$á/utf8,_/binary>>"), + ?Q("<<$é/utf8,_/binary>>") + ]), + + %% Sized integers are expanded and then squeezed into integer16 + [ + {test,bs_get_integer2,_,_,[_,{integer,16}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<0:32,_/binary>>"), + ?Q("<<\"bbbb\",_/binary>>") + ]), + + %% Groups of 8 bits are squeezed into integer16 + [ + {test,bs_get_integer2,_,_,[_,{integer,16}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<\"aaaa\",_/binary>>"), + ?Q("<<\"bbbb\",_/binary>>") + ]), + + %% Groups of 8 bits with empty binary are also squeezed + [ + {test,bs_get_integer2,_,_,[_,{integer,16}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<\"aaaa\",_/binary>>"), + ?Q("<<\"bbbb\",_/binary>>"), + ?Q("<<>>") + ]), + + %% Groups of 8 bits with float lookup are not squeezed + [ + {test,bs_get_integer2,_,_,[_,{integer,8}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<\"aaaa\",_/binary>>"), + ?Q("<<\"bbbb\",_/binary>>"), + ?Q("<<_/float>>") + ]), + + %% Groups of diverse bits go with minimum possible + [ + {test,bs_get_integer2,_,_,[_,{integer,8}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<\"aa\",_/binary>>"), + ?Q("<<\"bb\",_/binary>>"), + ?Q("<<\"c\",_/binary>>") + ]), + + %% Groups of diverse bits go with minimum possible but are recursive... + [ + {test,bs_get_integer2,_,_,[_,{integer,8}|_],_} + | RestDiverse + ] = binary_match_to_asm([ + ?Q("<<\"aaa\",_/binary>>"), + ?Q("<<\"abb\",_/binary>>"), + ?Q("<<\"c\",_/binary>>") + ]), + + %% so we still perform a 16 bits lookup for the remaining + true = lists:any(fun({test,bs_get_integer2,_,_,[_,{integer,16}|_],_}) -> true; + (_) -> false end, RestDiverse), + + %% Large match is kept as is if there is a sized match later + [ + {test,bs_get_integer2,_,_,[_,{integer,64}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<255,255,255,255,255,255,255,255>>"), + ?Q("<<_:64>>") + ]), + + %% Large match is kept as is with large matches before and after + [ + {test,bs_get_integer2,_,_,[_,{integer,32}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<A:32,_:A>>"), + ?Q("<<0:32>>"), + ?Q("<<_:32>>") + ]), + + %% Large match is kept as is with large matches before and after + [ + {test,bs_get_integer2,_,_,[_,{integer,32}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<A:32,_:A>>"), + ?Q("<<0,0,0,0>>"), + ?Q("<<_:32>>") + ]), + + %% Large match is kept as is with smaller but still large matches before and after + [ + {test,bs_get_integer2,_,_,[_,{integer,32}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<A:32, _:A>>"), + ?Q("<<0:64>>"), + ?Q("<<_:32>>") + ]), + + %% There is no squeezing for groups with more than 16 matches + [ + {test,bs_get_integer2,_,_,[_,{integer,8}|_],_} + | _ + ] = binary_match_to_asm([ + ?Q("<<\"aa\", _/binary>>"), + ?Q("<<\"bb\", _/binary>>"), + ?Q("<<\"cc\", _/binary>>"), + ?Q("<<\"dd\", _/binary>>"), + ?Q("<<\"ee\", _/binary>>"), + ?Q("<<\"ff\", _/binary>>"), + ?Q("<<\"gg\", _/binary>>"), + ?Q("<<\"hh\", _/binary>>"), + ?Q("<<\"ii\", _/binary>>"), + ?Q("<<\"jj\", _/binary>>"), + ?Q("<<\"kk\", _/binary>>"), + ?Q("<<\"ll\", _/binary>>"), + ?Q("<<\"mm\", _/binary>>"), + ?Q("<<\"nn\", _/binary>>"), + ?Q("<<\"oo\", _/binary>>"), + ?Q("<<\"pp\", _/binary>>") + ]), + + ok. + +binary_match_to_asm(Matches) -> + Clauses = [ + begin + Ann = element(2, Match), + {clause,Ann,[Match],[],[{integer,Ann,Return}]} + end || {Match,Return} <- lists:zip(Matches, lists:seq(1, length(Matches))) + ], + + Module = [ + {attribute,1,module,match_to_asm}, + {attribute,2,export,[{example,1}]}, + {function,3,example,1,Clauses} + ], + + {ok,match_to_asm,{match_to_asm,_Exports,_Attrs,Funs,_},_} = + compile:forms(Module, [return, to_asm]), + + [{function,example,1,2,AllInstructions}|_] = Funs, + [{label,_},{line,_},{func_info,_,_,_},{label,_},{'%',_}, + {test,bs_start_match3,_,_,_,_},{bs_get_position,_,_,_}|Instructions] = AllInstructions, + Instructions. diff --git a/lib/compiler/test/misc_SUITE.erl b/lib/compiler/test/misc_SUITE.erl index eb60dc049d..20fadc4fdb 100644 --- a/lib/compiler/test/misc_SUITE.erl +++ b/lib/compiler/test/misc_SUITE.erl @@ -274,14 +274,34 @@ silly_coverage(Config) when is_list(Config) -> bad_ssa_lint_input() -> {b_module,#{},t, - [{foobar,1},{module_info,0},{module_info,1}], + [{a,1},{b,1},{c,1},{module_info,0},{module_info,1}], [], [{b_function, - #{func_info => {t,foobar,1},location => {"t.erl",4}}, + #{func_info => {t,a,1},location => {"t.erl",4}}, [{b_var,0}], #{0 => {b_blk,#{},[],{b_ret,#{},{b_var,'@undefined_var'}}}}, 3}, {b_function, + #{func_info => {t,b,1},location => {"t.erl",5}}, + [{b_var,0}], + #{0 => + {b_blk,#{}, + [{b_set,#{},{b_var,'@first_var'},first_op,[]}, + {b_set,#{},{b_var,'@second_var'},second_op,[]}, + {b_set,#{},{b_var,'@ret'},succeeded,[{b_var,'@first_var'}]}], + {b_ret,#{},{b_var,'@ret'}}}}, + 3}, + {b_function, + #{func_info => {t,c,1},location => {"t.erl",6}}, + [{b_var,0}], + #{0 => + {b_blk,#{}, + [{b_set,#{},{b_var,'@first_var'},first_op,[]}, + {b_set,#{},{b_var,'@ret'},succeeded,[{b_var,'@first_var'}]}, + {b_set,#{},{b_var,'@second_var'},second_op,[]}], + {b_ret,#{},{b_var,'@ret'}}}}, + 3}, + {b_function, #{func_info => {t,module_info,0}}, [], #{0 => diff --git a/lib/compiler/test/receive_SUITE.erl b/lib/compiler/test/receive_SUITE.erl index 752491f0f8..8cd864c59e 100644 --- a/lib/compiler/test/receive_SUITE.erl +++ b/lib/compiler/test/receive_SUITE.erl @@ -431,6 +431,20 @@ elusive_common_exit(_Config) -> self() ! {1, a}, self() ! {2, b}, {[z], [{2,b},{1,a}]} = elusive_loop([x,y,z], 2, []), + + CodeServer = whereis(code_server), + Self = self(), + Self ! {Self, abc}, + Self ! {CodeServer, []}, + Self ! {Self, other}, + try elusive2([]) of + Unexpected -> + ct:fail("Expected an exception; got ~p\n", [Unexpected]) + catch + throw:[other, CodeServer, Self] -> + ok + end, + ok. elusive_loop(List, 0, Results) -> @@ -449,4 +463,25 @@ elusive_loop(List, ToReceive, Results) -> %% that it would not insert all necessary copy instructions. elusive_loop(RemList, ToReceive-1, [Result | Results]). + +elusive2(Acc) -> + receive + {Pid, abc} -> + ok; + {Pid, []} -> + ok; + {Pid, Res} -> + %% beam_ssa_pre_codegen:find_loop_exit/2 attempts to find + %% the first block of the common code after the receive + %% statement. It used to only look at the two last clauses + %% of the receive. In this function, the last two clauses + %% don't have any common block, so it would be assumed + %% that there was no common block for any of the + %% clauses. That would mean that copy instructions would + %% not be inserted as needed. + throw([Res | Acc]) + end, + %% Common code. + elusive2([Pid | Acc]). + id(I) -> I. diff --git a/lib/edoc/src/edoc.app.src b/lib/edoc/src/edoc.app.src index 43343e2ae8..834c0eb005 100644 --- a/lib/edoc/src/edoc.app.src +++ b/lib/edoc/src/edoc.app.src @@ -23,4 +23,4 @@ {applications, [compiler,kernel,stdlib,syntax_tools]}, {env, []}, {runtime_dependencies, ["xmerl-1.3.7","syntax_tools-1.6.14","stdlib-2.5", - "kernel-3.0","inets-5.10","erts-6.0"]}]}. + "kernel-3.0","erts-6.0"]}]}. diff --git a/lib/edoc/src/edoc.erl b/lib/edoc/src/edoc.erl index 62483602aa..0fdc818fae 100644 --- a/lib/edoc/src/edoc.erl +++ b/lib/edoc/src/edoc.erl @@ -259,10 +259,9 @@ opt_negations() -> %% </dd> %% <dt>{@type {doc_path, [string()]@}} %% </dt> -%% <dd>Specifies a list of URI:s pointing to directories that contain -%% EDoc-generated documentation. URI without a `scheme://' part are -%% taken as relative to `file://'. (Note that such paths must use -%% `/' as separator, regardless of the host operating system.) +%% <dd>Specifies a list of file system paths pointing to directories that +%% contain EDoc-generated documentation. All paths for applications +%% in the code path are automatically added. %% </dd> %% <dt>{@type {doclet, Module::atom()@}} %% </dt> diff --git a/lib/edoc/src/edoc_lib.erl b/lib/edoc/src/edoc_lib.erl index d00a283794..5959fa6f08 100644 --- a/lib/edoc/src/edoc_lib.erl +++ b/lib/edoc/src/edoc_lib.erl @@ -32,12 +32,12 @@ -export([count/2, lines/1, split_at/2, split_at_stop/1, split_at_space/1, filename/1, transpose/1, segment/2, get_first_sentence/1, is_space/1, strip_space/1, parse_expr/2, - parse_contact/2, escape_uri/1, join_uri/2, is_relative_uri/1, + parse_contact/2, escape_uri/1, join_uri/2, is_name/1, to_label/1, find_doc_dirs/0, find_sources/2, find_file/2, try_subdir/2, unique/1, write_file/3, write_file/4, write_info_file/3, read_info_file/1, get_doc_env/1, get_doc_env/3, copy_file/2, - uri_get/1, run_doclet/2, run_layout/2, + run_doclet/2, run_layout/2, simplify_path/1, timestr/1, datestr/1, read_encoding/2]). -import(edoc_report, [report/2, warning/2]). @@ -438,128 +438,6 @@ join_uri("", Path) -> join_uri(Base, Path) -> Base ++ "/" ++ Path. -%% Check for relative URI; "network paths" ("//...") not included! - -%% @private -is_relative_uri([$: | _]) -> - false; -is_relative_uri([$/, $/ | _]) -> - false; -is_relative_uri([$/ | _]) -> - true; -is_relative_uri([$? | _]) -> - true; -is_relative_uri([$# | _]) -> - true; -is_relative_uri([_ | Cs]) -> - is_relative_uri(Cs); -is_relative_uri([]) -> - true. - -%% @private -uri_get("file:///" ++ Path) -> - uri_get_file(Path); -uri_get("file://localhost/" ++ Path) -> - uri_get_file(Path); -uri_get("file://" ++ Path) -> - Msg = io_lib:format("cannot handle 'file:' scheme with " - "nonlocal network-path: 'file://~ts'.", - [Path]), - {error, Msg}; -uri_get("file:/" ++ Path) -> - uri_get_file(Path); -uri_get("file:" ++ Path) -> - Msg = io_lib:format("ignoring malformed URI: 'file:~ts'.", [Path]), - {error, Msg}; -uri_get("http:" ++ Path) -> - uri_get_http("http:" ++ Path); -uri_get("ftp:" ++ Path) -> - uri_get_ftp("ftp:" ++ Path); -uri_get("//" ++ Path) -> - Msg = io_lib:format("cannot access network-path: '//~ts'.", [Path]), - {error, Msg}; -uri_get([C, $:, $/ | _]=Path) when C >= $A, C =< $Z; C >= $a, C =< $z -> - uri_get_file(Path); % special case for Windows -uri_get([C, $:, $\ | _]=Path) when C >= $A, C =< $Z; C >= $a, C =< $z -> - uri_get_file(Path); % special case for Windows -uri_get(URI) -> - case is_relative_uri(URI) of - true -> - uri_get_file(URI); - false -> - Msg = io_lib:format("cannot handle URI: '~ts'.", [URI]), - {error, Msg} - end. - -uri_get_file(File0) -> - File = filename:join(?FILE_BASE, File0), - case read_file(File) of - {ok, Text} -> - {ok, Text}; - {error, R} -> - {error, file:format_error(R)} - end. - -uri_get_http(URI) -> - %% Try using option full_result=false - case catch {ok, httpc:request(get, {URI,[]}, [], - [{full_result, false}])} of - {'EXIT', _} -> - uri_get_http_r10(URI); - Result -> - uri_get_http_1(Result, URI) - end. - -uri_get_http_r10(URI) -> - %% Try most general form of request - Result = (catch {ok, httpc:request(get, {URI,[]}, [], [])}), - uri_get_http_1(Result, URI). - -uri_get_http_1(Result, URI) -> - case Result of - {ok, {ok, {200, Text}}} when is_list(Text) -> - %% new short result format - {ok, Text}; - {ok, {ok, {Status, Text}}} when is_integer(Status), is_list(Text) -> - %% new short result format when status /= 200 - Phrase = httpd_util:reason_phrase(Status), - {error, http_errmsg(Phrase, URI)}; - {ok, {ok, {{_Vsn, 200, _Phrase}, _Hdrs, Text}}} when is_list(Text) -> - %% new long result format - {ok, Text}; - {ok, {ok, {{_Vsn, _Status, Phrase}, _Hdrs, Text}}} when is_list(Text) -> - %% new long result format when status /= 200 - {error, http_errmsg(Phrase, URI)}; - {ok, {200,_Hdrs,Text}} when is_list(Text) -> - %% old result format - {ok, Text}; - {ok, {Status,_Hdrs,Text}} when is_list(Text) -> - %% old result format when status /= 200 - Phrase = httpd_util:reason_phrase(Status), - {error, http_errmsg(Phrase, URI)}; - {ok, {error, R}} -> - Reason = inet:format_error(R), - {error, http_errmsg(Reason, URI)}; - {ok, R} -> - Reason = io_lib:format("bad return value ~tP", [R, 5]), - {error, http_errmsg(Reason, URI)}; - {'EXIT', R} -> - Reason = io_lib:format("crashed with reason ~tw", [R]), - {error, http_errmsg(Reason, URI)}; - R -> - Reason = io_lib:format("uncaught throw: ~tw", [R]), - {error, http_errmsg(Reason, URI)} - end. - -http_errmsg(Reason, URI) -> - io_lib:format("http error: ~ts: '~ts'", [Reason, URI]). - -%% TODO: implement ftp access method - -uri_get_ftp(URI) -> - Msg = io_lib:format("cannot access ftp scheme yet: '~ts'.", [URI]), - {error, Msg}. - %% @private to_label([$\s | Cs]) -> to_label(Cs); @@ -754,18 +632,6 @@ read_info_file(Dir) -> {?NO_APP, []} end. -%% URI access - -uri_get_info_file(Base) -> - URI = join_uri(Base, ?INFO_FILE), - case uri_get(URI) of - {ok, Text} -> - parse_info_file(Text, URI); - {error, Msg} -> - warning("could not read '~ts': ~ts.", [URI, Msg]), - {?NO_APP, []} - end. - parse_info_file(Text, Name) -> case parse_terms(Text) of {ok, Vs} -> @@ -897,7 +763,7 @@ find_doc_dirs([]) -> get_doc_links(App, Modules, Opts) -> Path = proplists:append_values(doc_path, Opts) ++ find_doc_dirs(), - Ds = [{P, uri_get_info_file(P)} || P <- Path], + Ds = [{P, read_info_file(P)} || P <- Path], Ds1 = [{"", {App, Modules}} | Ds], D = dict:new(), make_links(Ds1, D, D). diff --git a/lib/eldap/doc/src/eldap.xml b/lib/eldap/doc/src/eldap.xml index 790a2f4e26..4a8c2d1647 100644 --- a/lib/eldap/doc/src/eldap.xml +++ b/lib/eldap/doc/src/eldap.xml @@ -317,7 +317,7 @@ </type> <desc> <p> Modify the DN of an entry. <c>DeleteOldRDN</c> indicates - whether the current RDN should be removed from the attribute list after the after operation. + whether the current RDN should be removed from the attribute list after the operation. <c>NewSupDN</c> is the new parent that the RDN shall be moved to. If the old parent should remain as parent, <c>NewSupDN</c> shall be "".</p> <code> diff --git a/lib/erl_interface/src/decode/decode_fun.c b/lib/erl_interface/src/decode/decode_fun.c index db71007505..76dc0e2ab8 100644 --- a/lib/erl_interface/src/decode/decode_fun.c +++ b/lib/erl_interface/src/decode/decode_fun.c @@ -52,7 +52,10 @@ int ei_decode_fun(const char *buf, int *index, erlang_fun *p) switch (get8(s)) { case ERL_FUN_EXT: /* mark as old (R7 and older) external fun */ - if (p != NULL) p->arity = -1; + if (p != NULL) { + p->type = EI_FUN_CLOSURE; + p->arity = -1; + } /* first number of free vars (environment) */ n = get32be(s); /* then the pid */ diff --git a/lib/eunit/src/eunit_proc.erl b/lib/eunit/src/eunit_proc.erl index 96bdcf88b6..6e702543d0 100644 --- a/lib/eunit/src/eunit_proc.erl +++ b/lib/eunit/src/eunit_proc.erl @@ -644,6 +644,8 @@ io_request({get_line, _Enc, _Prompt}, Buf) -> {eof, Buf}; io_request({get_until, _Prompt, _M, _F, _As}, Buf) -> {eof, Buf}; +io_request({get_until, _Enc, _Prompt, _M, _F, _As}, Buf) -> + {eof, Buf}; io_request({setopts, _Opts}, Buf) -> {ok, Buf}; io_request(getopts, Buf) -> diff --git a/lib/eunit/src/eunit_surefire.erl b/lib/eunit/src/eunit_surefire.erl index 2b9f82b075..002a069a92 100644 --- a/lib/eunit/src/eunit_surefire.erl +++ b/lib/eunit/src/eunit_surefire.erl @@ -451,6 +451,11 @@ escape_xml([$< | Tail], Acc, ForAttr) -> escape_xml(Tail, [$;, $t, $l, $& | Acc] escape_xml([$> | Tail], Acc, ForAttr) -> escape_xml(Tail, [$;, $t, $g, $& | Acc], ForAttr); escape_xml([$& | Tail], Acc, ForAttr) -> escape_xml(Tail, [$;, $p, $m, $a, $& | Acc], ForAttr); escape_xml([$" | Tail], Acc, true) -> escape_xml(Tail, [$;, $t, $o, $u, $q, $& | Acc], true); % " +escape_xml([Char | Tail], Acc, ForAttr) when + Char == $\n; Char == $\r; Char == $\t -> escape_xml(Tail, [Char | Acc], ForAttr); +%% Strip C0 control codes which are not allowed in XML 1.0 +escape_xml([Char | Tail], Acc, ForAttr) when + 0 =< Char, Char =< 31 -> escape_xml(Tail, Acc, ForAttr); escape_xml([Char | Tail], Acc, ForAttr) when is_integer(Char) -> escape_xml(Tail, [Char | Acc], ForAttr). %% the input may be utf8 or latin1; the resulting list is unicode diff --git a/lib/eunit/test/Makefile b/lib/eunit/test/Makefile index b6ece61b43..7c1e56c867 100644 --- a/lib/eunit/test/Makefile +++ b/lib/eunit/test/Makefile @@ -22,6 +22,7 @@ include $(ERL_TOP)/make/$(TARGET)/otp.mk MODULES = \ eunit_SUITE \ + tc0 \ tlatin \ tutf8 diff --git a/lib/eunit/test/eunit_SUITE.erl b/lib/eunit/test/eunit_SUITE.erl index 63bdc6c334..b9f4ea4557 100644 --- a/lib/eunit/test/eunit_SUITE.erl +++ b/lib/eunit/test/eunit_SUITE.erl @@ -21,14 +21,16 @@ -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, - app_test/1,appup_test/1,eunit_test/1,surefire_utf8_test/1,surefire_latin_test/1]). + app_test/1,appup_test/1,eunit_test/1,surefire_utf8_test/1,surefire_latin_test/1, + surefire_c0_test/1]). -include_lib("common_test/include/ct.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. all() -> - [app_test, appup_test, eunit_test, surefire_utf8_test, surefire_latin_test]. + [app_test, appup_test, eunit_test, surefire_utf8_test, surefire_latin_test, + surefire_c0_test]. groups() -> []. @@ -65,11 +67,24 @@ surefire_utf8_test(Config) when is_list(Config) -> check_surefire(tutf8), ok. +surefire_c0_test(Config) when is_list(Config) -> + ok = file:set_cwd(proplists:get_value(priv_dir, Config, ".")), + Chars = check_surefire(tc0), + %% Check that these characters were not stripped + true = lists:member($\n, Chars), + true = lists:member($\r, Chars), + true = lists:member($\t, Chars), + ok. + check_surefire(Module) -> File = "TEST-"++atom_to_list(Module)++".xml", file:delete(File), % ignore test result, some fail on purpose eunit:test(Module, [{report,{eunit_surefire,[{dir,"."}]}}]), {ok, Bin} = file:read_file(File), - [_|_] = unicode:characters_to_list(Bin, unicode), - ok.
\ No newline at end of file + Chars = unicode:characters_to_list(Bin, unicode), + %% Check that unicode decoding succeeded + [_|_] = Chars, + %% Check that file is valid XML + xmerl_scan:file(File), + Chars. diff --git a/lib/eunit/test/tc0.erl b/lib/eunit/test/tc0.erl new file mode 100644 index 0000000000..8c90633fc8 --- /dev/null +++ b/lib/eunit/test/tc0.erl @@ -0,0 +1,14 @@ +-module(tc0). + +-include_lib("eunit/include/eunit.hrl"). + +'c0_bad_output_test_'() -> + [{integer_to_list(C), fun() -> io:format("'~c'", [C]) end} + || C <- lists:seq(0, 31)]. + +'c0_bad_description_test_'() -> + [{[C], fun() -> ok end} + || C <- lists:seq(0, 31)]. + +'c0_bad_name__test'() -> + ok. diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java index a3b089c1da..917e5baf3a 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java @@ -106,9 +106,9 @@ public class OtpOutputStream extends ByteArrayOutputStream { } /** - * Trims the capacity of this <tt>OtpOutputStream</tt> instance to be the + * Trims the capacity of this <code>OtpOutputStream</code> instance to be the * buffer's current size. An application can use this operation to minimize - * the storage of an <tt>OtpOutputStream</tt> instance. + * the storage of an <code>OtpOutputStream</code> instance. */ public void trimToSize() { resize(super.count); @@ -125,7 +125,7 @@ public class OtpOutputStream extends ByteArrayOutputStream { } /** - * Increases the capacity of this <tt>OtpOutputStream</tt> instance, if + * Increases the capacity of this <code>OtpOutputStream</code> instance, if * necessary, to ensure that it can hold at least the number of elements * specified by the minimum capacity argument. * @@ -909,7 +909,7 @@ public class OtpOutputStream extends ByteArrayOutputStream { * @param o * the Erlang term to write. * @param level - * the compression level (<tt>0..9</tt>) + * the compression level (<code>0..9</code>) */ public void write_compressed(final OtpErlangObject o, final int level) { @SuppressWarnings("resource") diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml index d923207f9f..2c09c84b25 100644 --- a/lib/kernel/doc/src/file.xml +++ b/lib/kernel/doc/src/file.xml @@ -957,10 +957,9 @@ f.txt: {person, "kalle", 25}. </item> </taglist> <p><c><anno>IoDevice</anno></c> is really the pid of the process that - handles the file. This process is linked to the process - that originally opened the file. If any process to which - the <c><anno>IoDevice</anno></c> is linked terminates, the file is - closed and the process itself is terminated. + handles the file. This process monitors the process that originally + opened the file (the owner process). If the owner process terminates, + the file is closed and the process itself terminates too. An <c><anno>IoDevice</anno></c> returned from this call can be used as an argument to the I/O functions (see <seealso marker="stdlib:io"><c>io(3)</c></seealso>).</p> diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 2ad2df97a8..cde03ce1c4 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2018. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -555,7 +555,7 @@ allocate(#file_descriptor{module = Module} = Handle, Offset, Length) -> | {no_translation, unicode, latin1}. read(File, Sz) when (is_pid(File) orelse is_atom(File)), is_integer(Sz), Sz >= 0 -> - case io:request(File, {get_chars, '', Sz}) of + case io:request(File, {get_chars, latin1, '', Sz}) of Data when is_list(Data); is_binary(Data) -> {ok, Data}; Other -> @@ -576,7 +576,7 @@ read(_, _) -> | {no_translation, unicode, latin1}. read_line(File) when (is_pid(File) orelse is_atom(File)) -> - case io:request(File, {get_line, ''}) of + case io:request(File, {get_line, latin1, ''}) of Data when is_list(Data); is_binary(Data) -> {ok, Data}; Other -> diff --git a/lib/kernel/src/group.erl b/lib/kernel/src/group.erl index 5625ae6eb7..8c0ced8678 100644 --- a/lib/kernel/src/group.erl +++ b/lib/kernel/src/group.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2018. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -795,12 +795,6 @@ save_line({stack, U, _L, D}, Line) -> {stack, U, Line, D}. get_lines(Ls) -> get_all_lines(Ls). -%get_lines({stack, U, {}, []}) -> -% U; -%get_lines({stack, U, {}, D}) -> -% tl(lists:reverse(D, U)); -%get_lines({stack, U, L, D}) -> -% get_lines({stack, U, {}, [L|D]}). %% There's a funny behaviour whenever the line stack doesn't have a "\n" %% at its end -- get_lines() seemed to work on the assumption it *will* be diff --git a/lib/kernel/src/logger.erl b/lib/kernel/src/logger.erl index 38bd2f481c..fd02cf67bf 100644 --- a/lib/kernel/src/logger.erl +++ b/lib/kernel/src/logger.erl @@ -600,11 +600,11 @@ get_module_level() -> %%%----------------------------------------------------------------- %%% Misc -spec compare_levels(Level1,Level2) -> eq | gt | lt when - Level1 :: level(), - Level2 :: level(). -compare_levels(Level,Level) when ?IS_LEVEL(Level) -> + Level1 :: level() | all | none, + Level2 :: level() | all | none. +compare_levels(Level,Level) when ?IS_LEVEL_ALL(Level) -> eq; -compare_levels(Level1,Level2) when ?IS_LEVEL(Level1), ?IS_LEVEL(Level2) -> +compare_levels(Level1,Level2) when ?IS_LEVEL_ALL(Level1), ?IS_LEVEL_ALL(Level2) -> Int1 = logger_config:level_to_int(Level1), Int2 = logger_config:level_to_int(Level2), if Int1 < Int2 -> gt; @@ -950,7 +950,7 @@ get_logger_type(Env) -> get_logger_level() -> case application:get_env(kernel,logger_level,info) of - Level when ?IS_LEVEL(Level); Level=:=all; Level=:=none -> + Level when ?IS_LEVEL_ALL(Level) -> Level; Level -> throw({logger_level, Level}) diff --git a/lib/kernel/src/logger_internal.hrl b/lib/kernel/src/logger_internal.hrl index e53922e5d3..c2b2d419e7 100644 --- a/lib/kernel/src/logger_internal.hrl +++ b/lib/kernel/src/logger_internal.hrl @@ -86,7 +86,12 @@ L=:=warning orelse L=:=notice orelse L=:=info orelse - L=:=debug)). + L=:=debug )). + +-define(IS_LEVEL_ALL(L), + ?IS_LEVEL(L) orelse + L=:=all orelse + L=:=none ). -define(IS_MSG(Msg), ((is_tuple(Msg) andalso tuple_size(Msg)==2) diff --git a/lib/kernel/src/logger_std_h.erl b/lib/kernel/src/logger_std_h.erl index 2b078ef091..8477a0fc93 100644 --- a/lib/kernel/src/logger_std_h.erl +++ b/lib/kernel/src/logger_std_h.erl @@ -457,12 +457,12 @@ maybe_ensure_file(State) -> %% In order to play well with tools like logrotate, we need to be able %% to re-create the file if it has disappeared (e.g. if rotated by %% logrotate) -ensure_file(#{fd:=Fd0,inode:=INode0,file_name:=FileName,modes:=Modes}=State) -> +ensure_file(#{inode:=INode0,file_name:=FileName,modes:=Modes}=State) -> case file:read_file_info(FileName,[raw]) of {ok,#file_info{inode=INode0}} -> State#{last_check=>timestamp()}; _ -> - close_log_file(Fd0), + close_log_file(State), case file:open(FileName,Modes) of {ok,Fd} -> {ok,#file_info{inode=INode}} = diff --git a/lib/kernel/src/user.erl b/lib/kernel/src/user.erl index 5a3487a9ba..81520dd841 100644 --- a/lib/kernel/src/user.erl +++ b/lib/kernel/src/user.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2017. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -537,54 +537,6 @@ get_line_doit(Prompt, Port, Q, Accu, Enc) -> binrev(L, T) -> list_to_binary(lists:reverse(L, T)). -%% is_cr_at(Pos,Bin) -> -%% case Bin of -%% <<_:Pos/binary,$\r,_/binary>> -> -%% true; -%% _ -> -%% false -%% end. - -%% collect_line_bin_re(Bin,_Data,Stack,_) -> -%% case re:run(Bin,<<"\n">>) of -%% nomatch -> -%% X = byte_size(Bin)-1, -%% case is_cr_at(X,Bin) of -%% true -> -%% <<D:X/binary,_/binary>> = Bin, -%% [<<$\r>>,D|Stack]; -%% false -> -%% [Bin|Stack] -%% end; -%% {match,[{Pos,1}]} -> -%% PosPlus = Pos + 1, -%% case Stack of -%% [] -> -%% case is_cr_at(Pos - 1,Bin) of -%% false -> -%% <<Head:PosPlus/binary,Tail/binary>> = Bin, -%% {stop, Head, Tail}; -%% true -> -%% PosMinus = Pos - 1, -%% <<Head:PosMinus/binary,_,_,Tail/binary>> = Bin, -%% {stop, binrev([],[Head,$\n]),Tail} -%% end; -%% [<<$\r>>|Stack1] when Pos =:= 0 -> - -%% <<_:PosPlus/binary,Tail/binary>> = Bin, -%% {stop,binrev(Stack1, [$\n]),Tail}; -%% _ -> -%% case is_cr_at(Pos - 1,Bin) of -%% false -> -%% <<Head:PosPlus/binary,Tail/binary>> = Bin, -%% {stop,binrev(Stack, [Head]),Tail}; -%% true -> -%% PosMinus = Pos - 1, -%% <<Head:PosMinus/binary,_,_,Tail/binary>> = Bin, -%% {stop, binrev(Stack,[Head,$\n]),Tail} -%% end -%% end -%% end. %% get_chars(Prompt, Module, Function, XtraArg, Port, Queue, Encoding) %% Gets characters from the input port until the applied function %% returns {stop,Result,RestBuf}. Does not block output until input @@ -618,9 +570,6 @@ get_chars(Prompt, M, F, Xa, Port, Q, State, Enc) -> {Port, eof} -> put(eof, true), {ok, eof, queue:new()}; - %%{io_request,From,ReplyAs,Request} when is_pid(From) -> - %% get_chars_req(Prompt, M, F, Xa, Port, queue:new(), State, - %% Request, From, ReplyAs); {io_request,From,ReplyAs,{get_geometry,_}=Req} when is_pid(From) -> do_io_request(Req, From, ReplyAs, Port, queue:new()), %Keep Q over this call diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl index 9efe83d8b3..747f1d9e1b 100644 --- a/lib/kernel/test/file_SUITE.erl +++ b/lib/kernel/test/file_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2018. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -278,11 +278,11 @@ mini_server(Parent) -> Parent ! {io_request,From,To,{put_chars,Data}}, From ! {io_reply, To, ok}, mini_server(Parent); - {io_request,From,To,{get_chars,'',N}} -> + {io_request,From,To,{get_chars,_Encoding,'',N}} -> Parent ! {io_request,From,To,{get_chars,'',N}}, From ! {io_reply, To, {ok, lists:duplicate(N,$a)}}, mini_server(Parent); - {io_request,From,To,{get_line,''}} -> + {io_request,From,To,{get_line,_Encoding,''}} -> Parent ! {io_request,From,To,{get_line,''}}, From ! {io_reply, To, {ok, "hej\n"}}, mini_server(Parent) diff --git a/lib/kernel/test/global_SUITE.erl b/lib/kernel/test/global_SUITE.erl index 8eab36e308..5bff9cc292 100644 --- a/lib/kernel/test/global_SUITE.erl +++ b/lib/kernel/test/global_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1997-2018. All Rights Reserved. +%% Copyright Ericsson AB 1997-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -2512,8 +2512,10 @@ re_register_name(Config) when is_list(Config) -> Me = self(), Pid1 = spawn(fun() -> proc(Me) end), yes = global:register_name(name, Pid1), + wait_for_monitor(Pid1), Pid2 = spawn(fun() -> proc(Me) end), _ = global:re_register_name(name, Pid2), + wait_for_monitor(Pid2), Pid2 ! die, Pid1 ! die, receive {Pid1, MonitoredBy1} -> [] = MonitoredBy1 end, @@ -2522,6 +2524,15 @@ re_register_name(Config) when is_list(Config) -> init_condition(Config), ok. +wait_for_monitor(Pid) -> + case process_info(Pid, monitored_by) of + {monitored_by, []} -> + timer:sleep(1), + wait_for_monitor(Pid); + {monitored_by, [_]} -> + ok + end. + proc(Parent) -> receive die -> ok end, {monitored_by, MonitoredBy} = process_info(self(), monitored_by), diff --git a/lib/kernel/test/logger_SUITE.erl b/lib/kernel/test/logger_SUITE.erl index 035e5d8974..f8f3d27778 100644 --- a/lib/kernel/test/logger_SUITE.erl +++ b/lib/kernel/test/logger_SUITE.erl @@ -880,7 +880,7 @@ other_node(cleanup,_Config) -> ok. compare_levels(_Config) -> - Levels = [emergency,alert,critical,error,warning,notice,info,debug], + Levels = [none,emergency,alert,critical,error,warning,notice,info,debug,all], ok = compare(Levels), {error,badarg} = ?TRY(logger:compare_levels(bad,bad)), {error,badarg} = ?TRY(logger:compare_levels({bad},notice)), diff --git a/lib/mnesia/doc/src/Mnesia_chap7.xmlsrc b/lib/mnesia/doc/src/Mnesia_chap7.xmlsrc index ffbbdadec0..968e89a745 100644 --- a/lib/mnesia/doc/src/Mnesia_chap7.xmlsrc +++ b/lib/mnesia/doc/src/Mnesia_chap7.xmlsrc @@ -295,7 +295,7 @@ ok</pre> if the log is large. Notice that the <c>Mnesia</c> system continues to operate during log dumps.</p> <p>By default <c>Mnesia</c> either dumps the log whenever - 100 records have + 1000 records have been written in the log or when three minutes have passed. This is controlled by the two application parameters <c>-mnesia dump_log_write_threshold WriteOperations</c> and diff --git a/lib/mnesia/src/mnesia_controller.erl b/lib/mnesia/src/mnesia_controller.erl index 882de0d613..0f221b0c1f 100644 --- a/lib/mnesia/src/mnesia_controller.erl +++ b/lib/mnesia/src/mnesia_controller.erl @@ -331,35 +331,39 @@ release_schema_commit_lock() -> %% Special for preparation of add table copy get_network_copy(Tid, Tab, Cs) -> -% We can't let the controller queue this one -% because that may cause a deadlock between schema_operations -% and initial tableloadings which both takes schema locks. -% But we have to get copier_done msgs when the other side -% goes down. - call({add_other, self()}), - Reason = {dumper,{add_table_copy, Tid}}, - Work = #net_load{table = Tab,reason = Reason,cstruct = Cs}, - %% I'll need this cause it's linked trough the subscriber - %% might be solved by using monitor in subscr instead. - process_flag(trap_exit, true), - Load = load_table_fun(Work), - Res = ?CATCH(Load()), - process_flag(trap_exit, false), - call({del_other, self()}), - case Res of - #loader_done{is_loaded = true} -> - Tab = Res#loader_done.table_name, - case Res#loader_done.needs_announce of - true -> - i_have_tab(Tab); - false -> - ignore - end, - Res#loader_done.reply; - #loader_done{} -> - Res#loader_done.reply; - Else -> - {not_loaded, Else} + %% We can't let the controller queue this one + %% because that may cause a deadlock between schema_operations + %% and initial tableloadings which both takes schema locks. + %% But we have to get copier_done msgs when the other side + %% goes down. + case call({add_other, self()}) of + ok -> + Reason = {dumper,{add_table_copy, Tid}}, + Work = #net_load{table = Tab,reason = Reason,cstruct = Cs}, + %% I'll need this cause it's linked trough the subscriber + %% might be solved by using monitor in subscr instead. + process_flag(trap_exit, true), + Load = load_table_fun(Work), + Res = ?CATCH(Load()), + process_flag(trap_exit, false), + call({del_other, self()}), + case Res of + #loader_done{is_loaded = true} -> + Tab = Res#loader_done.table_name, + case Res#loader_done.needs_announce of + true -> + i_have_tab(Tab); + false -> + ignore + end, + Res#loader_done.reply; + #loader_done{} -> + Res#loader_done.reply; + Else -> + {not_loaded, Else} + end; + {error, Else} -> + {not_loaded, Else} end. %% This functions is invoked from the dumper @@ -772,6 +776,18 @@ handle_call({unannounce_add_table_copy, [Tab, Node], From}, ReplyTo, State) -> noreply(State#state{early_msgs = [{call, Msg, undefined} | Msgs]}) end; +handle_call({add_other, Who}, _From, State = #state{others=Others0, schema_is_merged=SM}) -> + case SM of + true -> + Others = [Who|Others0], + {reply, ok, State#state{others=Others}}; + false -> + {reply, {error, {not_active,schema,node()}}, State} + end; +handle_call({del_other, Who}, _From, State = #state{others=Others0}) -> + Others = lists:delete(Who, Others0), + {reply, ok, State#state{others=Others}}; + handle_call(Msg, From, State) when State#state.schema_is_merged /= true -> %% Buffer early messages Msgs = State#state.early_msgs, @@ -803,13 +819,6 @@ handle_call({block_table, [Tab], From}, _Dummy, State) -> handle_call({check_w2r, _Node, Tab}, _From, State) -> {reply, val({Tab, where_to_read}), State}; -handle_call({add_other, Who}, _From, State = #state{others=Others0}) -> - Others = [Who|Others0], - {reply, ok, State#state{others=Others}}; -handle_call({del_other, Who}, _From, State = #state{others=Others0}) -> - Others = lists:delete(Who, Others0), - {reply, ok, State#state{others=Others}}; - handle_call(Msg, _From, State) -> error("~p got unexpected call: ~tp~n", [?SERVER_NAME, Msg]), noreply(State). diff --git a/lib/mnesia/src/mnesia_locker.erl b/lib/mnesia/src/mnesia_locker.erl index f68626413e..0222c5b1a0 100644 --- a/lib/mnesia/src/mnesia_locker.erl +++ b/lib/mnesia/src/mnesia_locker.erl @@ -774,10 +774,12 @@ do_sticky_lock(Tid, Store, {Tab, Key} = Oid, Lock) -> N = node(), receive {?MODULE, N, granted} -> + ?ets_insert(Store, {sticky, true}), ?ets_insert(Store, {{locks, Tab, Key}, write}), [?ets_insert(Store, {nodes, Node}) || Node <- WNodes], granted; {?MODULE, N, {granted, Val}} -> %% for rwlocks + ?ets_insert(Store, {sticky, true}), case opt_lookup_in_client(Val, Oid, write) of C = #cyclic{} -> exit({aborted, C}); diff --git a/lib/mnesia/src/mnesia_monitor.erl b/lib/mnesia/src/mnesia_monitor.erl index 4cfe16dec0..4e50b46da8 100644 --- a/lib/mnesia/src/mnesia_monitor.erl +++ b/lib/mnesia/src/mnesia_monitor.erl @@ -83,9 +83,9 @@ going_down = [], tm_started = false, early_connects = [], connecting, mq = [], remote_node_status = []}). --define(current_protocol_version, {8,3}). +-define(current_protocol_version, {8,4}). --define(previous_protocol_version, {8,2}). +-define(previous_protocol_version, {8,3}). start() -> gen_server:start_link({local, ?MODULE}, ?MODULE, @@ -196,7 +196,7 @@ protocol_version() -> %% A sorted list of acceptable protocols the %% preferred protocols are first in the list acceptable_protocol_versions() -> - [protocol_version(), ?previous_protocol_version, {8,1}]. + [protocol_version(), ?previous_protocol_version]. needs_protocol_conversion(Node) -> case {?catch_val({protocol, Node}), protocol_version()} of diff --git a/lib/mnesia/src/mnesia_schema.erl b/lib/mnesia/src/mnesia_schema.erl index ef38adca1e..d0f5d0e07b 100644 --- a/lib/mnesia/src/mnesia_schema.erl +++ b/lib/mnesia/src/mnesia_schema.erl @@ -697,7 +697,7 @@ schema_coordinator(Client, _Fun, undefined) -> schema_coordinator(Client, Fun, Controller) when is_pid(Controller) -> %% Do not trap exit in order to automatically die %% when the controller dies - + put(transaction_client, Client), %% debug link(Controller), unlink(Client), @@ -730,7 +730,10 @@ api_list2cs(Other) -> mnesia:abort({badarg, Other}). vsn_cs2list(Cs) -> - cs2list(need_old_cstructs(), Cs). + cs2list(Cs). + +cs2list(false, Cs) -> + cs2list(Cs). cs2list(Cs) when is_record(Cs, cstruct) -> Tags = record_info(fields, cstruct), @@ -755,25 +758,6 @@ cs2list(Cs) when element(1, Cs) == cstruct, tuple_size(Cs) == 19 -> cookie,version], rec2list(Tags, Tags, 2, Cs). -cs2list(false, Cs) -> - cs2list(Cs); -cs2list({8,3}, Cs) -> - cs2list(Cs); -cs2list({8,Minor}, Cs) when Minor =:= 2; Minor =:= 1 -> - Orig = record_info(fields, cstruct), - Tags = [name,type,ram_copies,disc_copies,disc_only_copies, - load_order,access_mode,majority,index,snmp,local_content, - record_name,attributes, - user_properties,frag_properties,storage_properties, - cookie,version], - CsList = rec2list(Tags, Orig, 2, Cs), - case proplists:get_value(index, CsList, []) of - [] -> CsList; - NewFormat -> - OldFormat = [Pos || {Pos, _Pref} <- NewFormat], - lists:keyreplace(index, 1, CsList, {index, OldFormat}) - end. - rec2list([index | Tags], [index|Orig], Pos, Rec) -> Val = element(Pos, Rec), [{index, lists:map( @@ -796,19 +780,8 @@ rec2list([], _, _Pos, _Rec) -> rec2list(Tags, [_|Orig], Pos, Rec) -> rec2list(Tags, Orig, Pos+1, Rec). -normalize_cs(Cstructs, Node) -> - %% backward-compatibility hack; normalize before returning - case need_old_cstructs([Node]) of - false -> - Cstructs; - Version -> - %% some other format - [convert_cs(Version, Cs) || Cs <- Cstructs] - end. - -convert_cs(Version, Cs) -> - Fields = [Value || {_, Value} <- cs2list(Version, Cs)], - list_to_tuple([cstruct|Fields]). +normalize_cs(Cstructs, _Node) -> + Cstructs. list2cs(List) -> list2cs(List, get_ext_types()). @@ -1864,11 +1837,7 @@ do_move_table(schema, _FromNode, _ToNode) -> mnesia:abort({bad_type, schema}); do_move_table(Tab, FromNode, ToNode) when is_atom(FromNode), is_atom(ToNode) -> TidTs = get_tid_ts_and_lock(schema, write), - AnyOld = lists:any(fun(Node) -> mnesia_monitor:needs_protocol_conversion(Node) end, - [ToNode|val({Tab, where_to_write})]), - if AnyOld -> ignore; %% Leads to deadlock on old nodes - true -> get_tid_ts_and_lock(Tab, write) - end, + get_tid_ts_and_lock(Tab, write), insert_schema_ops(TidTs, make_move_table(Tab, FromNode, ToNode)); do_move_table(Tab, FromNode, ToNode) -> mnesia:abort({badarg, Tab, FromNode, ToNode}). @@ -3438,15 +3407,14 @@ do_merge_schema(LockTabs0) -> mnesia_lib:intersect(Ns,NeedsLock)) || {T,Ns} <- LockTabs], - NeedsConversion = need_old_cstructs(NeedsLock ++ LockedAlready), {value, SchemaCs} = lists:keysearch(schema, #cstruct.name, Cstructs), - SchemaDef = cs2list(NeedsConversion, SchemaCs), + SchemaDef = cs2list(false, SchemaCs), %% Announce that Node is running A = [{op, announce_im_running, node(), SchemaDef, Running, RemoteRunning}], do_insert_schema_ops(Store, A), %% Introduce remote tables to local node - do_insert_schema_ops(Store, make_merge_schema(Node, NeedsConversion, Cstructs)), + do_insert_schema_ops(Store, make_merge_schema(Node, false, Cstructs)), %% Introduce local tables to remote nodes Tabs = val({schema, tables}), @@ -3471,23 +3439,7 @@ do_merge_schema(LockTabs0) -> end. fetch_cstructs(Node) -> - Convert = mnesia_monitor:needs_protocol_conversion(Node), - case rpc:call(Node, mnesia_controller, get_remote_cstructs, []) of - {cstructs, Cs0, RemoteRunning1} when Convert -> - {cstructs, [list2cs(cs2list(Cs)) || Cs <- Cs0], RemoteRunning1}; - Result -> - Result - end. - -need_old_cstructs() -> - need_old_cstructs(val({schema, where_to_write})). - -need_old_cstructs(Nodes) -> - Filter = fun(Node) -> mnesia_monitor:needs_protocol_conversion(Node) end, - case lists:filter(Filter, Nodes) of - [] -> false; - Ns -> lists:min([element(1, ?catch_val({protocol, Node})) || Node <- Ns]) - end. + rpc:call(Node, mnesia_controller, get_remote_cstructs, []). tab_to_nodes(Tab) when is_atom(Tab) -> Cs = val({Tab, cstruct}), diff --git a/lib/mnesia/src/mnesia_text.erl b/lib/mnesia/src/mnesia_text.erl index cc21621ff4..ee31fdfd27 100644 --- a/lib/mnesia/src/mnesia_text.erl +++ b/lib/mnesia/src/mnesia_text.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2018. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -170,7 +170,7 @@ read_terms(Stream, File, Line, L) -> end. read_term_from_stream(Stream, File, Line) -> - R = io:request(Stream, {get_until,'',erl_scan,tokens,[Line]}), + R = io:request(Stream, {get_until,latin1,'',erl_scan,tokens,[Line]}), case R of {ok,Toks,EndLine} -> case erl_parse:parse_term(Toks) of diff --git a/lib/mnesia/src/mnesia_tm.erl b/lib/mnesia/src/mnesia_tm.erl index 8b79fca1d7..8a4113422a 100644 --- a/lib/mnesia/src/mnesia_tm.erl +++ b/lib/mnesia/src/mnesia_tm.erl @@ -26,7 +26,7 @@ init/1, non_transaction/5, transaction/6, - commit_participant/5, + commit_participant/6, dirty/2, display_info/2, do_update_op/3, @@ -62,13 +62,14 @@ %% Format on coordinators is [{Tid, EtsTabList} ..... -record(prep, {protocol = sym_trans, - %% async_dirty | sync_dirty | sym_trans | sync_sym_trans | asym_trans + %% async_dirty | sync_dirty | sym_trans | sync_sym_trans | asym_trans | sync_asym_trans records = [], prev_tab = [], % initiate to a non valid table name prev_types, prev_snmp, types, - majority = [] + majority = [], + sync = false }). -record(participant, {tid, pid, commit, disc_nodes = [], @@ -250,11 +251,13 @@ doit_loop(#state{coordinators=Coordinators,participants=Participants,supervisor= mnesia_checkpoint:tm_enter_pending(Tid, DiscNs, RamNs), Commit = new_cr_format(Commit0), Pid = - case Protocol of - asym_trans when node(Tid#tid.pid) /= node() -> - Args = [tmpid(From), Tid, Commit, DiscNs, RamNs], + if + node(Tid#tid.pid) =:= node() -> + error({internal_error, local_node}); + Protocol =:= asym_trans orelse Protocol =:= sync_asym_trans -> + Args = [Protocol, tmpid(From), Tid, Commit, DiscNs, RamNs], spawn_link(?MODULE, commit_participant, Args); - _ when node(Tid#tid.pid) /= node() -> %% *_sym_trans + true -> %% *_sym_trans reply(From, {vote_yes, Tid}), nopid end, @@ -1190,7 +1193,15 @@ do_arrange(Tid, Store, RestoreKey, Prep, N) when RestoreKey == restore_op -> P2 = Prep#prep{protocol = asym_trans, records = Recs2}, do_arrange(Tid, Store, ?ets_next(Store, RestoreKey), P2, N + 1); do_arrange(_Tid, _Store, '$end_of_table', Prep, N) -> - {N, Prep}; + case Prep of + #prep{sync=true, protocol=asym_trans} -> + {N, Prep#prep{protocol=sync_asym_trans}}; + _ -> + {N, Prep} + end; +do_arrange(Tid, Store, sticky, Prep, N) -> + P2 = Prep#prep{sync=true}, + do_arrange(Tid, Store, ?ets_next(Store, sticky), P2, N); do_arrange(Tid, Store, IgnoredKey, Prep, N) -> %% locks, nodes ... local atoms... do_arrange(Tid, Store, ?ets_next(Store, IgnoredKey), Prep, N). @@ -1448,7 +1459,8 @@ multi_commit(sync_sym_trans, _Maj = [], Tid, CR, Store) -> [{tid, Tid}, {outcome, Outcome}]), Outcome; -multi_commit(asym_trans, Majority, Tid, CR, Store) -> +multi_commit(Protocol, Majority, Tid, CR, Store) + when Protocol =:= asym_trans; Protocol =:= sync_asym_trans -> %% This more expensive commit protocol is used when %% table definitions are changed (schema transactions). %% It is also used when the involved tables are @@ -1515,7 +1527,7 @@ multi_commit(asym_trans, Majority, Tid, CR, Store) -> end, Pending = mnesia_checkpoint:tm_enter_pending(Tid, DiscNs, RamNs), ?ets_insert(Store, Pending), - {WaitFor, Local} = ask_commit(asym_trans, Tid, CR2, DiscNs, RamNs), + {WaitFor, Local} = ask_commit(Protocol, Tid, CR2, DiscNs, RamNs), SchemaPrep = ?CATCH(mnesia_schema:prepare_commit(Tid, Local, {coord, WaitFor})), {Votes, Pids} = rec_all(WaitFor, Tid, do_commit, []), @@ -1563,38 +1575,38 @@ multi_commit(asym_trans, Majority, Tid, CR, Store) -> %% Returns do_commit or {do_abort, Reason} rec_acc_pre_commit([Pid | Tail], Tid, Store, Commit, Res, DumperMode, - GoodPids, SchemaAckPids) -> + GoodPids, AckPids) -> receive {?MODULE, _, {acc_pre_commit, Tid, Pid, true}} -> rec_acc_pre_commit(Tail, Tid, Store, Commit, Res, DumperMode, - [Pid | GoodPids], [Pid | SchemaAckPids]); + [Pid | GoodPids], [Pid | AckPids]); {?MODULE, _, {acc_pre_commit, Tid, Pid, false}} -> rec_acc_pre_commit(Tail, Tid, Store, Commit, Res, DumperMode, - [Pid | GoodPids], SchemaAckPids); + [Pid | GoodPids], AckPids); {?MODULE, _, {acc_pre_commit, Tid, Pid}} -> %% Kept for backwards compatibility. Remove after Mnesia 4.x rec_acc_pre_commit(Tail, Tid, Store, Commit, Res, DumperMode, - [Pid | GoodPids], [Pid | SchemaAckPids]); + [Pid | GoodPids], [Pid | AckPids]); {?MODULE, _, {do_abort, Tid, Pid, _Reason}} -> AbortRes = {do_abort, {bad_commit, node(Pid)}}, rec_acc_pre_commit(Tail, Tid, Store, Commit, AbortRes, DumperMode, - GoodPids, SchemaAckPids); + GoodPids, AckPids); {mnesia_down, Node} when Node == node(Pid) -> AbortRes = {do_abort, {bad_commit, Node}}, ?SAFE(Pid ! {Tid, AbortRes}), %% Tell him that he has died rec_acc_pre_commit(Tail, Tid, Store, Commit, AbortRes, DumperMode, - GoodPids, SchemaAckPids) + GoodPids, AckPids) end; -rec_acc_pre_commit([], Tid, Store, {Commit,OrigC}, Res, DumperMode, GoodPids, SchemaAckPids) -> +rec_acc_pre_commit([], Tid, Store, {Commit,OrigC}, Res, DumperMode, GoodPids, AckPids) -> D = Commit#commit.decision, case Res of do_commit -> %% Now everybody knows that the others %% has voted yes. We also know that %% everybody are uncertain. - prepare_sync_schema_commit(Store, SchemaAckPids), + prepare_sync_schema_commit(Store, AckPids), tell_participants(GoodPids, {Tid, committed}), D2 = D#decision{outcome = committed}, mnesia_recover:log_decision(D2), @@ -1606,7 +1618,7 @@ rec_acc_pre_commit([], Tid, Store, {Commit,OrigC}, Res, DumperMode, GoodPids, Sc do_commit(Tid, Commit, DumperMode), ?eval_debug_fun({?MODULE, rec_acc_pre_commit_done_commit}, [{tid, Tid}]), - sync_schema_commit(Tid, Store, SchemaAckPids), + sync_schema_commit(Tid, Store, AckPids), mnesia_locker:release_tid(Tid), ?MODULE ! {delete_transaction, Tid}; @@ -1623,6 +1635,7 @@ rec_acc_pre_commit([], Tid, Store, {Commit,OrigC}, Res, DumperMode, GoodPids, Sc Res. %% Note all nodes in case of mnesia_down mgt +%% sync_schema_commit is (ab)used for sync_asym_trans as well. prepare_sync_schema_commit(_Store, []) -> ok; prepare_sync_schema_commit(Store, [Pid | Pids]) -> @@ -1648,17 +1661,17 @@ tell_participants([Pid | Pids], Msg) -> tell_participants([], _Msg) -> ok. --spec commit_participant(_, _, _, _, _) -> no_return(). +-spec commit_participant(_, _, _, _, _, _) -> no_return(). %% Trap exit because we can get a shutdown from application manager -commit_participant(Coord, Tid, Bin, DiscNs, RamNs) when is_binary(Bin) -> +commit_participant(Protocol, Coord, Tid, Bin, DiscNs, RamNs) when is_binary(Bin) -> process_flag(trap_exit, true), Commit = binary_to_term(Bin), - commit_participant(Coord, Tid, Bin, Commit, DiscNs, RamNs); -commit_participant(Coord, Tid, C = #commit{}, DiscNs, RamNs) -> + commit_participant(Protocol, Coord, Tid, Bin, Commit, DiscNs, RamNs); +commit_participant(Protocol, Coord, Tid, C = #commit{}, DiscNs, RamNs) -> process_flag(trap_exit, true), - commit_participant(Coord, Tid, C, C, DiscNs, RamNs). + commit_participant(Protocol, Coord, Tid, C, C, DiscNs, RamNs). -commit_participant(Coord, Tid, Bin, C0, DiscNs, _RamNs) -> +commit_participant(Protocol, Coord, Tid, Bin, C0, DiscNs, _RamNs) -> ?eval_debug_fun({?MODULE, commit_participant, pre}, [{tid, Tid}]), try mnesia_schema:prepare_commit(Tid, C0, {part, Coord}) of {Modified, C = #commit{}, DumperMode} -> @@ -1683,8 +1696,9 @@ commit_participant(Coord, Tid, Bin, C0, DiscNs, _RamNs) -> mnesia_recover:log_decision(D#decision{outcome = unclear}), ?eval_debug_fun({?MODULE, commit_participant, pre_commit}, [{tid, Tid}]), - Expect_schema_ack = C#commit.schema_ops /= [], - reply(Coord, {acc_pre_commit, Tid, self(), Expect_schema_ack}), + ExpectAck = C#commit.schema_ops /= [] + orelse Protocol =:= sync_asym_trans, + reply(Coord, {acc_pre_commit, Tid, self(), ExpectAck}), %% Now we are vulnerable for failures, since %% we cannot decide without asking others @@ -1694,7 +1708,7 @@ commit_participant(Coord, Tid, Bin, C0, DiscNs, _RamNs) -> ?eval_debug_fun({?MODULE, commit_participant, log_commit}, [{tid, Tid}]), do_commit(Tid, C, DumperMode), - case Expect_schema_ack of + case ExpectAck of false -> ignore; true -> reply(Coord, {schema_commit, Tid, self()}) end, @@ -1978,7 +1992,7 @@ sync_send_dirty(Tid, [Head | Tail], Tab, WaitFor) -> Res = do_dirty(Tid, Head), {WF, Res}; true -> - {?MODULE, Node} ! {self(), {sync_dirty, Tid, ext_format(Head), Tab}}, + {?MODULE, Node} ! {self(), {sync_dirty, Tid, Head, Tab}}, sync_send_dirty(Tid, Tail, Tab, [Node | WaitFor]) end; sync_send_dirty(_Tid, [], _Tab, WaitFor) -> @@ -1997,11 +2011,11 @@ async_send_dirty(Tid, [Head | Tail], Tab, ReadNode, WaitFor, Res) -> NewRes = do_dirty(Tid, Head), async_send_dirty(Tid, Tail, Tab, ReadNode, WaitFor, NewRes); ReadNode == Node -> - {?MODULE, Node} ! {self(), {sync_dirty, Tid, ext_format(Head), Tab}}, + {?MODULE, Node} ! {self(), {sync_dirty, Tid, Head, Tab}}, NewRes = {'EXIT', {aborted, {node_not_running, Node}}}, async_send_dirty(Tid, Tail, Tab, ReadNode, [Node | WaitFor], NewRes); true -> - {?MODULE, Node} ! {self(), {async_dirty, Tid, ext_format(Head), Tab}}, + {?MODULE, Node} ! {self(), {async_dirty, Tid, Head, Tab}}, async_send_dirty(Tid, Tail, Tab, ReadNode, WaitFor, Res) end; async_send_dirty(_Tid, [], _Tab, _ReadNode, WaitFor, Res) -> @@ -2058,24 +2072,20 @@ ask_commit(Protocol, Tid, [Head | Tail], DiscNs, RamNs, WaitFor, Local) -> Node == node() -> ask_commit(Protocol, Tid, Tail, DiscNs, RamNs, WaitFor, Head); true -> - CR = ext_format(Head), - Msg = {ask_commit, Protocol, Tid, CR, DiscNs, RamNs}, + Msg = {ask_commit, convert_old(Protocol, Node), Tid, Head, DiscNs, RamNs}, {?MODULE, Node} ! {self(), Msg}, ask_commit(Protocol, Tid, Tail, DiscNs, RamNs, [Node | WaitFor], Local) end; ask_commit(_Protocol, _Tid, [], _DiscNs, _RamNs, WaitFor, Local) -> {WaitFor, Local}. -ext_format(#commit{ext=[]}=CR) -> CR; -ext_format(#commit{node=Node, ext=Ext}=CR) -> +convert_old(sync_asym_trans, Node) -> case mnesia_monitor:needs_protocol_conversion(Node) of - true -> - case lists:keyfind(snmp, 1, Ext) of - false -> CR#commit{ext=[]}; - {snmp, List} -> CR#commit{ext=List} - end; - false -> CR - end. + true -> asym_trans; + false -> sync_asym_trans + end; +convert_old(Protocol, _) -> + Protocol. new_cr_format(#commit{ext=[]}=Cr) -> Cr; new_cr_format(#commit{ext=[{_,_}|_]}=Cr) -> Cr; @@ -2304,7 +2314,7 @@ reconfigure_participants(_, []) -> %% tell mnesia_tm on all involved nodes (including the local node) %% about the outcome. tell_outcome(Tid, Protocol, Node, CheckNodes, TellNodes) -> - Outcome = mnesia_recover:what_happened(Tid, Protocol, CheckNodes), + Outcome = mnesia_recover:what_happened(Tid, proto(Protocol), CheckNodes), case Outcome of aborted -> rpc:abcast(TellNodes, ?MODULE, {Tid,{do_abort, {mnesia_down, Node}}}); @@ -2313,6 +2323,9 @@ tell_outcome(Tid, Protocol, Node, CheckNodes, TellNodes) -> end, Outcome. +proto(sync_asym_trans) -> asym_trans; +proto(Proto) -> Proto. + do_stop(#state{coordinators = Coordinators}) -> Msg = {mnesia_down, node()}, lists:foreach(fun({Tid, _}) -> Tid#tid.pid ! Msg end, gb_trees:to_list(Coordinators)), diff --git a/lib/mnesia/test/mnesia_isolation_test.erl b/lib/mnesia/test/mnesia_isolation_test.erl index 49bcec14af..c99158945d 100644 --- a/lib/mnesia/test/mnesia_isolation_test.erl +++ b/lib/mnesia/test/mnesia_isolation_test.erl @@ -29,7 +29,7 @@ -export([no_conflict/1, simple_queue_conflict/1, advanced_queue_conflict/1, simple_deadlock_conflict/1, advanced_deadlock_conflict/1, schema_deadlock/1, lock_burst/1, - nasty/1, basic_sticky_functionality/1, + nasty/1, basic_sticky_functionality/1, sticky_sync/1, unbound1/1, unbound2/1, create_table/1, delete_table/1, move_table_copy/1, add_table_index/1, del_table_index/1, transform_table/1, @@ -71,7 +71,8 @@ groups() -> advanced_deadlock_conflict, schema_deadlock, lock_burst, {group, sticky_locks}, {group, unbound_locking}, {group, admin_conflict}, nasty]}, - {sticky_locks, [], [basic_sticky_functionality]}, + {sticky_locks, [], + [basic_sticky_functionality,sticky_sync]}, {unbound_locking, [], [unbound1, unbound2]}, {admin_conflict, [], [create_table, delete_table, move_table_copy, @@ -594,9 +595,49 @@ get_held() -> mnesia_locker ! {get_table, self(), mnesia_sticky_locks}, receive {mnesia_sticky_locks, Locks} -> Locks end. +sticky_sync(suite) -> []; +sticky_sync(Config) when is_list(Config) -> + %% BUG ERIERL-768 + Nodes = [N1, N2] = ?acquire_nodes(2, Config), + + mnesia:create_table(dc, [{type, ordered_set}, {disc_copies, Nodes}]), + mnesia:create_table(ec, [{type, ordered_set}, {ram_copies, [N2]}]), + + TestFun = + fun(I) -> + %% In first transaction we initialise {dc, I} record with value 0 + First = fun() -> + %% Do a lot of writes into ram copies table + %% which on the Slave in do_commit will be + %% processed first + lists:foreach(fun(J) -> ok = mnesia:write(ec, {ec, J, 0}, write) end, + lists:seq(1, 750)), + %% Then set initial value of {dc, I} record to 0 with sticky_write + mnesia:write(dc, {dc, I, 0}, sticky_write) + end, + ok = mnesia:activity(transaction, First), + %% In second transaction we set value of {dc, I} record to 1 + Upd = fun() -> + %% Modify a single ram copies record with ensured lock grant + %% (key not used in previous transactions) + %% we use this second table only to force asym_trans protocol + mnesia:write(ec, {ec, 1001 + I, 0}, write), + %% And set final version of {dc, I} record to 1 with sticky_write + mnesia:write(dc, {dc, I, 1}, sticky_write) + end, + ok = mnesia:activity(transaction, Upd) + end, + + %% Fill 1000 dc records. At the end all dc records should have value 1. + lists:foreach(TestFun, lists:seq(1,1000)), + io:format("Written, check content~n",[]), + All = fun() -> mnesia:select(dc, [ {{dc, '_', 0}, [] ,['$_']} ]) end, + ?match({atomic, []}, rpc:call(N1, mnesia, sync_transaction, [All])), + ?match({atomic, []}, rpc:call(N2, mnesia, sync_transaction, [All])), -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + ?verify_mnesia(Nodes, []). +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% unbound1(suite) -> []; unbound1(Config) when is_list(Config) -> @@ -1036,29 +1077,57 @@ add_table_copy(Config) when is_list(Config) -> Def = [{ram_copies, [ThisNode]}, {attributes, [key, attr1, attr2]}], ?match({atomic, ok}, mnesia:create_table(Tab, Def)), insert(Tab, 50), - {success, [A]} = ?start_activities([ThisNode]), + {success, [A]} = ?start_activities([ThisNode]), mnesia_test_lib:start_sync_transactions([A], 0), A ! fun() -> mnesia:write({Tab, 1, 1, updated}) end, ?match_receive({A, ok}), %% A is executed - Pid = spawn_link(?MODULE, op, [self(), mnesia, add_table_copy, + Pid = spawn_link(?MODULE, op, [self(), mnesia, add_table_copy, [Tab, Node2, ram_copies]]), - + ?match_receive(timeout), %% op waits for locks occupied by A A ! end_trans, %% Kill A, locks should be released - ?match_receive({A,{atomic,end_trans}}), - - receive + ?match_receive({A,{atomic,end_trans}}), + + receive Msg -> ?match({Pid, {atomic, ok}}, Msg) after timer:seconds(20) -> ?error("Operation timed out", []) end, + ?match_receive({'EXIT', Pid, normal}), sys:get_status(whereis(mnesia_locker)), % Explicit sync, release locks is async - ?match([], mnesia:system_info(held_locks)), - ?match([], mnesia:system_info(lock_queue)), + ?match([], mnesia:system_info(held_locks)), + ?match([], mnesia:system_info(lock_queue)), + + {atomic, ok} = mnesia:del_table_copy(Tab, Node2), + Self = self(), + New = spawn_link(Node2, + fun () -> + application:stop(mnesia), + Self ! {self(), ok}, + io:format(user, "restart mnesia~n", []), + Self ! {self(), catch application:start(mnesia)} + end), + receive {New,ok} -> ok end, + + Add = fun Add() -> + case mnesia:add_table_copy(Tab, Node2, disc_copies) of + {atomic, ok} -> ok; + _R -> io:format(user, "aborted with reason ~p~n", [_R]), + timer:sleep(10), + Add() + end + end, + + ?match(ok, Add()), + ?match_receive({New,ok}), + + sys:get_status(whereis(mnesia_locker)), % Explicit sync, release locks is async + ?match([], mnesia:system_info(held_locks)), + ?match([], mnesia:system_info(lock_queue)), ok. del_table_copy(suite) -> []; diff --git a/lib/mnesia/test/mt b/lib/mnesia/test/mt index a398ee0422..b169734f56 100755 --- a/lib/mnesia/test/mt +++ b/lib/mnesia/test/mt @@ -34,8 +34,35 @@ erlcmd="erl -sname a $p $args -mnesia_test_timeout" erlcmd1="erl -sname a1 $p $args" erlcmd2="erl -sname a2 $p $args" -xterm -geometry 70x20+0+550 -T a1 -e $erlcmd1 & -xterm -geometry 70x20+450+550 -T a2 -e $erlcmd2 & +if test z"$MT_TERM" = z ; then + MT_TERM=xterm +fi + +case $MT_TERM in + xterm) + geom0="-geometry 142x40+0+0" + geom1="-geometry 70x20+0+550" + geom2="-geometry 70x20+480+550" + title="-T" + exec="-e" + ;; + gnome-terminal) + geom0="--geometry 142x40+0+0" + geom1="--geometry 70x20+0+740" + geom2="--geometry 70x20+700+740" + title="--title" + exec="--hide-menubar --" + ;; + *rxvt) + geom0="-geometry 142x40+0+0" + geom1="-geometry 70x20+0+680" + geom2="-geometry 70x20+630+680" + title="-title" + exec="-e" +esac + +$MT_TERM $geom1 $title a1 $exec $erlcmd1 & +$MT_TERM $geom2 $title a2 $exec $erlcmd2 & rm "$latest" 2>/dev/null ln -s "$log" "$latest" @@ -51,11 +78,6 @@ echo "Give the following command in order to see the outcome from node a@$h"":" echo "" echo " less test_log$$" -ostype=`uname -s` -if [ "$ostype" = "SunOS" ] ; then - /usr/openwin/bin/xterm -geometry 145x40+0+0 -T a -l -lf "$log" -e $erlcmd & -else - xterm -geometry 145x40+0+0 -T a -e script -f -c "$erlcmd" "$log" & -fi +$MT_TERM $geom0 $title a $exec script -f -c "$erlcmd" "$log" & tail -f "$log" | egrep 'Eval|<>ERROR|NYI' diff --git a/lib/observer/src/cdv_bin_cb.erl b/lib/observer/src/cdv_bin_cb.erl index 91d33474c8..819596b483 100644 --- a/lib/observer/src/cdv_bin_cb.erl +++ b/lib/observer/src/cdv_bin_cb.erl @@ -33,42 +33,43 @@ detail_pages() -> [{"Binary", fun init_bin_page/2}]. init_bin_page(Parent,{Type,Bin}) -> + Cs = observer_lib:colors(Parent), cdv_multi_wx:start_link( Parent, - [{"Format \~p",cdv_html_wx,{Type,format_bin_fun("~p",Bin)}}, - {"Format \~tp",cdv_html_wx,{Type,format_bin_fun("~tp",Bin)}}, - {"Format \~w",cdv_html_wx,{Type,format_bin_fun("~w",Bin)}}, - {"Format \~tw",cdv_html_wx,{Type,format_bin_fun("~tw",Bin)}}, - {"Format \~s",cdv_html_wx,{Type,format_bin_fun("~s",Bin)}}, - {"Format \~ts",cdv_html_wx,{Type,format_bin_fun("~ts",Bin)}}, - {"Hex",cdv_html_wx,{Type,hex_binary_fun(Bin)}}, - {"Term",cdv_html_wx,{Type,binary_to_term_fun(Bin)}}]). + [{"Format \~p",cdv_html_wx,{Type,format_bin_fun("~p",Bin,Cs)}}, + {"Format \~tp",cdv_html_wx,{Type,format_bin_fun("~tp",Bin,Cs)}}, + {"Format \~w",cdv_html_wx,{Type,format_bin_fun("~w",Bin,Cs)}}, + {"Format \~tw",cdv_html_wx,{Type,format_bin_fun("~tw",Bin,Cs)}}, + {"Format \~s",cdv_html_wx,{Type,format_bin_fun("~s",Bin,Cs)}}, + {"Format \~ts",cdv_html_wx,{Type,format_bin_fun("~ts",Bin,Cs)}}, + {"Hex",cdv_html_wx,{Type,hex_binary_fun(Bin,Cs)}}, + {"Term",cdv_html_wx,{Type,binary_to_term_fun(Bin,Cs)}}]). -format_bin_fun(Format,Bin) -> +format_bin_fun(Format,Bin,Cs) -> fun() -> try io_lib:format(Format,[Bin]) of - Str -> plain_html(lists:flatten(Str)) + Str -> plain_html(lists:flatten(Str),Cs) catch error:badarg -> Warning = "This binary cannot be formatted with " ++ Format, - observer_html_lib:warning(Warning) + observer_html_lib:warning(Warning,Cs) end end. -binary_to_term_fun(Bin) -> +binary_to_term_fun(Bin,Cs) -> fun() -> try binary_to_term(Bin) of - Term -> plain_html(io_lib:format("~tp",[Term])) + Term -> plain_html(io_lib:format("~tp",[Term]),Cs) catch error:badarg -> Warning = "This binary cannot be converted to an Erlang term", - observer_html_lib:warning(Warning) + observer_html_lib:warning(Warning,Cs) end end. -define(line_break,25). -hex_binary_fun(Bin) -> +hex_binary_fun(Bin,Cs) -> fun() -> S = "<<" ++ format_hex(Bin,?line_break) ++ ">>", - plain_html(io_lib:format("~s",[S])) + plain_html(io_lib:format("~s",[S]), Cs) end. format_hex(<<>>,_) -> @@ -82,5 +83,5 @@ format_hex(<<B1:4,B2:4,Bin/binary>>,N) -> [integer_to_list(B1,16),integer_to_list(B2,16),$, | format_hex(Bin,N-1)]. -plain_html(Text) -> - observer_html_lib:plain_page(Text). +plain_html(Text,Cs) -> + observer_html_lib:plain_page(Text,Cs). diff --git a/lib/observer/src/cdv_html_wx.erl b/lib/observer/src/cdv_html_wx.erl index 8956173c93..83ee98de6e 100644 --- a/lib/observer/src/cdv_html_wx.erl +++ b/lib/observer/src/cdv_html_wx.erl @@ -30,7 +30,8 @@ %% Records -record(state, - {panel, + {parent, + panel, app, %% which tool is the user expand_table, expand_wins=[], @@ -62,7 +63,7 @@ init(ParentWin, HtmlText, Tab, App) -> HtmlWin = observer_lib:html_window(ParentWin), wxHtmlWindow:setPage(HtmlWin,HtmlText), wx_misc:endBusyCursor(), - {HtmlWin, #state{panel=HtmlWin,expand_table=Tab,app=App}}. + {HtmlWin, #state{parent=ParentWin, panel=HtmlWin,expand_table=Tab,app=App}}. init(ParentWin, Callback) -> {HtmlWin, State} = init(ParentWin, "", undefined, cdv), @@ -70,12 +71,15 @@ init(ParentWin, Callback) -> %%%%%%%%%%%%%%%%%%%%%%% Callbacks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -handle_info(active, #state{panel=HtmlWin,delayed_fetch=Callback}=State) +handle_info(active, #state{parent=Parent, panel=HtmlWin,delayed_fetch=Callback}=State) when Callback=/=undefined -> observer_lib:display_progress_dialog(HtmlWin, "Crashdump Viewer", "Reading data"), - {{expand,HtmlText,Tab},TW} = Callback:get_info(), + {{expand,Title,Info,Tab},TW} = Callback:get_info(), + Cs = observer_lib:colors(Parent), + HtmlText = observer_html_lib:expandable_term(Title,Info,Tab,Cs), + observer_lib:sync_destroy_progress_dialog(), wx_misc:beginBusyCursor(), wxHtmlWindow:setPage(HtmlWin,HtmlText), @@ -138,7 +142,8 @@ handle_event(#wx{event=#wxHtmlLink{type=command_html_link_clicked, list_to_integer(Key3)}}}, expand(Id,cdv_term_cb,State); _ when App =:= obs -> - observer ! {open_link, Target}; + observer ! {open_link, Target}, + State; _ -> cdv_virtual_list_wx:start_detail_win(Target), State diff --git a/lib/observer/src/cdv_mod_cb.erl b/lib/observer/src/cdv_mod_cb.erl index 2183e1aa3d..7f2cd0cf87 100644 --- a/lib/observer/src/cdv_mod_cb.erl +++ b/lib/observer/src/cdv_mod_cb.erl @@ -85,7 +85,8 @@ init_old_comp_page(Parent, Info) -> init_info_page(Parent, undefined) -> init_info_page(Parent, ""); init_info_page(Parent, String) -> - cdv_html_wx:start_link(Parent,observer_html_lib:plain_page(String)). + Cs = observer_lib:colors(Parent), + cdv_html_wx:start_link(Parent,observer_html_lib:plain_page(String,Cs)). format({Bin,q}) when is_binary(Bin) -> [$'|binary_to_list(Bin)]; diff --git a/lib/observer/src/cdv_persistent_cb.erl b/lib/observer/src/cdv_persistent_cb.erl index d5da18f7fc..90abc6a4f5 100644 --- a/lib/observer/src/cdv_persistent_cb.erl +++ b/lib/observer/src/cdv_persistent_cb.erl @@ -26,7 +26,4 @@ get_info() -> Tab = ets:new(pt_expand,[set,public]), {ok,PT,TW} = crashdump_viewer:persistent_terms(), - {{expand, - observer_html_lib:expandable_term("Persistent Terms",PT,Tab), - Tab}, - TW}. + {{expand, "Persistent Terms", PT, Tab}, TW}. diff --git a/lib/observer/src/cdv_proc_cb.erl b/lib/observer/src/cdv_proc_cb.erl index 2497b4889e..61bd86f188 100644 --- a/lib/observer/src/cdv_proc_cb.erl +++ b/lib/observer/src/cdv_proc_cb.erl @@ -108,7 +108,7 @@ init_stack_page(Parent, Info) -> init_memory_page(Parent, Info0, Tag, Heading) -> Info = proplists:get_value(Tag,Info0), Tab = proplists:get_value(expand_table,Info0), - Html = observer_html_lib:expandable_term(Heading,Info,Tab), + Html = observer_html_lib:expandable_term(Heading,Info,Tab, observer_lib:colors(Parent)), cdv_html_wx:start_link(Parent,{expand,Html,Tab}). init_ets_page(Parent, Info) -> diff --git a/lib/observer/src/cdv_term_cb.erl b/lib/observer/src/cdv_term_cb.erl index 85da1d227a..a2a7a8750d 100644 --- a/lib/observer/src/cdv_term_cb.erl +++ b/lib/observer/src/cdv_term_cb.erl @@ -35,31 +35,32 @@ init_term_page(ParentWin, {Type, [Term, Tab]}) -> Expanded = expand(Term, true), BinSaved = expand(Term, Tab), observer_lib:report_progress({ok,stop_pulse}), + Cs = observer_lib:colors(ParentWin), cdv_multi_wx:start_link( ParentWin, - [{"Format \~p",cdv_html_wx,{Type, format_term_fun("~p",BinSaved,Tab)}}, - {"Format \~tp",cdv_html_wx,{Type,format_term_fun("~tp",BinSaved,Tab)}}, - {"Format \~w",cdv_html_wx,{Type,format_term_fun("~w",BinSaved,Tab)}}, - {"Format \~tw",cdv_html_wx,{Type,format_term_fun("~tw",BinSaved,Tab)}}, - {"Format \~s",cdv_html_wx,{Type,format_term_fun("~s",Expanded,Tab)}}, - {"Format \~ts",cdv_html_wx,{Type,format_term_fun("~ts",Expanded,Tab)}}]). + [{"Format \~p",cdv_html_wx,{Type, format_term_fun("~p",BinSaved,Tab,Cs)}}, + {"Format \~tp",cdv_html_wx,{Type,format_term_fun("~tp",BinSaved,Tab,Cs)}}, + {"Format \~w",cdv_html_wx,{Type,format_term_fun("~w",BinSaved,Tab,Cs)}}, + {"Format \~tw",cdv_html_wx,{Type,format_term_fun("~tw",BinSaved,Tab,Cs)}}, + {"Format \~s",cdv_html_wx,{Type,format_term_fun("~s",Expanded,Tab,Cs)}}, + {"Format \~ts",cdv_html_wx,{Type,format_term_fun("~ts",Expanded,Tab,Cs)}}]). -format_term_fun(Format,Term,Tab) -> +format_term_fun(Format,Term,Tab,Cs) -> fun() -> observer_lib:report_progress({ok,"Formatting term"}), observer_lib:report_progress({ok,start_pulse}), try io_lib:format(Format,[Term]) of - Str -> {expand, plain_html(Str), Tab} + Str -> {expand, plain_html(Str,Cs), Tab} catch error:badarg -> Warning = "This term cannot be formatted with " ++ Format, - observer_html_lib:warning(Warning) + observer_html_lib:warning(Warning,Cs) after observer_lib:report_progress({ok,stop_pulse}) end end. -plain_html(Text) -> - observer_html_lib:plain_page(Text). +plain_html(Text,Cs) -> + observer_html_lib:plain_page(Text,Cs). expand(['#CDVBin',Offset,Size,Pos], true) -> {ok,Bin} = crashdump_viewer:expand_binary({Offset,Size,Pos}), diff --git a/lib/observer/src/cdv_virtual_list_wx.erl b/lib/observer/src/cdv_virtual_list_wx.erl index 14877b7eab..51e85e17c1 100644 --- a/lib/observer/src/cdv_virtual_list_wx.erl +++ b/lib/observer/src/cdv_virtual_list_wx.erl @@ -96,8 +96,9 @@ start_detail_win_2(Callback,Id) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init([ParentWin, Callback, Owner]) -> - {Holder,TW} = spawn_table_holder(Callback, Owner), Panel = wxPanel:new(ParentWin), + Attrs = observer_lib:create_attrs(Panel), + {Holder,TW} = spawn_table_holder(Callback, Owner, Attrs), {Grid,MenuCols} = create_list_box(Panel, Holder, Callback, Owner), Sizer = wxBoxSizer:new(?wxVERTICAL), wxSizer:add(Sizer, Grid, [{flag, ?wxEXPAND bor ?wxALL}, @@ -233,7 +234,8 @@ handle_call(new_dump, _From, Ref = erlang:monitor(process,Holder), Holder ! stop, receive {'DOWN',Ref,_,_,_} -> ok end, - {NewHolder,TW} = spawn_table_holder(Callback, all), + Attrs = observer_lib:create_attrs(Grid), + {NewHolder,TW} = spawn_table_holder(Callback, all, Attrs), {reply, ok, State#state{detail_wins=[],holder=NewHolder,trunc_warn=TW}}; handle_call(Msg, _From, State) -> @@ -329,9 +331,8 @@ handle_event(Event, State) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%TABLE HOLDER%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -spawn_table_holder(Callback, Owner) -> +spawn_table_holder(Callback, Owner, Attrs) -> {Info,TW} = Callback:get_info(Owner), - Attrs = observer_lib:create_attrs(), Parent = self(), Holder = case Owner of diff --git a/lib/observer/src/cdv_wx.erl b/lib/observer/src/cdv_wx.erl index 7100cc8790..8ad5da857e 100644 --- a/lib/observer/src/cdv_wx.erl +++ b/lib/observer/src/cdv_wx.erl @@ -197,8 +197,7 @@ setup(#state{frame=Frame, notebook=Notebook}=State) -> MemPanel = add_page(Notebook, ?MEM_STR, cdv_multi_wx, cdv_mem_cb), %% Persistent Terms Panel - PersistentPanel = add_page(Notebook, ?PERSISTENT_STR, - cdv_html_wx, cdv_persistent_cb), + PersistentPanel = add_page(Notebook, ?PERSISTENT_STR, cdv_html_wx, cdv_persistent_cb), %% Memory Panel IntPanel = add_page(Notebook, ?INT_STR, cdv_multi_wx, cdv_int_tab_cb), diff --git a/lib/observer/src/observer_app_wx.erl b/lib/observer/src/observer_app_wx.erl index 8c3eef5411..c4527ba063 100644 --- a/lib/observer/src/observer_app_wx.erl +++ b/lib/observer/src/observer_app_wx.erl @@ -48,7 +48,7 @@ usegc = false }). --record(paint, {font, pen, brush, sel, links}). +-record(paint, {font, fg, pen, brush, sel, links}). -record(app, {ptree, n2p, links, dim}). -record(box, {x,y, w,h, s1}). @@ -92,7 +92,8 @@ init([Notebook, Parent, _Config]) -> Extra = wxBoxSizer:new(?wxVERTICAL), DrawingArea = wxScrolledWindow:new(P2, [{winid, ?DRAWAREA}, {style,?wxFULL_REPAINT_ON_RESIZE}]), - wxWindow:setBackgroundColour(DrawingArea, ?wxWHITE), + BG = wxWindow:getBackgroundColour(Apps), + wxWindow:setBackgroundStyle(DrawingArea, ?wxBG_STYLE_SYSTEM), wxWindow:setVirtualSize(DrawingArea, 800, 800), wxSplitterWindow:setMinimumPaneSize(Splitter,50), wxSizer:add(Extra, DrawingArea, [{flag, ?wxEXPAND},{proportion, 1}]), @@ -127,7 +128,17 @@ init([Notebook, Parent, _Config]) -> Font0 end, SelCol = wxSystemSettings:getColour(?wxSYS_COLOUR_HIGHLIGHT), - GreyBrush = wxBrush:new({230,230,240}), + {Fg,BGBrush,Pen} = + case observer_lib:is_darkmode(BG) of + false -> + {wxSystemSettings:getColour(?wxSYS_COLOUR_BTNTEXT), + wxBrush:new(wxSystemSettings:getColour(?wxSYS_COLOUR_BTNSHADOW)), + wxPen:new({80,80,80}, [{width, Scale * 2}])}; + true -> + {wxSystemSettings:getColour(?wxSYS_COLOUR_BTNTEXT), + wxBrush:new(wxSystemSettings:getColour(?wxSYS_COLOUR_BTNSHADOW)), + wxPen:new({0,0,0}, [{width, Scale * 2}])} + end, SelBrush = wxBrush:new(SelCol), LinkPen = wxPen:new(SelCol, [{width, Scale * 2}]), process_flag(trap_exit, true), @@ -137,8 +148,9 @@ init([Notebook, Parent, _Config]) -> app_w =DrawingArea, usegc = UseGC, paint=#paint{font = Font, - pen = wxPen:new({80,80,80}, [{width, Scale * 2}]), - brush= GreyBrush, + fg = Fg, + pen = Pen, + brush= BGBrush, sel = SelBrush, links= LinkPen } @@ -306,11 +318,11 @@ handle_info({delivery, _Pid, app, _Curr, {[], [], [], []}}, handle_info({delivery, Pid, app, Curr, AppData}, State = #state{panel=Panel, appmon=Pid, current=Curr, usegc=UseGC, - app_w=AppWin, paint=#paint{font=Font}}) -> + app_w=AppWin, paint=#paint{fg=Fg, font=Font}}) -> GC = if UseGC -> {?wxGC:create(AppWin), false}; true -> {false, wxWindowDC:new(AppWin)} end, - setFont(GC, Font, {0,0,0}), + setFont(GC, Font, Fg), App = build_tree(AppData, GC), destroy_gc(GC), setup_scrollbar(AppWin, App), @@ -508,13 +520,13 @@ tree_map([], _ , Acc) -> Acc. draw(_DC, undefined, _, _) -> ok; draw(DC, #app{dim={_W,_H}, ptree=Tree, links=Links}, Sel, - #paint{font=Font, pen=Pen, brush=Brush, links=LPen, sel=SelBrush}) -> + #paint{font=Font, fg=Fg, pen=Pen, brush=Brush, links=LPen, sel=SelBrush}) -> setPen(DC, LPen), [draw_xlink(Link, DC) || Link <- Links], setPen(DC, Pen), %% ?wxGC:drawRectangle(DC, 2,2, _W-2,_H-2), %% DEBUG setBrush(DC, Brush), - setFont(DC, Font, {0,0,0}), + setFont(DC, Font, Fg), draw_tree(Tree, root, DC), case Sel of undefined -> ok; diff --git a/lib/observer/src/observer_defs.hrl b/lib/observer/src/observer_defs.hrl index 504d0877d9..7902b32cba 100644 --- a/lib/observer/src/observer_defs.hrl +++ b/lib/observer/src/observer_defs.hrl @@ -36,6 +36,7 @@ check = false }). +-record(colors, {fg, even, odd}). -record(attrs, {even, odd, searched, deleted, changed_odd, changed_even, new_odd, new_even}). -define(EVEN(Row), ((Row rem 2) =:= 0)). -define(BG_EVEN, {230,230,250}). diff --git a/lib/observer/src/observer_html_lib.erl b/lib/observer/src/observer_html_lib.erl index c67fa28c6d..4c92a8faab 100644 --- a/lib/observer/src/observer_html_lib.erl +++ b/lib/observer/src/observer_html_lib.erl @@ -24,9 +24,9 @@ %% viewer. No logic or states are kept by this module. %% --export([plain_page/1, - expandable_term/3, - warning/1]). +-export([plain_page/2, + expandable_term/4, + warning/2]). -include("crashdump_viewer.hrl"). -include("observer_defs.hrl"). @@ -34,8 +34,9 @@ %%%----------------------------------------------------------------- %%% Display the given information as is, no heading %%% Empty body if no info exists. -warning(Info) -> - header(body(warning_body(Info))). +warning(Info, Colors0) -> + Colors = convert(Colors0), + header(body(warning_body(Info), Colors)). warning_body(Info) -> [warn(Info)]. @@ -43,18 +44,22 @@ warning_body(Info) -> %%%----------------------------------------------------------------- %%% Display the given information as is, no heading %%% Empty body if no info exists. -plain_page(Info) -> - header(body(plain_body(Info))). +plain_page(Info, Colors0) -> + Colors = convert(Colors0), + header(body(plain_body(Info), Colors)). plain_body(Info) -> [pre(href_proc_port(lists:flatten(Info)))]. %%%----------------------------------------------------------------- %%% Expanded memory -expandable_term(Heading,Expanded,Tab) -> - header(Heading,body(expandable_term_body(Heading,Expanded,Tab))). +expandable_term(Heading,Expanded,Tab, Colors0) -> + Colors = convert(Colors0), + header(Heading, + body(expandable_term_body(Heading,Expanded,Tab,Colors), + Colors)). -expandable_term_body(Heading,[],_Tab) -> +expandable_term_body(Heading,[],_Tab, _) -> [case Heading of "MsgQueue" -> "No messages were found"; "Message Queue" -> "No messages were found"; @@ -65,7 +70,7 @@ expandable_term_body(Heading,[],_Tab) -> "SaslLog" -> "No log entry was found"; "Persistent Terms" -> "No persistent terms were found" end]; -expandable_term_body(Heading,Expanded,Tab) -> +expandable_term_body(Heading,Expanded,Tab, Colors) -> Attr = "BORDER=0 CELLPADDING=0 CELLSPACING=1 WIDTH=100%", [case Heading of "MsgQueue" -> @@ -74,7 +79,7 @@ expandable_term_body(Heading,Expanded,Tab) -> [th("WIDTH=70%","Message"), th("WIDTH=30%","SeqTraceToken")]) | element(1, lists:mapfoldl(fun(Msg, Even) -> - {msgq_table(Tab, Msg, Even), + {msgq_table(Tab, Msg, Even, Colors), not Even} end, true, Expanded))]); @@ -84,7 +89,7 @@ expandable_term_body(Heading,Expanded,Tab) -> [th("WIDTH=10%","Id"), th("WIDTH=90%","Message")]) | element(1, lists:mapfoldl(fun(Msg, {Even,N}) -> - {msgq_table(Tab, Msg, N, Even), + {msgq_table(Tab, Msg, N, Even, Colors), {not Even, N+1}} end, {true,1}, Expanded))]); @@ -94,7 +99,7 @@ expandable_term_body(Heading,Expanded,Tab) -> [th("WIDTH=20%","Label"), th("WIDTH=80%","Term")]) | element(1, lists:mapfoldl(fun(Entry, Even) -> - {stackdump_table(Tab, Entry, Even), + {stackdump_table(Tab, Entry, Even, Colors), not Even} end, true, Expanded))]); "ProcState" -> @@ -103,7 +108,7 @@ expandable_term_body(Heading,Expanded,Tab) -> [th("WIDTH=20%","Label"), th("WIDTH=80%","Information")]) | element(1, lists:mapfoldl(fun(Entry, Even) -> - {proc_state(Tab, Entry,Even), + {proc_state(Tab, Entry,Even, Colors), not Even} end, true, Expanded))]); "SaslLog" -> @@ -115,37 +120,37 @@ expandable_term_body(Heading,Expanded,Tab) -> [th("WIDTH=30%","Key"), th("WIDTH=70%","Value")]) | element(1, lists:mapfoldl(fun(Entry, Even) -> - {dict_table(Tab, Entry,Even), + {dict_table(Tab, Entry, Even, Colors), not Even} end, true, Expanded))]) end]. -msgq_table(Tab,{Msg0,Token0}, Even) -> +msgq_table(Tab,{Msg0,Token0}, Even, Colors) -> Token = case Token0 of [] -> ""; _ -> io_lib:fwrite("~w",[Token0]) end, Msg = all_or_expand(Tab,Msg0), - tr(color(Even),[td(pre(Msg)), td(Token)]). + tr(color(Even, Colors),[td(pre(Msg)), td(Token)]). -msgq_table(Tab,Msg0, Id, Even) -> +msgq_table(Tab,Msg0, Id, Even, Colors) -> Msg = all_or_expand(Tab,Msg0), - tr(color(Even),[td(integer_to_list(Id)), td(pre(Msg))]). + tr(color(Even, Colors),[td(integer_to_list(Id)), td(pre(Msg))]). -stackdump_table(Tab,{Label0,Term0},Even) -> +stackdump_table(Tab,{Label0,Term0},Even, Colors) -> Label = io_lib:format("~w",[Label0]), Term = all_or_expand(Tab,Term0), - tr(color(Even), [td("VALIGN=center",pre(Label)), td(pre(Term))]). + tr(color(Even, Colors), [td("VALIGN=center",pre(Label)), td(pre(Term))]). -dict_table(Tab,{Key0,Value0}, Even) -> +dict_table(Tab,{Key0,Value0}, Even, Colors) -> Key = all_or_expand(Tab,Key0), Value = all_or_expand(Tab,Value0), - tr(color(Even), [td("VALIGN=center",pre(Key)), td(pre(Value))]). + tr(color(Even, Colors), [td("VALIGN=center",pre(Key)), td(pre(Value))]). -proc_state(Tab,{Key0,Value0}, Even) -> +proc_state(Tab,{Key0,Value0}, Even, Colors) -> Key = lists:flatten(io_lib:format("~ts",[Key0])), Value = all_or_expand(Tab,Value0), - tr(color(Even), [td("VALIGN=center",Key), td(pre(Value))]). + tr(color(Even, Colors), [td("VALIGN=center",Key), td(pre(Value))]). all_or_expand(Tab,Term) -> Preview = io_lib:format("~tP",[Term,8]), @@ -171,8 +176,8 @@ all_or_expand(Tab,Bin,_PreviewStr,_Expand) Term = io_lib:format("~tp", [OBSBin]), href_proc_port(lists:flatten(Term), true). -color(true) -> io_lib:format("BGCOLOR=\"#~2.16.0B~2.16.0B~2.16.0B\"", tuple_to_list(?BG_EVEN)); -color(false) -> io_lib:format("BGCOLOR=\"#~2.16.0B~2.16.0B~2.16.0B\"", tuple_to_list(?BG_ODD)). +color(true, #colors{even=Even}) -> "BGCOLOR="++Even; +color(false,#colors{odd=Odd}) -> "BGCOLOR="++Odd. %%%----------------------------------------------------------------- %%% Internal library @@ -180,10 +185,10 @@ start_html() -> "<HTML>\n". stop_html() -> "</HTML>". -start_html_body() -> - "<BODY BGCOLOR=\"#FFFFFF\">\n". +start_html_body(#colors{even=Even, fg=Fg}) -> + "<BODY BGCOLOR=" ++ Even ++ ">\n <FONT COLOR=" ++ Fg ++ ">\n". stop_html_body() -> - "</BODY>\n". + "</FONT> </BODY>\n". header(Body) -> header("","",Body). @@ -205,8 +210,8 @@ only_html_header(Title,JavaScript) -> JavaScript, "</HEAD>\n"]. -body(Text) -> - [start_html_body(), +body(Text, Colors) -> + [start_html_body(Colors), Text, stop_html_body()]. @@ -417,3 +422,8 @@ warn([]) -> []; warn(Warning) -> font("COLOR=\"#FF0000\"",p([Warning,br(),br()])). + +convert(#colors{fg={FR,FB,FG}, even={ER,EB,EG}, odd={OR,OG,OB}}) -> + #colors{fg = io_lib:format("\"#~2.16.0B~2.16.0B~2.16.0B\"", [FR,FB,FG]), + even = io_lib:format("\"#~2.16.0B~2.16.0B~2.16.0B\"", [ER,EB,EG]), + odd = io_lib:format("\"#~2.16.0B~2.16.0B~2.16.0B\"", [OR,OG,OB])}. diff --git a/lib/observer/src/observer_lib.erl b/lib/observer/src/observer_lib.erl index 7c68b0ebb6..7d115306bd 100644 --- a/lib/observer/src/observer_lib.erl +++ b/lib/observer/src/observer_lib.erl @@ -28,8 +28,8 @@ interval_dialog/4, start_timer/1, start_timer/2, stop_timer/1, timer_config/1, display_info/2, display_info/3, fill_info/2, update_info/2, to_str/1, create_menus/3, create_menu_item/3, - create_attrs/0, - set_listctrl_col_size/2, + is_darkmode/1, colors/1, create_attrs/1, + set_listctrl_col_size/2, mix/3, create_status_bar/1, html_window/1, html_window/2, make_obsbin/2, @@ -373,26 +373,44 @@ create_menu_item(separator, Menu, Index) -> wxMenu:insertSeparator(Menu, Index), Index+1. -create_attrs() -> - Font = wxSystemSettings:getFont(?wxSYS_DEFAULT_GUI_FONT), +colors(Window) -> + DarkMode = is_darkmode(wxWindow:getBackgroundColour(Window)), Text = case wxSystemSettings:getColour(?wxSYS_COLOUR_LISTBOXTEXT) of - {255,255,255,_} -> {10,10,10}; %% Is white on Mac for some reason - Color -> Color - end, - #attrs{even = wxListItemAttr:new(Text, ?BG_EVEN, Font), - odd = wxListItemAttr:new(Text, ?BG_ODD, Font), - deleted = wxListItemAttr:new(?FG_DELETED, ?BG_DELETED, Font), - changed_even = wxListItemAttr:new(Text, mix(?BG_CHANGED,?BG_EVEN), Font), - changed_odd = wxListItemAttr:new(Text, mix(?BG_CHANGED,?BG_ODD), Font), - new_even = wxListItemAttr:new(Text, mix(?BG_NEW,?BG_EVEN), Font), - new_odd = wxListItemAttr:new(Text, mix(?BG_NEW, ?BG_ODD), Font), - searched = wxListItemAttr:new(Text, ?BG_SEARCHED, Font) - }. - -mix(RGB,_) -> RGB. - -%% mix({R,G,B},{MR,MG,MB}) -> -%% {trunc(R*MR/255), trunc(G*MG/255), trunc(B*MB/255)}. + {255,255,255,_} when not DarkMode -> {10,10,10}; %% Is white on Mac for some reason + Color -> Color + end, + Even = wxSystemSettings:getColour(?wxSYS_COLOUR_LISTBOX), + Odd = mix(Even, wxSystemSettings:getColour(?wxSYS_COLOUR_HIGHLIGHT), 0.8), + #colors{fg=rgb(Text), even=rgb(Even), odd=rgb(Odd)}. + +create_attrs(Window) -> + Font = wxSystemSettings:getFont(?wxSYS_DEFAULT_GUI_FONT), + #colors{fg=Text, even=Even, odd=Odd} = colors(Window), + #attrs{even = wxListItemAttr:new(Text, Even, Font), + odd = wxListItemAttr:new(Text, Odd, Font), + deleted = wxListItemAttr:new(?FG_DELETED, ?BG_DELETED, Font), + changed_even = wxListItemAttr:new(Text, mix(?BG_CHANGED, ?BG_EVEN, 0.9), Font), + changed_odd = wxListItemAttr:new(Text, mix(?BG_CHANGED, ?BG_ODD, 0.9), Font), + new_even = wxListItemAttr:new(Text, mix(?BG_NEW, ?BG_EVEN, 0.9), Font), + new_odd = wxListItemAttr:new(Text, mix(?BG_NEW, ?BG_ODD, 0.9), Font), + searched = wxListItemAttr:new(Text, ?BG_SEARCHED, Font) + }. + +rgb({R,G,B,_}) -> {R,G,B}; +rgb({_,_,_}=RGB) -> RGB. + +mix(RGB,{MR,MG,MB,_}, V) -> + mix(RGB, {MR,MG,MB}, V); +mix({R,G,B,_}, RGB, V) -> + mix({R,G,B}, RGB, V); +mix({R,G,B},{MR,MG,MB}, V) when V =< 1.0 -> + {min(255, round(R*V+MR*(1.0-V))), + min(255, round(G*V+MG*(1.0-V))), + min(255, round(B*V+MB*(1.0-V)))}. + + +is_darkmode({R,G,B,_}) -> + ((R+G+B) div 3) < 100. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/lib/observer/src/observer_perf_wx.erl b/lib/observer/src/observer_perf_wx.erl index 79271addf2..50a6d6a915 100644 --- a/lib/observer/src/observer_perf_wx.erl +++ b/lib/observer/src/observer_perf_wx.erl @@ -55,7 +55,7 @@ -define(wxGC, wxGraphicsContext). --record(paint, {font, small, pen, pen2, pens, dot_pens, usegc = false}). +-record(paint, {font, small, fg, pen, pen2, pens, dot_pens, usegc = false}). start_link(Notebook, Parent, Config) -> wx_object:start_link(?MODULE, [Notebook, Parent, Config], []). @@ -126,7 +126,16 @@ setup_graph_drawing(Panels) -> SF = wxFont:new(Scale * (DefSize-2), DefFamily, ?wxFONTSTYLE_NORMAL, ?wxFONTWEIGHT_NORMAL), {F, SF} end, - BlackPen = wxPen:new({0,0,0}, [{width, Scale}]), + BG = wxWindow:getBackgroundColour((hd(Panels))#win.panel), + Fg = case observer_lib:is_darkmode(BG) of + false -> {0,0,0}; + true -> wxSystemSettings:getColour(?wxSYS_COLOUR_BTNTEXT) + end, + + PenColor = case observer_lib:is_darkmode(BG) of + false -> {0,0,0}; + true -> {0,0,0} + end, Pens = [wxPen:new(Col, [{width, Scale}, {style, ?wxSOLID}]) || Col <- tuple_to_list(colors())], DotPens = [wxPen:new(Col, [{width, Scale}, {style, ?wxDOT}]) @@ -134,8 +143,9 @@ setup_graph_drawing(Panels) -> #paint{usegc = UseGC, font = Font, small = SmallFont, - pen = ?wxGREY_PEN, - pen2 = BlackPen, + fg = Fg, %% Text color + pen = wxPen:new(PenColor), + pen2 = wxPen:new(PenColor, [{width, Scale}]), pens = list_to_tuple(Pens), dot_pens = list_to_tuple(DotPens) }. @@ -525,7 +535,7 @@ draw_win(DC, #win{name=Name, no_samples=Samples, geom=#{scale:={WS,HS}}, DrawBs(), ok; -draw_win(DC, #win{no_samples=Samples} = Win,Ti, #paint{small=Small}=Paint) -> +draw_win(DC, #win{no_samples=Samples} = Win,Ti, #paint{fg=Fg, small=Small}=Paint) -> %% Draw Error Msg try draw_borders(DC, Ti, Win, Paint) of {X0,_Y0,DrawBs} -> @@ -533,7 +543,7 @@ draw_win(DC, #win{no_samples=Samples} = Win,Ti, #paint{small=Small}=Paint) -> true -> "Waiting for data"; false -> "Information not available" end, - setFont(DC, Small, {0,0,0}), + setFont(DC, Small, Fg), {_,WW} = getSize(DC), drawText(DC, Text, X0 + 100, WW div 2), DrawBs(), @@ -628,7 +638,7 @@ spline_tan(Y0, Y1, Y2, Y3) -> draw_borders(DC, #ti{secs=Secs, fetch=FetchFreq}, #win{name=Type, geom=Geom, info=Info, max={_,_,Unit,_}}, - #paint{pen=Pen, pen2=Pen2, font=Font, small=Small}) -> + #paint{pen=Pen, pen2=Pen2, fg=Fg, font=Font, small=Small}) -> #{p0:={GraphX0, GraphY0}, p1:={GraphX1,GraphY1}, scale:={ScaleW0,_}, txsz:={TW,TH,SpaceW}, txt:={BottomTextY, MaxTextY}, strs:={Str1,Str2,Str3}} = Geom, @@ -640,7 +650,7 @@ draw_borders(DC, #ti{secs=Secs, fetch=FetchFreq}, GraphY50 = GraphY0 + (GraphY1 - GraphY0) / 2, GraphY75 = GraphY0 + 3*(GraphY1 - GraphY0) / 4, - setFont(DC, Small, {0,0,0}), + setFont(DC, Small, Fg), Align = fun(Str, Y) -> {StrW, _} = getTextExtent(DC, Str), drawText(DC, Str, GraphX0 - StrW - ?BW, Y) @@ -670,11 +680,11 @@ draw_borders(DC, #ti{secs=Secs, fetch=FetchFreq}, strokeLine(DC, GraphX0-3, GraphY50, GraphX1, GraphY50), strokeLine(DC, GraphX0-3, GraphY75, GraphX1, GraphY75), - setFont(DC, Font, {0,0,0}), + setFont(DC, Font, Fg), Text = fun(X,Y, Str, PenId) -> if PenId == 0 -> - setFont(DC, Font, {0,0,0}); + setFont(DC, Font, Fg); PenId > 0 -> Id = 1 + ((PenId-1) rem tuple_size(colors())), setFont(DC, Font, element(Id, colors())) diff --git a/lib/observer/src/observer_port_wx.erl b/lib/observer/src/observer_port_wx.erl index 00cf1b5fba..5cb6d9bc22 100644 --- a/lib/observer/src/observer_port_wx.erl +++ b/lib/observer/src/observer_port_wx.erl @@ -61,7 +61,8 @@ inet}). -record(opt, {sort_key=2, - sort_incr=true + sort_incr=true, + odd_bg }). -record(state, @@ -111,7 +112,10 @@ init([Notebook, Parent, Config]) -> wxListCtrl:connect(Grid, size, [{skip, true}]), wxWindow:setFocus(Grid), - {Panel, #state{grid=Grid, parent=Parent, panel=Panel, timer=Config}}. + Even = wxSystemSettings:getColour(?wxSYS_COLOUR_LISTBOX), + Odd = observer_lib:mix(Even, wxSystemSettings:getColour(?wxSYS_COLOUR_HIGHLIGHT), 0.8), + Opt = #opt{odd_bg=Odd}, + {Panel, #state{grid=Grid, parent=Parent, panel=Panel, timer=Config, opt=Opt}}. handle_event(#wx{id=?ID_REFRESH}, State = #state{node=Node, grid=Grid, opt=Opt}) -> @@ -553,7 +557,7 @@ filter_monitor_info() -> update_grid(Grid, Sel, Opt, Ports) -> wx:batch(fun() -> update_grid2(Grid, Sel, Opt, Ports) end). -update_grid2(Grid, Sel, #opt{sort_key=Sort,sort_incr=Dir}, Ports) -> +update_grid2(Grid, Sel, #opt{sort_key=Sort,sort_incr=Dir, odd_bg=BG}, Ports) -> wxListCtrl:deleteAllItems(Grid), Update = fun(#port{id = Id, @@ -563,8 +567,8 @@ update_grid2(Grid, Sel, #opt{sort_key=Sort,sort_incr=Dir}, Ports) -> controls = Ctrl}, Row) -> _Item = wxListCtrl:insertItem(Grid, Row, ""), - if (Row rem 2) =:= 0 -> - wxListCtrl:setItemBackgroundColour(Grid, Row, ?BG_EVEN); + if (Row rem 2) =:= 1 -> + wxListCtrl:setItemBackgroundColour(Grid, Row, BG); true -> ignore end, diff --git a/lib/observer/src/observer_pro_wx.erl b/lib/observer/src/observer_pro_wx.erl index 4ab4a78462..6b359f3c44 100644 --- a/lib/observer/src/observer_pro_wx.erl +++ b/lib/observer/src/observer_pro_wx.erl @@ -94,7 +94,7 @@ start_link(Notebook, Parent, Config) -> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% init([Notebook, Parent, Config]) -> - Attrs = observer_lib:create_attrs(), + Attrs = observer_lib:create_attrs(Notebook), Self = self(), Acc = maps:get(acc, Config, false), Holder = spawn_link(fun() -> init_table_holder(Self, Acc, Attrs) end), diff --git a/lib/observer/src/observer_procinfo.erl b/lib/observer/src/observer_procinfo.erl index bd5fed0951..637a090a15 100644 --- a/lib/observer/src/observer_procinfo.erl +++ b/lib/observer/src/observer_procinfo.erl @@ -214,12 +214,14 @@ init_process_page(Panel, Pid) -> init_message_page(Parent, Pid, Table) -> Win = observer_lib:html_window(Parent), + Cs = observer_lib:colors(Parent), Update = fun() -> case observer_wx:try_rpc(node(Pid), erlang, process_info, [Pid, messages]) of {messages, Messages} -> - Html = observer_html_lib:expandable_term("Message Queue", Messages, Table), + Html = observer_html_lib:expandable_term("Message Queue", Messages, + Table, Cs), wxHtmlWindow:setPage(Win, Html); _ -> throw(process_undefined) @@ -230,11 +232,12 @@ init_message_page(Parent, Pid, Table) -> init_dict_page(Parent, Pid, Table) -> Win = observer_lib:html_window(Parent), + Cs = observer_lib:colors(Parent), Update = fun() -> case observer_wx:try_rpc(node(Pid), erlang, process_info, [Pid, dictionary]) of {dictionary,Dict} -> - Html = observer_html_lib:expandable_term("Dictionary", Dict, Table), + Html = observer_html_lib:expandable_term("Dictionary", Dict, Table, Cs), wxHtmlWindow:setPage(Win, Html); _ -> throw(process_undefined) @@ -254,6 +257,8 @@ init_stack_page(Parent, Pid) -> wxListCtrl:insertColumn(LCtrl, 1, Li), wxListCtrl:setColumnWidth(LCtrl, 1, Scale * 300), wxListItem:destroy(Li), + Even = wxSystemSettings:getColour(?wxSYS_COLOUR_LISTBOX), + Odd = observer_lib:mix(Even, wxSystemSettings:getColour(?wxSYS_COLOUR_HIGHLIGHT), 0.8), Update = fun() -> case observer_wx:try_rpc(node(Pid), erlang, process_info, [Pid, current_stacktrace]) @@ -262,8 +267,8 @@ init_stack_page(Parent, Pid) -> wxListCtrl:deleteAllItems(LCtrl), wx:foldl(fun({M, F, A, Info}, Row) -> _Item = wxListCtrl:insertItem(LCtrl, Row, ""), - ?EVEN(Row) andalso - wxListCtrl:setItemBackgroundColour(LCtrl, Row, ?BG_EVEN), + ?EVEN(Row) orelse + wxListCtrl:setItemBackgroundColour(LCtrl, Row, Odd), wxListCtrl:setItem(LCtrl, Row, 0, observer_lib:to_str({M,F,A})), FileLine = case Info of [{file,File},{line,Line}] -> @@ -288,9 +293,10 @@ init_stack_page(Parent, Pid) -> init_state_page(Parent, Pid, Table) -> Win = observer_lib:html_window(Parent), + Cs = observer_lib:colors(Parent), Update = fun() -> StateInfo = fetch_state_info(Pid), - Html = observer_html_lib:expandable_term("ProcState", StateInfo, Table), + Html = observer_html_lib:expandable_term("ProcState", StateInfo, Table, Cs), wxHtmlWindow:setPage(Win, Html) end, Update(), @@ -341,6 +347,7 @@ fetch_state_info2(Pid, M) -> init_log_page(Parent, Pid, Table) -> Win = observer_lib:html_window(Parent), + Cs = observer_lib:colors(Parent), Update = fun() -> Fd = spawn_link(fun() -> io_server() end), rpc:call(node(Pid), rb, rescan, [[{start_log, Fd}]]), @@ -353,7 +360,7 @@ init_log_page(Parent, Pid, Table) -> NbBlanks = length(Pref) - 1, Re = "(<" ++ Pref ++ "\.[^>]{1,}>)[ ]{"++ integer_to_list(NbBlanks) ++ "}", Look = re:replace(ExpPid, Re, "\\1", [global, {return, list}]), - Html = observer_html_lib:expandable_term("SaslLog", Look, Table), + Html = observer_html_lib:expandable_term("SaslLog", Look, Table, Cs), wxHtmlWindow:setPage(Win, Html) end, Update(), diff --git a/lib/observer/src/observer_tv_table.erl b/lib/observer/src/observer_tv_table.erl index 7bd67a0f0b..32d75f77d4 100644 --- a/lib/observer/src/observer_tv_table.erl +++ b/lib/observer/src/observer_tv_table.erl @@ -116,8 +116,8 @@ init([Parent, Opts]) -> TabId = table_id(Table), ColumnNames = column_names(Node, Source, TabId), KeyPos = key_pos(Node, Source, TabId), - - Attrs = observer_lib:create_attrs(), + Panel = wxPanel:new(Frame), + Attrs = observer_lib:create_attrs(Panel), Self = self(), Holder = spawn_link(fun() -> @@ -125,7 +125,6 @@ init([Parent, Opts]) -> length(ColumnNames), Node, Attrs) end), - Panel = wxPanel:new(Frame), Sizer = wxBoxSizer:new(?wxVERTICAL), Style = ?wxLC_REPORT bor ?wxLC_VIRTUAL bor ?wxLC_SINGLE_SEL bor ?wxLC_HRULES, Grid = wxListCtrl:new(Panel, [{style, Style}, diff --git a/lib/observer/src/observer_tv_wx.erl b/lib/observer/src/observer_tv_wx.erl index 9743a6ed42..d622b1423b 100644 --- a/lib/observer/src/observer_tv_wx.erl +++ b/lib/observer/src/observer_tv_wx.erl @@ -71,7 +71,7 @@ init([Notebook, Parent, Config]) -> Style = ?wxLC_REPORT bor ?wxLC_VIRTUAL bor ?wxLC_SINGLE_SEL bor ?wxLC_HRULES, Self = self(), - Attrs = observer_lib:create_attrs(), + Attrs = observer_lib:create_attrs(Panel), Holder = spawn_link(fun() -> init_table_holder(Self, Attrs) end), CBs = [{onGetItemText, fun(_, Item,Col) -> get_row(Holder, Item, Col) end}, {onGetItemAttr, fun(_, Item) -> get_attr(Holder, Item) end}], diff --git a/lib/observer/test/crashdump_helper.erl b/lib/observer/test/crashdump_helper.erl index 84ed99afa5..10d88c994a 100644 --- a/lib/observer/test/crashdump_helper.erl +++ b/lib/observer/test/crashdump_helper.erl @@ -48,7 +48,7 @@ n1_proc(Creator,_N2,Pid2,Port2,_L) -> Ref = make_ref(), Pid = self(), Bin = list_to_binary(lists:seq(1, 255)), - <<_:2,SubBin:17/binary,_/bits>> = Bin, + <<_:2,SubBin:65/binary,_/bits>> = Bin, register(named_port,Port), @@ -102,7 +102,7 @@ remote_proc(P1,Creator) -> end). create_binaries() -> - Sizes = lists:seq(60, 70) ++ lists:seq(120, 140), + Sizes = lists:seq(100, 120) ++ lists:seq(200, 240), [begin <<H:16/unit:8>> = erlang:md5(<<Size:32>>), Data = ((H bsl (8*150)) div (H+7919)), @@ -113,7 +113,7 @@ create_sub_binaries(Bins) -> [create_sub_binary(Bin, Start, LenSub) || Bin <- Bins, Start <- [0,1,2,3,4,5,10,22], - LenSub <- [0,1,2,3,4,6,9]]. + LenSub <- [0,1,2,3,4,6,9,65]]. create_sub_binary(Bin, Start, LenSub) -> Len = byte_size(Bin) - LenSub - Start, diff --git a/lib/parsetools/doc/src/leex.xml b/lib/parsetools/doc/src/leex.xml index 3b82f60201..3944c650d8 100644 --- a/lib/parsetools/doc/src/leex.xml +++ b/lib/parsetools/doc/src/leex.xml @@ -4,7 +4,7 @@ <erlref> <header> <copyright> - <year>2009</year><year>2017</year> + <year>2009</year><year>2019</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -193,7 +193,7 @@ Token = tuple()</code> but used through the i/o system where it can typically be called in an application by:</p> <code> -io:request(InFile, {get_until,Prompt,Module,token,[Line]}) +io:request(InFile, {get_until,unicode,Prompt,Module,token,[Line]}) -> TokenRet</code> </desc> </func> @@ -240,7 +240,7 @@ io:request(InFile, {get_until,Prompt,Module,token,[Line]}) but used through the i/o system where it can typically be called in an application by:</p> <code> -io:request(InFile, {get_until,Prompt,Module,tokens,[Line]}) +io:request(InFile, {get_until,unicode,Prompt,Module,tokens,[Line]}) -> TokensRet</code> </desc> </func> diff --git a/lib/public_key/src/pubkey_cert.erl b/lib/public_key/src/pubkey_cert.erl index 12c61e158f..d85f322918 100644 --- a/lib/public_key/src/pubkey_cert.erl +++ b/lib/public_key/src/pubkey_cert.erl @@ -1169,7 +1169,7 @@ validity(Opts) -> Format = fun({Y,M,D}) -> lists:flatten( - io_lib:format("~4..0w~2..0w~2..0w000000Z",[Y,M,D])) + io_lib:format("~4..0w~2..0w~2..0w130000Z",[Y,M,D])) end, #'Validity'{notBefore={generalTime, Format(DefFrom)}, notAfter ={generalTime, Format(DefTo)}}. diff --git a/lib/sasl/src/systools_lib.erl b/lib/sasl/src/systools_lib.erl index dd97aeff08..f5489e7900 100644 --- a/lib/sasl/src/systools_lib.erl +++ b/lib/sasl/src/systools_lib.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2016. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -63,8 +63,8 @@ read_term(File) -> end. read_term_from_stream(Stream, File) -> - _ = epp:set_encoding(Stream), - R = io:request(Stream, {get_until,'',erl_scan,tokens,[1]}), + Encoding = epp:set_encoding(Stream), + R = io:request(Stream, {get_until,Encoding,'',erl_scan,tokens,[1]}), case R of {ok,Toks,_EndLine} -> case erl_parse:parse_term(Toks) of diff --git a/lib/snmp/src/compile/snmpc_misc.erl b/lib/snmp/src/compile/snmpc_misc.erl index 312074f2e7..d0fee418e1 100644 --- a/lib/snmp/src/compile/snmpc_misc.erl +++ b/lib/snmp/src/compile/snmpc_misc.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2003-2016. All Rights Reserved. +%% Copyright Ericsson AB 2003-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -156,7 +156,8 @@ loop(Fd, Res, Func, StartLine, File) -> %% io:read modified to give us line numbers. %%----------------------------------------------------------------- read(Io, Prompt, StartLine) -> - case io:request(Io, {get_until, Prompt, erl_scan, tokens, [StartLine]}) of + Enc = latin1, + case io:request(Io, {get_until, Enc, Prompt, erl_scan, tokens, [StartLine]}) of {ok, Toks, EndLine} -> case erl_parse:parse_term(Toks) of {ok, Term} -> diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 20b7af0373..bec9d4d9d9 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -265,7 +265,8 @@ open_file(File) -> end. do_read(Io, Prompt, StartLine) -> - case io:request(Io, {get_until,Prompt,erl_scan,tokens,[StartLine]}) of + Enc = latin1, + case io:request(Io, {get_until,Enc,Prompt,erl_scan,tokens,[StartLine]}) of {ok, Toks, EndLine} -> case erl_parse:parse_term(Toks) of {ok, Term} -> diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 3104f2a096..5aab9a74e0 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -2737,7 +2737,8 @@ read_lines(Fd, Acc, StartLine) -> end. read_and_parse_term(Fd, StartLine) -> - case io:request(Fd, {get_until, "", erl_scan, tokens, [StartLine]}) of + Enc = latin1, + case io:request(Fd, {get_until, Enc, "", erl_scan, tokens, [StartLine]}) of {ok, Tokens, EndLine} -> case erl_parse:parse_term(Tokens) of {ok, Term} -> diff --git a/lib/ssh/doc/src/ssh_client_channel.xml b/lib/ssh/doc/src/ssh_client_channel.xml index cd28b95fd3..e6683dbd0b 100644 --- a/lib/ssh/doc/src/ssh_client_channel.xml +++ b/lib/ssh/doc/src/ssh_client_channel.xml @@ -150,12 +150,12 @@ <tag><c>{init_args(), list()}</c></tag> <item><p>The list of arguments to the <c>init</c> function of the callback module.</p></item> - <tag><c>{cm, ssh:connection_ref()}</c></tag> + <tag><c>{cm, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>}</c></tag> <item><p>Reference to the <c>ssh</c> connection as returned by <seealso marker="ssh#connect-3">ssh:connect/3</seealso>. </p></item> - <tag><c>{channel_id, ssh:channel_id()}</c></tag> + <tag><c>{channel_id, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>}</c></tag> <item><p>Id of the <c>ssh</c> channel as returned by <seealso marker="ssh_connection#session_channel/2">ssh_connection:session_channel/2,4</seealso>. </p></item> @@ -198,7 +198,7 @@ {ok, ChannelRef} | {error, Reason}</name> <fsummary>Starts a process that handles an SSH channel.</fsummary> <type> - <v>SshConnection = ssh:connection_ref()</v> + <v>SshConnection = <seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso></v> <d>As returned by <seealso marker="ssh#connect-3">ssh:connect/3</seealso></d> <v>ChannelId = <seealso marker="ssh#type-channel_id">ssh:channel_id()</seealso></v> @@ -374,7 +374,7 @@ function and all channels are to handle the following message.</p> <taglist> - <tag><c>{ssh_channel_up, ssh:channel_id(), ssh:connection_ref()}</c></tag> + <tag><c>{ssh_channel_up, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>}</c></tag> <item><p>This is the first message that the channel receives. It is sent just before the <seealso marker="#init-1">init/1</seealso> function @@ -393,21 +393,21 @@ ChannelId, State}</name> <fsummary>Handles <c>ssh</c> connection protocol messages.</fsummary> <type> - <v>Msg = ssh_connection:event()</v> + <v>Msg = <seealso marker="ssh_connection#type-event">ssh_connection:event()</seealso></v> <v>ChannelId = <seealso marker="ssh#type-channel_id">ssh:channel_id()</seealso></v> <v>State = term()</v> </type> <desc> <p>Handles SSH Connection Protocol messages that may need service-specific attention. For details, - see <seealso marker="ssh_connection"> ssh_connection:event()</seealso>. + see <seealso marker="ssh_connection#type-event">ssh_connection:event()</seealso>. </p> <p>The following message is taken care of by the <c>ssh_client_channel</c> behavior.</p> <taglist> - <tag><c>{closed, ssh:channel_id()}</c></tag> + <tag><c>{closed, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>}</c></tag> <item><p>The channel behavior sends a close message to the other side, if such a message has not already been sent. Then it terminates the channel with reason <c>normal</c>.</p></item> diff --git a/lib/ssh/doc/src/ssh_connection.xml b/lib/ssh/doc/src/ssh_connection.xml index 2a701929f6..9fa1da659c 100644 --- a/lib/ssh/doc/src/ssh_connection.xml +++ b/lib/ssh/doc/src/ssh_connection.xml @@ -40,128 +40,119 @@ <p>The <url href="http://www.ietf.org/rfc/rfc4254.txt">SSH Connection Protocol</url> is used by clients and servers, that is, SSH channels, to communicate over the SSH connection. The API functions in this module send SSH Connection Protocol events, - which are received as messages by the remote channel. - If the receiving channel is an Erlang process, the - messages have the format - <c><![CDATA[{ssh_cm, connection_ref(), ssh_event_msg()}]]></c>. + which are received as messages by the remote channel handling the remote channel. + The Erlang format of thoose messages is + (see also <seealso marker="#type-event">below</seealso>): + </p> + <p><c>{ssh_cm, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>, </c><seealso marker="#type-channel_msg"><c>channel_msg()</c></seealso><c>}</c> + </p> + <p> If the <seealso marker="ssh_client_channel">ssh_client_channel</seealso> behavior is used to implement the channel process, these messages are handled by <seealso marker="ssh_client_channel#Module:handle_ssh_msg-2">handle_ssh_msg/2</seealso>.</p> </description> - <section> - <title>DATA TYPES</title> - - <p>Type definitions that are used more than once in this module, - or abstractions to indicate the intended use of the data - type, or both:</p> - - <taglist> - <tag><c>boolean() =</c></tag> - <item><p><c>true | false </c></p></item> - <tag><c>string() =</c></tag> - <item><p>list of ASCII characters</p></item> - <tag><c>timeout() =</c></tag> - <item><p><c>infinity | integer()</c> in milliseconds</p></item> - <tag><c>connection_ref() =</c></tag> - <item><p>opaque() -as returned by - <c>ssh:connect/3</c> or sent to an SSH channel processes</p></item> - <tag><c>channel_id() =</c></tag> - <item><p><c>integer()</c></p></item> - <tag><c>ssh_data_type_code() =</c></tag> - <item><p><c>1</c> ("stderr") | <c>0</c> ("normal") are - valid values, see - <url href="http://www.ietf.org/rfc/rfc4254.txt">RFC 4254</url> Section 5.2.</p></item> - <tag><c>ssh_request_status() =</c></tag> - <item><p> <c>success | failure</c></p></item> - <tag><c>event() =</c></tag> - <item><p><c>{ssh_cm, connection_ref(), ssh_event_msg()}</c></p></item> - <tag><c>ssh_event_msg() =</c></tag> - <item><p><c>data_events() | status_events() | terminal_events()</c></p></item> - <tag><c>reason() =</c></tag> - <item><p><c>timeout | closed</c></p></item> - </taglist> - - <taglist> - <tag><em>data_events()</em></tag> - <item> - <taglist> - <tag><c><![CDATA[{data, channel_id(), ssh_data_type_code(), Data :: binary()}]]></c></tag> - <item><p>Data has arrived on the channel. This event is sent as a - result of calling <seealso marker="ssh_connection#send-3"> - ssh_connection:send/[3,4,5]</seealso>.</p></item> - - <tag><c><![CDATA[{eof, channel_id()}]]></c></tag> - <item><p>Indicates that the other side sends no more data. - This event is sent as a result of calling <seealso - marker="ssh_connection#send_eof-2"> ssh_connection:send_eof/2</seealso>. - </p></item> - </taglist> - </item> + <datatypes> + <datatype> + <name name="ssh_data_type_code"/> + <desc> + <p>The valid values are <c>0</c> ("normal") and <c>1</c> ("stderr"), see + <url href="https://tools.ietf.org/html/rfc4254#page-8">RFC 4254, Section 5.2</url>.</p> + </desc> + </datatype> - <tag><em>status_events()</em></tag> - <item> + <datatype> + <name name="result"/> + <name name="reason"/> + <desc> + <p>The result of a call.</p> + <p>If the request reached the peer, was handled and the response + reached the requesting node the <seealso marker="#type-req_status">req_status()</seealso> + is the status reported from the peer.</p> + <p>If not, the <seealso marker="#type-reason">reason()</seealso> indicates what went wrong:</p> + <taglist> + <tag><c>closed</c></tag> + <item>indicates that the channel or connection was closed when trying to send the request + </item> + <tag><c>timeout</c></tag> + <item>indicates that the operation exceeded a time limit + </item> + </taglist> + </desc> + </datatype> - <taglist> - <tag><c><![CDATA[{signal, channel_id(), ssh_signal()}]]></c></tag> - <item><p>A signal can be delivered to the remote process/service - using the following message. Some systems do not support - signals, in which case they are to ignore this message. There is - currently no function to generate this event as the signals - referred to are on OS-level and not something generated by an - Erlang program.</p></item> + <datatype> + <name name="req_status"/> + <desc> + <p>The status of a request. + Coresponds to the <c>SSH_MSG_CHANNEL_SUCCESS</c> and <c>SSH_MSG_CHANNEL_FAILURE</c> values in + <url href="https://tools.ietf.org/html/rfc4254#section-5.4">RFC 4254, Section 5.4</url>. + </p> + </desc> + </datatype> - <tag><c><![CDATA[{exit_signal, channel_id(), ExitSignal :: string(), ErrorMsg ::string(), - LanguageString :: string()}]]></c></tag> + <datatype_title>SSH Connection Protocol: General</datatype_title> + <datatype> + <name name="event"/> + <name name="channel_msg"/> + <desc> + <p>As mentioned in the introduction, the + <url href="https://tools.ietf.org/html/rfc4254">SSH Connection Protocol</url> + events are handled as messages. When writing a channel handling process without using + the support by the <seealso marker="ssh_client_channel">ssh_client_channel</seealso> + behavior the process must handle thoose messages. + </p> + </desc> + </datatype> - <item><p>A remote execution can terminate violently because of a signal. - Then this message can be received. For details on valid string - values, see <url href="http://www.ietf.org/rfc/rfc4254.txt">RFC 4254</url> - Section 6.10, which shows a special case of these signals.</p></item> + <datatype> + <name name="want_reply"/> + <desc> + <p>Messages that include a <c>WantReply</c> expect the channel handling + process to call <seealso marker="ssh_connection#reply_request-4"> + ssh_connection:reply_request/4</seealso> + with the boolean value of <c>WantReply</c> as the second argument.</p> + </desc> + </datatype> - <tag><c><![CDATA[{exit_status, channel_id(), ExitStatus :: integer()}]]></c></tag> - <item><p>When the command running at the other end terminates, the - following message can be sent to return the exit status of the - command. A zero <c>exit_status</c> usually means that the command - terminated successfully. This event is sent as a result of calling - <seealso marker="ssh_connection#exit_status-3"> - ssh_connection:exit_status/3</seealso>.</p></item> - <tag><c><![CDATA[{closed, channel_id()}]]></c></tag> - <item><p>This event is sent as a result of calling - <seealso marker="ssh_connection#close-2">ssh_connection:close/2</seealso>. - Both the handling of this event and sending it are taken care of by the - <seealso marker="ssh_client_channel">ssh_client_channel</seealso> behavior.</p></item> - - </taglist> - </item> + <datatype_title>Data Transfer (RFC 4254, section 5.2)</datatype_title> + <datatype> + <name name="data_ch_msg"/> + <desc> + <p>Data has arrived on the channel. This event is sent as a result of calling + <seealso marker="ssh_connection#send-3"> ssh_connection:send/[3,4,5]</seealso>. + </p> + </desc> + </datatype> - <tag><em>terminal_events()</em></tag> - <item> - <p>Channels implementing a shell and command execution on the - server side are to handle the following messages that can be sent by client- - channel processes.</p> + <datatype_title>Closing a Channel (RFC 4254, section 5.3)</datatype_title> + <datatype> + <name name="eof_ch_msg"/> + <desc> + <p>Indicates that the other side sends no more data. This event is sent as a result of calling + <seealso marker="ssh_connection#send_eof-2"> ssh_connection:send_eof/2</seealso>. + </p> + </desc> + </datatype> + <datatype> + <name name="closed_ch_msg"/> + <desc> + <p>This event is sent as a result of calling + <seealso marker="ssh_connection#close-2">ssh_connection:close/2</seealso>. + Both the handling of this event and sending it are taken care of by the + <seealso marker="ssh_client_channel">ssh_client_channel</seealso> behavior.</p> + </desc> + </datatype> - <p>Events that include a <c>WantReply</c> expect the event handling - process to call <seealso marker="ssh_connection#reply_request-4"> - ssh_connection:reply_request/4</seealso> - with the boolean value of <c>WantReply</c> as the second argument.</p> - <taglist> - <tag><c><![CDATA[{env, channel_id(), WantReply :: boolean(), - Var ::string(), Value :: string()}]]></c></tag> - <item><p>Environment variables can be passed to the shell/command - to be started later. This event is sent as a result of calling <seealso - marker="ssh_connection#setenv-5"> ssh_connection:setenv/5</seealso>. - </p></item> - - <tag><c><![CDATA[{pty, channel_id(), - WantReply :: boolean(), {Terminal :: string(), CharWidth :: integer(), - RowHeight :: integer(), PixelWidth :: integer(), PixelHeight :: integer(), - TerminalModes :: [{Opcode :: atom() | integer(), - Value :: integer()}]}}]]></c></tag> - <item><p>A pseudo-terminal has been requested for the + <datatype_title>Requesting a Pseudo-Terminal (RFC 4254, section 6.2)</datatype_title> + <datatype> + <name name="pty_ch_msg"/> + <name name="term_mode"/> + <desc> + <p>A pseudo-terminal has been requested for the session. <c>Terminal</c> is the value of the TERM environment variable value, that is, <c>vt100</c>. Zero dimension parameters must be ignored. The character/row dimensions override the pixel @@ -169,46 +160,103 @@ drawable area of the window. <c>Opcode</c> in the <c>TerminalModes</c> list is the mnemonic name, represented as a lowercase Erlang atom, defined in - <url href="http://www.ietf.org/rfc/rfc4254.txt">RFC 4254</url>, Section 8. + <url href="https://tools.ietf.org/html/rfc4254#section-8">RFC 4254</url>, Section 8. It can also be an <c>Opcode</c> if the mnemonic name is not listed in the RFC. Example: <c>OP code: 53, mnemonic name ECHO erlang atom: echo</c>. This event is sent as a result of calling <seealso - marker="ssh_connection#ptty_alloc/4">ssh_connection:ptty_alloc/4</seealso>.</p></item> + marker="ssh_connection#ptty_alloc/4">ssh_connection:ptty_alloc/4</seealso>.</p> + </desc> + </datatype> + - <tag><c><![CDATA[{shell, WantReply :: boolean()}]]></c></tag> - <item><p>This message requests that the user default shell + <datatype_title>Environment Variable Passing (RFC 4254, section 6.4)</datatype_title> + <datatype> + <name name="env_ch_msg"/> + <desc> + <p>Environment variables can be passed to the shell/command + to be started later. This event is sent as a result of calling <seealso + marker="ssh_connection#setenv-5"> ssh_connection:setenv/5</seealso>. + </p> + </desc> + </datatype> + + + <datatype_title>Starting a Shell or Command (RFC 4254, section 6.5)</datatype_title> + <datatype> + <name name="shell_ch_msg"/> + <desc> + <p>This message requests that the user default shell is started at the other end. This event is sent as a result of calling <seealso marker="ssh_connection#shell-2"> ssh_connection:shell/2</seealso>. - </p></item> + </p> + </desc> + </datatype> + <datatype> + <name name="exec_ch_msg"/> + <desc> + <p>This message requests that the server starts + execution of the given command. This event is sent as a result of calling <seealso + marker="ssh_connection#exec-4">ssh_connection:exec/4 </seealso>. + </p> + </desc> + </datatype> + - <tag><c><![CDATA[{window_change, channel_id(), CharWidth() :: integer(), - RowHeight :: integer(), PixWidth :: integer(), PixHeight :: integer()}]]></c></tag> - <item><p>When the window (terminal) size changes on the client + <datatype_title>Window Dimension Change Message (RFC 4254, section 6.7)</datatype_title> + <datatype> + <name name="window_change_ch_msg"/> + <desc> + <p>When the window (terminal) size changes on the client side, it <em>can</em> send a message to the server side to inform it of - the new dimensions. No API function generates this event.</p></item> + the new dimensions. No API function generates this event.</p> + </desc> + </datatype> - <tag><c><![CDATA[{exec, channel_id(), - WantReply :: boolean(), Cmd :: string()}]]></c></tag> - <item><p>This message requests that the server starts - execution of the given command. This event is sent as a result of calling <seealso - marker="ssh_connection#exec-4">ssh_connection:exec/4 </seealso>. - </p></item> - </taglist> - </item> - </taglist> - </section> + <datatype_title>Signals (RFC 4254, section 6.9)</datatype_title> + <datatype> + <name name="signal_ch_msg"/> + <desc> + <p>A signal can be delivered to the remote process/service + using the following message. Some systems do not support + signals, in which case they are to ignore this message. There is + currently no function to generate this event as the signals + referred to are on OS-level and not something generated by an + Erlang program.</p> + </desc> + </datatype> + + + <datatype_title>Returning Exit Status (RFC 4254, section 6.10)</datatype_title> + <datatype> + <name name="exit_status_ch_msg"/> + <desc> + <p>When the command running at the other end terminates, the + following message can be sent to return the exit status of the + command. A zero <c>exit_status</c> usually means that the command + terminated successfully. This event is sent as a result of calling + <seealso marker="ssh_connection#exit_status-3"> + ssh_connection:exit_status/3</seealso>.</p> + </desc> + </datatype> + <datatype> + <name name="exit_signal_ch_msg"/> + <desc> + <p>A remote execution can terminate violently because of a signal. + Then this message can be received. For details on valid string + values, see <url href="https://tools.ietf.org/html/rfc4254#section-6.10">RFC 4254</url> + Section 6.10, which shows a special case of these signals.</p> + </desc> + </datatype> + + </datatypes> + <funcs> <func> - <name since="">adjust_window(ConnectionRef, ChannelId, NumOfBytes) -> ok</name> + <name since="" name="adjust_window" arity="3"/> <fsummary>Adjusts the SSH flow control window.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - <v>NumOfBytes = integer()</v> - </type> - <desc> + <desc> <p>Adjusts the SSH flow control window. This is to be done by both the client- and server-side channel processes.</p> @@ -221,17 +269,12 @@ </func> <func> - <name since="">close(ConnectionRef, ChannelId) -> ok</name> + <name since="" name="close" arity="2"/> <fsummary>Sends a close message on the channel <c>ChannelId</c>.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - </type> <desc> <p>A server- or client-channel process can choose to close their session by sending a close event. </p> - <note><p>This function is called by the <c>ssh_client_channel</c> behavior when the channel is terminated, see <seealso marker="ssh_client_channel"> ssh_client_channel(3)</seealso>. Thus, channels implemented @@ -240,57 +283,61 @@ </func> <func> - <name since="">exec(ConnectionRef, ChannelId, Command, TimeOut) -> ssh_request_status() | - {error, reason()}</name> + <name since="" name="exec" arity="4"/> <fsummary>Requests that the server starts the execution of the given command.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - <v>Command = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Is to be called by a client-channel process to request that the server starts executing the given command. The result is several messages according to the following pattern. The last message is a channel close message, as the <c>exec</c> request is a one-time execution that closes the channel when it is done.</p> - <taglist> - <tag><c>N x {ssh_cm, connection_ref(), - {data, channel_id(), ssh_data_type_code(), Data :: binary()}}</c></tag> + <!--taglist> + <tag><c>N x {ssh_cm, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>, {data, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>, </c><seealso marker="#type-ssh_data_type_code">ssh_data_type_code()</seealso><c>, Data :: binary()}}</c></tag> <item><p>The result of executing the command can be only one line or thousands of lines depending on the command.</p></item> - <tag><c>0 or 1 x {ssh_cm, connection_ref(), {eof, channel_id()}}</c></tag> + <tag><c>0 or 1 x {ssh_cm, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>, {eof, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>}}</c></tag> <item><p>Indicates that no more data is to be sent.</p></item> - <tag><c>0 or 1 x {ssh_cm, - connection_ref(), {exit_signal, - channel_id(), ExitSignal :: string(), ErrorMsg :: string(), LanguageString :: string()}}</c></tag> + <tag><c>0 or 1 x {ssh_cm, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>, {exit_signal, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>, ExitSignal :: string(), ErrorMsg :: string(), LanguageString :: string()}}</c></tag> <item><p>Not all systems send signals. For details on valid string values, see RFC 4254, Section 6.10</p></item> - <tag><c>0 or 1 x {ssh_cm, connection_ref(), {exit_status, - channel_id(), ExitStatus :: integer()}}</c></tag> + <tag><c>0 or 1 x {ssh_cm, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>, {exit_status, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>, ExitStatus :: integer()}}</c></tag> <item><p>It is recommended by the SSH Connection Protocol to send this message, but that is not always the case.</p></item> - <tag><c>1 x {ssh_cm, connection_ref(), - {closed, channel_id()}}</c></tag> + <tag><c>1 x {ssh_cm, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>, {closed, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>}}</c></tag> <item><p>Indicates that the <c>ssh_client_channel</c> started for the execution of the command has now been shut down.</p></item> + </taglist--> + + <taglist> + <tag>N x <seealso marker="#type-data_ch_msg">data message(s)</seealso></tag> + <item><p>The result of executing the command can be only one line + or thousands of lines depending on the command.</p></item> + + <tag>0 or 1 x <seealso marker="#type-eof_ch_msg">eof message</seealso></tag> + <item><p>Indicates that no more data is to be sent.</p></item> + + <tag>0 or 1 x <seealso marker="#type-exit_signal_ch_msg">exit signal message</seealso></tag> + <item><p>Not all systems send signals. For details on valid string + values, see RFC 4254, Section 6.10</p></item> + + <tag>0 or 1 x <seealso marker="#type-exit_status_ch_msg">exit status message</seealso></tag> + <item><p>It is recommended by the SSH Connection Protocol to send this + message, but that is not always the case.</p></item> + + <tag>1 x <seealso marker="#type-closed_ch_msg">closed status message</seealso></tag> + <item><p>Indicates that the <c>ssh_client_channel</c> started for the + execution of the command has now been shut down.</p></item> </taglist> </desc> </func> <func> - <name since="">exit_status(ConnectionRef, ChannelId, Status) -> ok</name> + <name since="" name="exit_status" arity="3"/> <fsummary>Sends the exit status of a command to the client.</fsummary> - <type> - <v>ConnectionRef = connection_ref() </v> - <v>ChannelId = channel_id()</v> - <v>Status = integer()</v> - </type> <desc> <p>Is to be called by a server-channel process to send the exit status of a command to the client.</p> @@ -298,16 +345,10 @@ </func> <func> - <name since="OTP 17.5">ptty_alloc(ConnectionRef, ChannelId, Options) -></name> - <name since="OTP 17.4">ptty_alloc(ConnectionRef, ChannelId, Options, Timeout) -> > ssh_request_status() | - {error, reason()}</name> + <name since="OTP 17.5" name="ptty_alloc" arity="3"/> + <name since="OTP 17.4" name="ptty_alloc" arity="4"/> <fsummary>Sends an SSH Connection Protocol <c>pty_req</c>, to allocate a pseudo-terminal.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - <v>Options = proplists:proplist()</v> - </type> <desc> <p>Sends an SSH Connection Protocol <c>pty_req</c>, to allocate a pseudo-terminal. Is to be called by an SSH client process.</p> @@ -339,14 +380,8 @@ </func> <func> - <name since="">reply_request(ConnectionRef, WantReply, Status, ChannelId) -> ok</name> + <name since="" name="reply_request" arity="4"/> <fsummary>Sends status replies to requests that want such replies.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>WantReply = boolean()</v> - <v>Status = ssh_request_status()</v> - <v>ChannelId = channel_id()</v> - </type> <desc> <p>Sends status replies to requests where the requester has stated that it wants a status report, that is, <c>WantReply = true</c>. @@ -361,14 +396,15 @@ <name since="">send(ConnectionRef, ChannelId, Data, Timeout) -></name> <name since="">send(ConnectionRef, ChannelId, Type, Data) -></name> <name since="">send(ConnectionRef, ChannelId, Type, Data, TimeOut) -> - ok | {error, timeout} | {error, closed}</name> + ok | Error</name> <fsummary>Sends channel data.</fsummary> <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> + <v>ConnectionRef = <seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso></v> + <v>ChannelId = <seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso></v> <v>Data = binary()</v> - <v>Type = ssh_data_type_code()</v> + <v>Type = <seealso marker="#type-ssh_data_type_code">ssh_data_type_code()</seealso></v> <v>Timeout = timeout()</v> + <v>Error = {error, <seealso marker="#type-reason">reason()</seealso>}</v> </type> <desc> <p>Is to be called by client- and server-channel processes to send data to each other. @@ -380,29 +416,17 @@ </func> <func> - <name since="">send_eof(ConnectionRef, ChannelId) -> ok | {error, closed}</name> + <name since="" name="send_eof" arity="2"/> <fsummary>Sends EOF on channel <c>ChannelId</c>.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - </type> <desc> <p>Sends EOF on channel <c>ChannelId</c>.</p> </desc> </func> <func> - <name since="">session_channel(ConnectionRef, Timeout) -></name> - <name since="">session_channel(ConnectionRef, InitialWindowSize, - MaxPacketSize, Timeout) -> {ok, channel_id()} | {error, reason()}</name> + <name since="" name="session_channel" arity="2"/> + <name since="" name="session_channel" arity="4"/> <fsummary>Opens a channel for an SSH session.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>InitialWindowSize = integer()</v> - <v>MaxPacketSize = integer()</v> - <v>Timeout = timeout()</v> - <v>Reason = term()</v> - </type> <desc> <p>Opens a channel for an SSH session. The channel id returned from this function is the id used as input to the other functions in this module.</p> @@ -410,17 +434,9 @@ </func> <func> - <name since="">setenv(ConnectionRef, ChannelId, Var, Value, TimeOut) -> ssh_request_status() | - {error, reason()}</name> + <name since="" name="setenv" arity="5"/> <fsummary>Environment variables can be passed to the shell/command to be started later.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - <v>Var = string()</v> - <v>Value = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Environment variables can be passed before starting the shell/command. Is to be called by a client channel processes.</p> @@ -428,14 +444,9 @@ </func> <func> - <name since="">shell(ConnectionRef, ChannelId) -> ok | failure | {error, closed} - </name> + <name since="" name="shell" arity="2"/> <fsummary>Requests that the user default shell (typically defined in /etc/passwd in Unix systems) is to be executed at the server end.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - </type> <desc> <p>Is to be called by a client channel process to request that the user default shell (typically defined in /etc/passwd in Unix systems) is executed @@ -448,15 +459,8 @@ </func> <func> - <name since="">subsystem(ConnectionRef, ChannelId, Subsystem, Timeout) -> ssh_request_status() | - {error, reason()}</name> + <name since="" name="subsystem" arity="4"/> <fsummary>Requests to execute a predefined subsystem on the server.</fsummary> - <type> - <v>ConnectionRef = connection_ref()</v> - <v>ChannelId = channel_id()</v> - <v>Subsystem = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Is to be called by a client-channel process for requesting to execute a predefined subsystem on the server. diff --git a/lib/ssh/doc/src/ssh_server_channel.xml b/lib/ssh/doc/src/ssh_server_channel.xml index a4e18bbfbf..87c745c9fb 100644 --- a/lib/ssh/doc/src/ssh_server_channel.xml +++ b/lib/ssh/doc/src/ssh_server_channel.xml @@ -112,7 +112,7 @@ function and all channels are to handle the following message.</p> <taglist> - <tag><c>{ssh_channel_up, ssh:channel_id(), ssh:connection_ref()}</c></tag> + <tag><c>{ssh_channel_up, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>, </c><seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso><c>}</c></tag> <item><p>This is the first message that the channel receives. This is especially useful if the server wants to send a message to the client without first @@ -129,21 +129,21 @@ ChannelId, State}</name> <fsummary>Handles <c>ssh</c> connection protocol messages.</fsummary> <type> - <v>Msg = ssh_connection:event()</v> + <v>Msg = <seealso marker="ssh_connection#type-event">ssh_connection:event()</seealso></v> <v>ChannelId = <seealso marker="ssh#type-channel_id">ssh:channel_id()</seealso></v> <v>State = term()</v> </type> <desc> <p>Handles SSH Connection Protocol messages that may need service-specific attention. For details, - see <seealso marker="ssh_connection"> ssh_connection:event()</seealso>. + see <seealso marker="ssh_connection#type-event">ssh_connection:event()</seealso>. </p> <p>The following message is taken care of by the <c>ssh_server_channel</c> behavior.</p> <taglist> - <tag><c>{closed, ssh:channel_id()}</c></tag> + <tag><c>{closed, </c><seealso marker="ssh:ssh#type-channel_id">ssh:channel_id()</seealso><c>}</c></tag> <item><p>The channel behavior sends a close message to the other side, if such a message has not already been sent. Then it terminates the channel with reason <c>normal</c>.</p></item> diff --git a/lib/ssh/doc/src/ssh_sftp.xml b/lib/ssh/doc/src/ssh_sftp.xml index c89092798d..f9f1e0953b 100644 --- a/lib/ssh/doc/src/ssh_sftp.xml +++ b/lib/ssh/doc/src/ssh_sftp.xml @@ -37,60 +37,112 @@ SSH.</p> </description> - <section> - <title>DATA TYPES</title> - <p>Type definitions that are used more than once in this module, - or abstractions to indicate the intended use of the data type, or both: - </p> - - <taglist> - <tag><c>reason()</c></tag> - <item> - <p>= <c>atom() | string() | tuple() </c>A description of the reason why an operation failed.</p> - <p> - The <c>atom()</c> value is formed from the sftp error codes in the protocol-level responses as defined in - <url href="https://tools.ietf.org/id/draft-ietf-secsh-filexfer-13.txt">draft-ietf-secsh-filexfer-13.txt</url> - section 9.1. - </p> - <p> + <datatypes> + <datatype> + <name name="sftp_option"/> + <desc> + </desc> + </datatype> + + <datatype_title>Error cause</datatype_title> + <datatype> + <name name="reason"/> + <desc> + <p>A description of the reason why an operation failed.</p> + <p>The <c>atom()</c> value is formed from the sftp error codes in the protocol-level responses as defined in + <url href="https://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#page-49">draft-ietf-secsh-filexfer-13</url> + section 9.1. The codes are named as <c>SSH_FX_*</c> which are transformed into lowercase of the star-part. E.g. the error code <c>SSH_FX_NO_SUCH_FILE</c> will cause the <c>reason()</c> to be <c>no_such_file</c>. </p> <p>The <c>string()</c> reason is the error information from the server in case of an exit-signal. If that information is empty, the reason is the exit signal name. </p> - <p>The <c>tuple()</c> reason are other errors like the <c>{exit_status,integer()}</c> if the exit status is not 0. + <p>The <c>tuple()</c> reason are other errors like for example <c>{exit_status,1}</c>. </p> - </item> + </desc> + </datatype> - <tag><c>connection_ref() =</c></tag> - <item><p><c>opaque()</c> - as returned by - <seealso marker="ssh#connect-3"><c>ssh:connect/3</c></seealso></p></item> + <datatype_title>Crypto operations for open_tar</datatype_title> + <datatype> + <name name="tar_crypto_spec"/> + <name name="encrypt_spec"/> + <name name="decrypt_spec"/> + <desc> + <p>Specifies the encryption or decryption applied to tar files when using + <seealso marker="#open_tar/3">open_tar/3</seealso> or + <seealso marker="#open_tar/4">open_tar/4</seealso>. + </p> + <p>The encryption or decryption is applied to the generated stream of + bytes prior to sending the resulting stream to the SFTP server. + </p> + <p>For code examples see Section + <seealso marker="using_ssh#example-with-encryption">Example with encryption</seealso> + in the ssh Users Guide. + </p> + </desc> + </datatype> - <tag><c>timeout()</c></tag> - <item><p>= <c>infinity | integer()</c> in milliseconds. Default infinity.</p></item> - </taglist> - </section> + <datatype> + <name name="init_fun"/> + <name name="chunk_size"/> + <name name="crypto_state"/> + <desc> + <p>The <c>init_fun()</c> in the + <seealso marker="#type-tar_crypto_spec">tar_crypto_spec</seealso> + is applied once prior to any other <c>crypto</c> + operation. The intention is that this function initiates the encryption or + decryption for example by calling + <seealso marker="crypto:crypto#crypto_init/4">crypto:crypto_init/4</seealso> + or similar. The <c>crypto_state()</c> is the state such a function may return. + </p> + <p>If the selected cipher needs to have the input data partioned into + blocks of a certain size, the <c>init_fun()</c> should return the second + form of return value with the <c>chunk_size()</c> set to the block size. + If the <c>chunk_size()</c> is <c>undefined</c>, the size of the <c>PlainBin</c>s varies, + because this is intended for stream crypto, whereas a fixed <c>chunk_size()</c> is intended for block crypto. + A <c>chunk_size()</c> can be changed in the return from the <c>crypto_fun()</c>. + The value can be changed between <c>pos_integer()</c> and <c>undefined</c>. + </p> + </desc> + </datatype> - <section> - <title>Time-outs</title> - <p>If the request functions for the SFTP channel return <c>{error, timeout}</c>, - no answer was received from the server within the expected time.</p> - <p>The request may have reached the server and may have been performed. - However, no answer was received from the server within the expected time.</p> - </section> + <datatype> + <name name="crypto_fun"/> + <name name="crypto_result"/> + <desc> + <p>The initial <c>crypto_state()</c> returned from the + <seealso marker="#type-init_fun">init_fun()</seealso> + is folded into repeated applications of the <c>crypto_fun()</c> in the + <seealso marker="#type-tar_crypto_spec">tar_crypto_spec</seealso>. + The binary returned from that fun is sent to the remote SFTP server and + the new <c>crypto_state()</c> is used in the next call of the + <c>crypto_fun()</c>. + </p> + <p>If the <c>crypto_fun()</c> reurns a <c>chunk_size()</c>, that value + is as block size for further blocks in calls to <c>crypto_fun()</c>. + </p> + </desc> + </datatype> + + <datatype> + <name name="final_fun"/> + <desc> + <p>If doing encryption, + the <c>final_fun()</c> in the + <seealso marker="#type-tar_crypto_spec">tar_crypto_spec</seealso> + is applied to the last piece of data. + The <c>final_fun()</c> is responsible for padding (if needed) and + encryption of that last piece. + </p> + </desc> + </datatype> + </datatypes> <funcs> <func> - <name since="">apread(ChannelPid, Handle, Position, Len) -> {async, N} | {error, reason()}</name> + <name name="apread" arity="4" since=""/> <fsummary>Reads asynchronously from an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Position = integer()</v> - <v>Len = integer()</v> - <v>N = term()</v> - </type> <desc><p>The <c><![CDATA[apread/4]]></c> function reads from a specified position, combining the <seealso marker="#position-3"><c>position/3</c></seealso> and <seealso marker="#aread-3"><c>aread/3</c></seealso> functions.</p> @@ -98,17 +150,8 @@ </func> <func> - <name since="">apwrite(ChannelPid, Handle, Position, Data) -> {async, N} | {error, reason()}</name> + <name name="apwrite" arity="4" since=""/> <fsummary>Writes asynchronously to an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Position = integer()</v> - <v>Len = integer()</v> - <v>Data = binary()</v> - <v>Timeout = timeout()</v> - <v>N = term()</v> - </type> <desc><p>The <c><![CDATA[apwrite/4]]></c> function writes to a specified position, combining the <seealso marker="#position-3"><c>position/3</c></seealso> and <seealso marker="#awrite-3"><c>awrite/3</c></seealso> functions.</p> @@ -116,15 +159,8 @@ </func> <func> - <name since="">aread(ChannelPid, Handle, Len) -> {async, N} | {error, reason()}</name> + <name name="aread" arity="3" since=""/> <fsummary>Reads asynchronously from an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Position = integer()</v> - <v>Len = integer()</v> - <v>N = term()</v> - </type> <desc> <p>Reads from an open file, without waiting for the result. If the handle is valid, the function returns <c><![CDATA[{async, N}]]></c>, where <c>N</c> @@ -137,16 +173,8 @@ </func> <func> - <name since="">awrite(ChannelPid, Handle, Data) -> {async, N} | {error, reason()}</name> + <name name="awrite" arity="3" since=""/> <fsummary>Writes asynchronously to an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Position = integer()</v> - <v>Len = integer()</v> - <v>Data = binary()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Writes to an open file, without waiting for the result. If the handle is valid, the function returns <c><![CDATA[{async, N}]]></c>, where <c>N</c> @@ -159,28 +187,18 @@ </func> <func> - <name since="">close(ChannelPid, Handle) -></name> - <name since="">close(ChannelPid, Handle, Timeout) -> ok | {error, reason()}</name> + <name name="close" arity="2" since=""/> + <name name="close" arity="3" since=""/> <fsummary>Closes an open handle.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Closes a handle to an open file or directory on the server.</p> </desc> </func> <func> - <name since="">delete(ChannelPid, Name) -></name> - <name since="">delete(ChannelPid, Name, Timeout) -> ok | {error, reason()}</name> + <name name="delete" arity="2" since=""/> + <name name="delete" arity="3" since=""/> <fsummary>Deletes a file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Deletes the file specified by <c><![CDATA[Name]]></c>. </p> @@ -188,14 +206,9 @@ </func> <func> - <name since="">del_dir(ChannelPid, Name) -></name> - <name since="">del_dir(ChannelPid, Name, Timeout) -> ok | {error, reason()}</name> + <name name="del_dir" arity="2" since=""/> + <name name="del_dir" arity="3" since=""/> <fsummary>Deletes an empty directory.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Deletes a directory specified by <c><![CDATA[Name]]></c>. The directory must be empty before it can be successfully deleted. @@ -204,16 +217,9 @@ </func> <func> - <name since="">list_dir(ChannelPid, Path) -></name> - <name since="">list_dir(ChannelPid, Path, Timeout) -> {ok, Filenames} | {error, reason()}</name> + <name name="list_dir" arity="2" since=""/> + <name name="list_dir" arity="3" since=""/> <fsummary>Lists the directory.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Path = string()</v> - <v>Filenames = [Filename]</v> - <v>Filename = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Lists the given directory on the server, returning the filenames as a list of strings.</p> @@ -221,14 +227,9 @@ </func> <func> - <name since="">make_dir(ChannelPid, Name) -></name> - <name since="">make_dir(ChannelPid, Name, Timeout) -> ok | {error, reason()}</name> + <name name="make_dir" arity="2" since=""/> + <name name="make_dir" arity="3" since=""/> <fsummary>Creates a directory.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Creates a directory specified by <c><![CDATA[Name]]></c>. <c><![CDATA[Name]]></c> must be a full path to a new directory. The directory can only be @@ -237,14 +238,9 @@ </func> <func> - <name since="">make_symlink(ChannelPid, Name, Target) -></name> - <name since="">make_symlink(ChannelPid, Name, Target, Timeout) -> ok | {error, reason()}</name> + <name name="make_symlink" arity="3" since=""/> + <name name="make_symlink" arity="4" since=""/> <fsummary>Creates a symbolic link.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Target = string()</v> - </type> <desc> <p>Creates a symbolic link pointing to <c><![CDATA[Target]]></c> with the name <c><![CDATA[Name]]></c>. @@ -252,32 +248,19 @@ </desc> </func> - <func> - <name since="">open(ChannelPid, File, Mode) -></name> - <name since="">open(ChannelPid, File, Mode, Timeout) -> {ok, Handle} | {error, reason()}</name> + <func> + <name name="open" arity="3" since=""/> + <name name="open" arity="4" since=""/> <fsummary>Opens a file and returns a handle.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>File = string()</v> - <v>Mode = [Modeflag]</v> - <v>Modeflag = read | write | creat | trunc | append | binary</v> - <v>Timeout = timeout()</v> - <v>Handle = term()</v> - </type> <desc> <p>Opens a file on the server and returns a handle, which can be used for reading or writing.</p> </desc> </func> <func> - <name since="">opendir(ChannelPid, Path) -></name> - <name since="">opendir(ChannelPid, Path, Timeout) -> {ok, Handle} | {error, reason()}</name> + <name name="opendir" arity="2" since=""/> + <name name="opendir" arity="3" since=""/> <fsummary>Opens a directory and returns a handle.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Path = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Opens a handle to a directory on the server. The handle can be used for reading directory contents.</p> @@ -285,72 +268,36 @@ </func> <func> - <name since="OTP 17.4">open_tar(ChannelPid, Path, Mode) -></name> - <name since="OTP 17.4">open_tar(ChannelPid, Path, Mode, Timeout) -> {ok, Handle} | {error, reason()}</name> + <name name="open_tar" arity="3" since="OTP 17.4"/> + <name name="open_tar" arity="4" since="OTP 17.4"/> <fsummary>Opens a tar file on the server to which <c>ChannelPid</c> is connected and returns a handle.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Path = string()</v> - <v>Mode = [read] | [write] | [read,EncryptOpt] | [write,DecryptOpt]</v> - <v>EncryptOpt = {crypto,{InitFun,EncryptFun,CloseFun}}</v> - <v>DecryptOpt = {crypto,{InitFun,DecryptFun}}</v> - <v>InitFun = (fun() -> {ok,CryptoState}) | (fun() -> {ok,CryptoState,ChunkSize})</v> - <v>CryptoState = any()</v> - <v>ChunkSize = undefined | pos_integer()</v> - <v>EncryptFun = (fun(PlainBin,CryptoState) -> EncryptResult)</v> - <v>EncryptResult = {ok,EncryptedBin,CryptoState} | {ok,EncryptedBin,CryptoState,ChunkSize}</v> - <v>PlainBin = binary()</v> - <v>EncryptedBin = binary()</v> - <v>DecryptFun = (fun(EncryptedBin,CryptoState) -> DecryptResult)</v> - <v>DecryptResult = {ok,PlainBin,CryptoState} | {ok,PlainBin,CryptoState,ChunkSize}</v> - <v>CloseFun = (fun(PlainBin,CryptoState) -> {ok,EncryptedBin})</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Opens a handle to a tar file on the server, associated with <c>ChannelPid</c>. - The handle can be used for remote tar creation and extraction, as defined by the - <seealso marker="stdlib:erl_tar#init-3">erl_tar:init/3</seealso> function. - </p> - - <p> For code exampel see Section - <seealso marker="using_ssh">SFTP Client with TAR Compression and Encryption</seealso> in - the ssh Users Guide. </p> - - <p>The <c>crypto</c> mode option is applied to the generated stream of bytes prior to sending - them to the SFTP server. This is intended for encryption but can be used for other - purposes. + The handle can be used for remote tar creation and extraction. The actual writing + and reading is performed by calls to + <seealso marker="stdlib:erl_tar#add-3">erl_tar:add/3,4</seealso> and + <seealso marker="stdlib:erl_tar#extract-2">erl_tar:extract/2</seealso>. + Note: The + <seealso marker="stdlib:erl_tar#init-3">erl_tar:init/3</seealso> function should not + be called, that one is called by this open_tar function. </p> - <p>The <c>InitFun</c> is applied once - prior to any other <c>crypto</c> operation. The returned <c>CryptoState</c> is then folded into - repeated applications of the <c>EncryptFun</c> or <c>DecryptFun</c>. The binary returned - from those funs are sent further to the remote SFTP server. Finally, if doing encryption, - the <c>CloseFun</c> is applied to the last piece of data. The <c>CloseFun</c> is - responsible for padding (if needed) and encryption of that last piece. + <p>For code examples see Section + <seealso marker="using_ssh#sftp-client-with-tar-compression">SFTP Client with TAR Compression</seealso> + in the ssh Users Guide. </p> - <p>The <c>ChunkSize</c> defines the size of the <c>PlainBin</c>s that <c>EncodeFun</c> is applied - to. If the <c>ChunkSize</c> is <c>undefined</c>, the size of the <c>PlainBin</c>s varies, - because this is intended for stream crypto, whereas a fixed <c>ChunkSize</c> is intended for block crypto. - <c>ChunkSize</c>s can be changed in the return from the <c>EncryptFun</c> or - <c>DecryptFun</c>. The value can be changed between <c>pos_integer()</c> and <c>undefined</c>. + <p>The <c>crypto</c> mode option is explained in the data types section above, see + <seealso marker="#Crypto operations for open_tar">Crypto operations for open_tar</seealso>. + Encryption is assumed if the <c>Mode</c> contains <c>write</c>, and + decryption if the <c>Mode</c> contains <c>read</c>. </p> - </desc> </func> <func> - <name since="">position(ChannelPid, Handle, Location) -></name> - <name since="">position(ChannelPid, Handle, Location, Timeout) -> {ok, NewPosition | {error, reason()}</name> + <name name="position" arity="3" since=""/> + <name name="position" arity="4" since=""/> <fsummary>Sets the file position of a file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Location = Offset - | {bof, Offset} | {cur, Offset} | {eof, Offset} | bof | cur | eof</v> - <v>Offset = integer()</v> - <v>Timeout = timeout()</v> - <v>NewPosition = integer()</v> - </type> <desc> <p>Sets the file position of the file referenced by <c><![CDATA[Handle]]></c>. Returns <c><![CDATA[{ok, NewPosition}]]></c> (as an absolute offset) if @@ -384,17 +331,9 @@ </func> <func> - <name since="">pread(ChannelPid, Handle, Position, Len) -></name> - <name since="">pread(ChannelPid, Handle, Position, Len, Timeout) -> {ok, Data} | eof | {error, reason()}</name> + <name name="pread" arity="4" since=""/> + <name name="pread" arity="5" since=""/> <fsummary>Reads from an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Position = integer()</v> - <v>Len = integer()</v> - <v>Timeout = timeout()</v> - <v>Data = string() | binary()</v> - </type> <desc><p>The <c><![CDATA[pread/3,4]]></c> function reads from a specified position, combining the <seealso marker="#position-3"><c>position/3</c></seealso> and <seealso marker="#read-3"><c>read/3,4</c></seealso> functions.</p> @@ -402,16 +341,9 @@ </func> <func> - <name since="">pwrite(ChannelPid, Handle, Position, Data) -> ok</name> - <name since="">pwrite(ChannelPid, Handle, Position, Data, Timeout) -> ok | {error, reason()}</name> + <name name="pwrite" arity="4" since=""/> + <name name="pwrite" arity="5" since=""/> <fsummary>Writes to an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Position = integer()</v> - <v>Data = iolist()</v> - <v>Timeout = timeout()</v> - </type> <desc><p>The <c><![CDATA[pwrite/3,4]]></c> function writes to a specified position, combining the <seealso marker="#position-3"><c>position/3</c></seealso> and <seealso marker="#write-3"><c>write/3,4</c></seealso> functions.</p> @@ -419,16 +351,9 @@ </func> <func> - <name since="">read(ChannelPid, Handle, Len) -></name> - <name since="">read(ChannelPid, Handle, Len, Timeout) -> {ok, Data} | eof | {error, reason()}</name> + <name name="read" arity="3" since=""/> + <name name="read" arity="4" since=""/> <fsummary>Reads from an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Len = integer()</v> - <v>Timeout = timeout()</v> - <v>Data = string() | binary()</v> - </type> <desc> <p>Reads <c><![CDATA[Len]]></c> bytes from the file referenced by <c><![CDATA[Handle]]></c>. Returns <c><![CDATA[{ok, Data}]]></c>, <c><![CDATA[eof]]></c>, or @@ -440,32 +365,19 @@ </desc> </func> - <func> - <name since="">read_file(ChannelPid, File) -></name> - <name since="">read_file(ChannelPid, File, Timeout) -> {ok, Data} | {error, reason()}</name> + <func> + <name name="read_file" arity="2" since=""/> + <name name="read_file" arity="3" since=""/> <fsummary>Reads a file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>File = string()</v> - <v>Data = binary()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Reads a file from the server, and returns the data in a binary.</p> </desc> </func> - <func> - <name since="">read_file_info(ChannelPid, Name) -></name> - <name since="">read_file_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | {error, reason()}</name> + <func> + <name name="read_file_info" arity="2" since=""/> + <name name="read_file_info" arity="3" since=""/> <fsummary>Gets information about a file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Handle = term()</v> - <v>Timeout = timeout()</v> - <v>FileInfo = record()</v> - </type> <desc> <p>Returns a <c><![CDATA[file_info]]></c> record from the file system object specified by <c><![CDATA[Name]]></c> or <c><![CDATA[Handle]]></c>. See @@ -474,38 +386,26 @@ </p> <p> Depending on the underlying OS:es links might be followed and info on the final file, directory - etc is returned. See <seealso marker="#read_link_info-2">ssh_sftp::read_link_info/2</seealso> + etc is returned. See <seealso marker="#read_link_info-2">read_link_info/2</seealso> on how to get information on links instead. </p> </desc> </func> <func> - <name since="">read_link(ChannelPid, Name) -></name> - <name since="">read_link(ChannelPid, Name, Timeout) -> {ok, Target} | {error, reason()}</name> + <name name="read_link" arity="2" since=""/> + <name name="read_link" arity="3" since=""/> <fsummary>Reads symbolic link.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Target = string()</v> - </type> <desc> <p>Reads the link target from the symbolic link specified by <c><![CDATA[name]]></c>. </p> </desc> </func> - <func> - <name since="">read_link_info(ChannelPid, Name) -> {ok, FileInfo} | {error, reason()}</name> - <name since="">read_link_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | {error, reason()}</name> + <func> + <name since="" name="read_link_info" arity="2"/> + <name since="" name="read_link_info" arity="3"/> <fsummary>Gets information about a symbolic link.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Handle = term()</v> - <v>Timeout = timeout()</v> - <v>FileInfo = record()</v> - </type> <desc> <p>Returns a <c><![CDATA[file_info]]></c> record from the symbolic link specified by <c><![CDATA[Name]]></c> or <c><![CDATA[Handle]]></c>. @@ -517,15 +417,9 @@ </func> <func> - <name since="">rename(ChannelPid, OldName, NewName) -> </name> - <name since="">rename(ChannelPid, OldName, NewName, Timeout) -> ok | {error, reason()}</name> + <name since="" name="rename" arity="3"/> + <name since="" name="rename" arity="4"/> <fsummary>Renames a file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>OldName = string()</v> - <v>NewName = string()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Renames a file named <c><![CDATA[OldName]]></c> and gives it the name <c><![CDATA[NewName]]></c>. @@ -535,25 +429,27 @@ <func> <name since="">start_channel(ConnectionRef) -></name> - <name since="">start_channel(ConnectionRef, Options) -> - {ok, Pid} | {error, reason()|term()}</name> + <name since="">start_channel(ConnectionRef, SftpOptions) -> + {ok, ChannelPid} | Error</name> + <name since="">start_channel(Host) -></name> <name since="">start_channel(Host, Options) -></name> - <name since="">start_channel(Host, Port, Options) -> - {ok, Pid, ConnectionRef} | {error, reason()|term()}</name> - + <name since="">start_channel(Host, Port, Options) -></name> <name since="">start_channel(TcpSocket) -></name> <name since="">start_channel(TcpSocket, Options) -> - {ok, Pid, ConnectionRef} | {error, reason()|term()}</name> + {ok, ChannelPid, ConnectionRef} | Error</name> <fsummary>Starts an SFTP client.</fsummary> <type> - <v>Host = string()</v> - <v>ConnectionRef = connection_ref()</v> - <v>Port = integer()</v> - <v>TcpSocket = port()</v> - <d>The socket is supposed to be from <seealso marker="kernel:gen_tcp#connect-3">gen_tcp:connect</seealso> or <seealso marker="kernel:gen_tcp#accept-1">gen_tcp:accept</seealso> with option <c>{active,false}</c></d> - <v>Options = [{Option, Value}]</v> + <v>Host = <seealso marker="ssh:ssh#type-host">ssh:host()</seealso></v> + <v>Port = <seealso marker="kernel:inet#type-port_number">inet:port_number()</seealso></v> + <v>TcpSocket = <seealso marker="ssh:ssh#type-open_socket">ssh:open_socket()</seealso></v> + <v>Options = [ <seealso marker="#type-sftp_option">sftp_option()</seealso> + | <seealso marker="ssh:ssh#type-client_option">ssh:client_option()</seealso> ]</v> + <v>SftpOptions = [ <seealso marker="#type-sftp_option">sftp_option()</seealso> ]</v> + <v>ChannelPid = pid()</v> + <v>ConnectionRef = <seealso marker="ssh:ssh#type-connection_ref">ssh:connection_ref()</seealso></v> + <v>Error = {error, <seealso marker="#type-reason">reason()</seealso>}</v> </type> <desc> <p>If no connection reference is provided, a connection is set @@ -594,11 +490,8 @@ </func> <func> - <name since="">stop_channel(ChannelPid) -> ok</name> + <name since="" name="stop_channel" arity="1"/> <fsummary>Stops the SFTP client channel.</fsummary> - <type> - <v>ChannelPid = pid()</v> - </type> <desc> <p>Stops an SFTP channel. Does not close the SSH connection. Use <seealso marker="ssh#close-1">ssh:close/1</seealso> to close it.</p> @@ -606,16 +499,9 @@ </func> <func> - <name since="">write(ChannelPid, Handle, Data) -></name> - <name since="">write(ChannelPid, Handle, Data, Timeout) -> ok | {error, reason()}</name> + <name since="" name="write" arity="3"/> + <name since="" name="write" arity="4"/> <fsummary>Writes to an open file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Handle = term()</v> - <v>Position = integer()</v> - <v>Data = iolist()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Writes <c><![CDATA[data]]></c> to the file referenced by <c><![CDATA[Handle]]></c>. The file is to be opened with <c><![CDATA[write]]></c> or <c><![CDATA[append]]></c> @@ -625,15 +511,9 @@ </func> <func> - <name since="">write_file(ChannelPid, File, Iolist) -></name> - <name since="">write_file(ChannelPid, File, Iolist, Timeout) -> ok | {error, reason()}</name> + <name since="" name="write_file" arity="3"/> + <name since="" name="write_file" arity="4"/> <fsummary>Writes a file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>File = string()</v> - <v>Iolist = iolist()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Writes a file to the server. The file is created if it does not exist but overwritten if it exists.</p> @@ -641,15 +521,9 @@ </func> <func> - <name since="">write_file_info(ChannelPid, Name, Info) -></name> - <name since="">write_file_info(ChannelPid, Name, Info, Timeout) -> ok | {error, reason()}</name> + <name since="" name="write_file_info" arity="3"/> + <name since="" name="write_file_info" arity="4"/> <fsummary>Writes information for a file.</fsummary> - <type> - <v>ChannelPid = pid()</v> - <v>Name = string()</v> - <v>Info = record()</v> - <v>Timeout = timeout()</v> - </type> <desc> <p>Writes file information from a <c><![CDATA[file_info]]></c> record to the file specified by <c><![CDATA[Name]]></c>. See diff --git a/lib/ssh/doc/src/ssh_sftpd.xml b/lib/ssh/doc/src/ssh_sftpd.xml index ee72784add..0d7b340399 100644 --- a/lib/ssh/doc/src/ssh_sftpd.xml +++ b/lib/ssh/doc/src/ssh_sftpd.xml @@ -35,36 +35,23 @@ <p>Specifies a channel process to handle an SFTP subsystem.</p> </description> - <section> - <title>DATA TYPES</title> - <taglist> - <tag><c>subsystem_spec() =</c></tag> - <item><p><c>{subsystem_name(), {channel_callback(), channel_init_args()}}</c></p></item> - <tag><c>subsystem_name() =</c></tag> - <item><p><c>"sftp"</c></p></item> - <tag><c>channel_callback() =</c></tag> - <item><p><c>atom()</c> - Name of the Erlang module implementing the subsystem using the - <seealso marker="ssh_server_channel">ssh_server_channel</seealso> (replaces ssh_daemon_channel) behaviour.</p></item> - <tag><c>channel_init_args() =</c></tag> - <item><p><c>list()</c> - The one given as argument to function <c>subsystem_spec/1</c>.</p></item> - </taglist> - </section> <funcs> <func> - <name since="">subsystem_spec(Options) -> subsystem_spec()</name> + <name name="subsystem_spec" arity="1" since=""/> <fsummary>Returns the subsystem specification that allows an SSH daemon to handle the subsystem "sftp".</fsummary> - <type> - <v>Options = [{Option, Value}]</v> - </type> <desc> <p>Is to be used together with <c>ssh:daemon/[1,2,3]</c></p> + <p>The <c>Name</c> is <c>"sftp"</c> and + <c>CbMod</c> is the name of the Erlang module implementing the subsystem using the + <seealso marker="ssh_server_channel">ssh_server_channel</seealso> (replaces ssh_daemon_channel) behaviour. + </p> <p>Options:</p> <taglist> - <tag><c><![CDATA[{cwd, String}]]></c></tag> + <tag><c>cwd</c></tag> <item> <p>Sets the initial current working directory for the server.</p> </item> - <tag><c><![CDATA[{file_handler, CallbackModule}]]></c></tag> + <tag><c>file_handler</c></tag> <item> <p>Determines which module to call for accessing the file server. The default value is <c>ssh_sftpd_file</c>, which uses the @@ -72,13 +59,13 @@ APIs to access the standard OTP file server. This option can be used to plug in other file servers.</p> </item> - <tag><c><![CDATA[{max_files, Integer}]]></c></tag> + <tag><c>max_files</c></tag> <item> <p>The default value is <c>0</c>, which means that there is no upper limit. If supplied, the number of filenames returned to the SFTP client per <c>READDIR</c> request is limited to at most the given value.</p> </item> - <tag><c><![CDATA[{root, String}]]></c></tag> + <tag><c>root</c></tag> <item> <p>Sets the SFTP root directory. Then the user cannot see any files above this root. If, for example, the root directory is set to <c>/tmp</c>, @@ -86,7 +73,7 @@ <c>cd /etc</c>, the user moves to <c>/tmp/etc</c>. </p> </item> - <tag><c><![CDATA[{sftpd_vsn, integer()}]]></c></tag> + <tag><c>sftpd_vsn</c></tag> <item> <p>Sets the SFTP version to use. Defaults to 5. Version 6 is under development and limited.</p> diff --git a/lib/ssh/doc/src/using_ssh.xml b/lib/ssh/doc/src/using_ssh.xml index 4455d5ecc5..5c56dee81d 100644 --- a/lib/ssh/doc/src/using_ssh.xml +++ b/lib/ssh/doc/src/using_ssh.xml @@ -232,9 +232,10 @@ </section> <section> - <title>SFTP Client with TAR Compression and Encryption</title> - - <p>Example of writing and then reading a tar file follows:</p> + <title>SFTP Client with TAR Compression</title> + <section> + <title>Basic example</title> + <p>This is an example of writing and then reading a tar file:</p> <code type="erl"> {ok,HandleWrite} = ssh_sftp:open_tar(ChannelPid, ?tar_file_name, [write]), ok = erl_tar:add(HandleWrite, .... ), @@ -248,8 +249,12 @@ {ok,NameValueList} = erl_tar:extract(HandleRead,[memory]), ok = erl_tar:close(HandleRead), </code> + </section> - <p>The previous write and read example can be extended with encryption and decryption as follows:</p> + <section> + <title>Example with encryption</title> + <p>The previous <seealso marker="using_ssh#basic-example">Basic example</seealso> + can be extended with encryption and decryption as follows:</p> <code type="erl"> %% First three parameters depending on which crypto type we select: Key = <<"This is a 256 bit key. abcdefghi">>, @@ -297,6 +302,7 @@ Cr = {InitFun,DecryptFun}, ok = erl_tar:close(HandleRead), </code> </section> + </section> <section> <marker id="usersguide_creating_a_subsystem"/> diff --git a/lib/ssh/src/ssh.erl b/lib/ssh/src/ssh.erl index ff5aee14d7..32f10c797d 100644 --- a/lib/ssh/src/ssh.erl +++ b/lib/ssh/src/ssh.erl @@ -66,6 +66,8 @@ cipher_alg/0, mac_alg/0, compression_alg/0, + host/0, + open_socket/0, ip_port/0 ]). diff --git a/lib/ssh/src/ssh_client_channel.erl b/lib/ssh/src/ssh_client_channel.erl index f985d8e273..3bd1e1fdf1 100644 --- a/lib/ssh/src/ssh_client_channel.erl +++ b/lib/ssh/src/ssh_client_channel.erl @@ -52,7 +52,7 @@ -callback handle_msg(Msg ::term(), State :: term()) -> {ok, State::term()} | {stop, ChannelId::ssh:channel_id(), State::term()}. --callback handle_ssh_msg({ssh_cm, ConnectionRef::ssh:connection_ref(), SshMsg::term()}, +-callback handle_ssh_msg(ssh_connection:event(), State::term()) -> {ok, State::term()} | {stop, ChannelId::ssh:channel_id(), State::term()}. diff --git a/lib/ssh/src/ssh_connect.hrl b/lib/ssh/src/ssh_connect.hrl index 9a060b8304..d6b50613f9 100644 --- a/lib/ssh/src/ssh_connect.hrl +++ b/lib/ssh/src/ssh_connect.hrl @@ -263,11 +263,8 @@ -record(connection, { requests = [], %% [{ChannelId, Pid}...] awaiting reply on request, channel_cache, - port_bindings, channel_id_seed, cli_spec, - address, - port, options, exec, system_supervisor, diff --git a/lib/ssh/src/ssh_connection.erl b/lib/ssh/src/ssh_connection.erl index 83f85b1d8e..c5316bf133 100644 --- a/lib/ssh/src/ssh_connection.erl +++ b/lib/ssh/src/ssh_connection.erl @@ -60,13 +60,121 @@ request_failure_msg/0, request_success_msg/1, - bind/4, unbind/3, unbind_channel/2, - bound_channel/3, encode_ip/1 + encode_ip/1 ]). -type connection_ref() :: ssh:connection_ref(). -type channel_id() :: ssh:channel_id(). +-type req_status() :: success | failure . +-type reason() :: closed | timeout . + +-type result() :: req_status() | {error, reason()} . + +-type ssh_data_type_code() :: non_neg_integer(). % Only 0 and 1 are used + + +%%% The SSH Connection Protocol + +-export_type([event/0, + channel_msg/0, + want_reply/0, + data_ch_msg/0, + eof_ch_msg/0, + signal_ch_msg/0, + exit_signal_ch_msg/0, + exit_status_ch_msg/0, + closed_ch_msg/0, + env_ch_msg/0, + pty_ch_msg/0, + shell_ch_msg/0, + window_change_ch_msg/0, + exec_ch_msg/0 + ]). + +-type event() :: {ssh_cm, ssh:connection_ref(), channel_msg()}. +-type channel_msg() :: data_ch_msg() + | eof_ch_msg() + | closed_ch_msg() + | pty_ch_msg() + | env_ch_msg() + | shell_ch_msg() + | exec_ch_msg() + | signal_ch_msg() + | window_change_ch_msg() + | exit_status_ch_msg() + | exit_signal_ch_msg() + . + +-type want_reply() :: boolean(). + +-type data_ch_msg() :: {data, + ssh:channel_id(), + ssh_data_type_code(), + Data :: binary() + } . +-type eof_ch_msg() :: {eof, + ssh:channel_id() + } . +-type signal_ch_msg() :: {signal, + ssh:channel_id(), + SignalName :: string() + } . +-type exit_signal_ch_msg() :: {exit_signal, ssh:channel_id(), + ExitSignal :: string(), + ErrorMsg :: string(), + LanguageString :: string()} . +-type exit_status_ch_msg() :: {exit_status, + ssh:channel_id(), + ExitStatus :: non_neg_integer() + } . +-type closed_ch_msg() :: {closed, + ssh:channel_id() + } . +-type env_ch_msg() :: {env, + ssh:channel_id(), + want_reply(), + Var :: string(), + Value :: string() + } . +-type pty_ch_msg() :: {pty, + ssh:channel_id(), + want_reply(), + {Terminal :: string(), + CharWidth :: non_neg_integer(), + RowHeight :: non_neg_integer(), + PixelWidth :: non_neg_integer(), + PixelHeight :: non_neg_integer(), + TerminalModes :: [term_mode()] + } + } . + +-type term_mode() :: {Opcode :: atom() | byte(), + Value :: non_neg_integer()} . + +-type shell_ch_msg() :: {shell, + ssh:channel_id(), + want_reply() + } . +-type window_change_ch_msg() :: {window_change, + ssh:channel_id(), + CharWidth :: non_neg_integer(), + RowHeight :: non_neg_integer(), + PixelWidth :: non_neg_integer(), + PixelHeight :: non_neg_integer() + } . +-type exec_ch_msg() :: {exec, + ssh:channel_id(), + want_reply(), + Command :: string() + } . + +%%% This function is soley to convince all +%%% checks that the type event() exists... +-export([dummy/1]). +-spec dummy(event()) -> false. +dummy(_) -> false. + %%-------------------------------------------------------------------- %%% API %%-------------------------------------------------------------------- @@ -77,14 +185,21 @@ %% application, a system command, or some built-in subsystem. %% -------------------------------------------------------------------- --spec session_channel(connection_ref(), timeout()) -> - {ok, channel_id()} | {error, timeout | closed}. +-spec session_channel(ConnectionRef, Timeout) -> Result when + ConnectionRef :: ssh:connection_ref(), + Timeout :: timeout(), + Result :: {ok, ssh:channel_id()} | {error, reason()} . session_channel(ConnectionHandler, Timeout) -> session_channel(ConnectionHandler, ?DEFAULT_WINDOW_SIZE, ?DEFAULT_PACKET_SIZE, Timeout). --spec session_channel(connection_ref(), integer(), integer(), timeout()) -> - {ok, channel_id()} | {error, timeout | closed}. + +-spec session_channel(ConnectionRef, InitialWindowSize, MaxPacketSize, Timeout) -> Result when + ConnectionRef :: ssh:connection_ref(), + InitialWindowSize :: pos_integer(), + MaxPacketSize :: pos_integer(), + Timeout :: timeout(), + Result :: {ok, ssh:channel_id()} | {error, reason()} . session_channel(ConnectionHandler, InitialWindowSize, MaxPacketSize, Timeout) -> case ssh_connection_handler:open_channel(ConnectionHandler, "session", <<>>, @@ -100,8 +215,11 @@ session_channel(ConnectionHandler, InitialWindowSize, MaxPacketSize, Timeout) -> %% Description: Will request that the server start the %% execution of the given command. %%-------------------------------------------------------------------- --spec exec(connection_ref(), channel_id(), string(), timeout()) -> - success | failure | {error, timeout | closed}. +-spec exec(ConnectionRef, ChannelId, Command, Timeout) -> result() when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + Command :: string(), + Timeout :: timeout(). exec(ConnectionHandler, ChannelId, Command, TimeOut) -> ssh_connection_handler:request(ConnectionHandler, self(), ChannelId, "exec", @@ -112,8 +230,10 @@ exec(ConnectionHandler, ChannelId, Command, TimeOut) -> %% defined in /etc/passwd in UNIX systems) be started at the other %% end. %%-------------------------------------------------------------------- --spec shell(connection_ref(), channel_id()) -> - ok | success | failure | {error, timeout}. +-spec shell(ConnectionRef, ChannelId) -> Result when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + Result :: ok | success | failure | {error, timeout} . shell(ConnectionHandler, ChannelId) -> ssh_connection_handler:request(ConnectionHandler, self(), ChannelId, @@ -122,8 +242,11 @@ shell(ConnectionHandler, ChannelId) -> %% %% Description: Executes a predefined subsystem. %%-------------------------------------------------------------------- --spec subsystem(connection_ref(), channel_id(), string(), timeout()) -> - success | failure | {error, timeout | closed}. +-spec subsystem(ConnectionRef, ChannelId, Subsystem, Timeout) -> result() when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + Subsystem :: string(), + Timeout :: timeout(). subsystem(ConnectionHandler, ChannelId, SubSystem, TimeOut) -> ssh_connection_handler:request(ConnectionHandler, self(), @@ -134,12 +257,13 @@ subsystem(ConnectionHandler, ChannelId, SubSystem, TimeOut) -> %%-------------------------------------------------------------------- -spec send(connection_ref(), channel_id(), iodata()) -> ok | {error, timeout | closed}. + send(ConnectionHandler, ChannelId, Data) -> send(ConnectionHandler, ChannelId, 0, Data, infinity). --spec send(connection_ref(), channel_id(), integer()| iodata(), timeout() | iodata()) -> - ok | {error, timeout | closed}. +-spec send(connection_ref(), channel_id(), iodata(), timeout()) -> ok | {error, reason()}; + (connection_ref(), channel_id(), ssh_data_type_code(), iodata()) -> ok | {error, reason()}. send(ConnectionHandler, ChannelId, Data, TimeOut) when is_integer(TimeOut) -> send(ConnectionHandler, ChannelId, 0, Data, TimeOut); @@ -151,14 +275,15 @@ send(ConnectionHandler, ChannelId, Type, Data) -> send(ConnectionHandler, ChannelId, Type, Data, infinity). --spec send(connection_ref(), channel_id(), integer(), iodata(), timeout()) -> - ok | {error, timeout | closed}. +-spec send(connection_ref(), channel_id(), ssh_data_type_code(), iodata(), timeout()) -> ok | {error, reason()}. send(ConnectionHandler, ChannelId, Type, Data, TimeOut) -> ssh_connection_handler:send(ConnectionHandler, ChannelId, Type, Data, TimeOut). %%-------------------------------------------------------------------- --spec send_eof(connection_ref(), channel_id()) -> ok | {error, closed}. +-spec send_eof(ConnectionRef, ChannelId) -> ok | {error, closed} when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(). %% %% %% Description: Sends eof on the channel <ChannelId>. @@ -167,7 +292,10 @@ send_eof(ConnectionHandler, Channel) -> ssh_connection_handler:send_eof(ConnectionHandler, Channel). %%-------------------------------------------------------------------- --spec adjust_window(connection_ref(), channel_id(), integer()) -> ok. +-spec adjust_window(ConnectionRef, ChannelId, NumOfBytes) -> ok when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + NumOfBytes :: integer(). %% %% %% Description: Adjusts the ssh flowcontrol window. @@ -176,8 +304,12 @@ adjust_window(ConnectionHandler, Channel, Bytes) -> ssh_connection_handler:adjust_window(ConnectionHandler, Channel, Bytes). %%-------------------------------------------------------------------- --spec setenv(connection_ref(), channel_id(), string(), string(), timeout()) -> - success | failure | {error, timeout | closed}. +-spec setenv(ConnectionRef, ChannelId, Var, Value, Timeout) -> result() when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + Var :: string(), + Value :: string(), + Timeout :: timeout(). %% %% %% Description: Environment variables may be passed to the shell/command to be @@ -189,7 +321,9 @@ setenv(ConnectionHandler, ChannelId, Var, Value, TimeOut) -> %%-------------------------------------------------------------------- --spec close(connection_ref(), channel_id()) -> ok. +-spec close(ConnectionRef, ChannelId) -> ok when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(). %% %% %% Description: Sends a close message on the channel <ChannelId>. @@ -198,7 +332,11 @@ close(ConnectionHandler, ChannelId) -> ssh_connection_handler:close(ConnectionHandler, ChannelId). %%-------------------------------------------------------------------- --spec reply_request(connection_ref(), boolean(), success | failure, channel_id()) -> ok. +-spec reply_request(ConnectionRef, WantReply, Status, ChannelId) -> ok when + ConnectionRef :: ssh:connection_ref(), + WantReply :: boolean(), + Status :: req_status(), + ChannelId :: ssh:channel_id(). %% %% %% Description: Send status replies to requests that want such replies. @@ -211,15 +349,20 @@ reply_request(_,false, _, _) -> %%-------------------------------------------------------------------- %% Description: Sends a ssh connection protocol pty_req. %%-------------------------------------------------------------------- --spec ptty_alloc(connection_ref(), channel_id(), proplists:proplist()) -> - success | failure | {error, timeout}. +-spec ptty_alloc(ConnectionRef, ChannelId, Options) -> result() when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + Options :: proplists:proplist(). ptty_alloc(ConnectionHandler, Channel, Options) -> ptty_alloc(ConnectionHandler, Channel, Options, infinity). --spec ptty_alloc(connection_ref(), channel_id(), proplists:proplist(), timeout()) -> - success | failure | {error, timeout | closed}. +-spec ptty_alloc(ConnectionRef, ChannelId, Options, Timeout) -> result() when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + Options :: proplists:proplist(), + Timeout :: timeout(). ptty_alloc(ConnectionHandler, Channel, Options0, TimeOut) -> TermData = backwards_compatible(Options0, []), % FIXME @@ -252,6 +395,10 @@ signal(ConnectionHandler, Channel, Sig) -> "signal", false, [?string(Sig)], 0). +-spec exit_status(ConnectionRef, ChannelId, Status) -> ok when + ConnectionRef :: ssh:connection_ref(), + ChannelId :: ssh:channel_id(), + Status :: integer(). exit_status(ConnectionHandler, Channel, Status) -> ssh_connection_handler:request(ConnectionHandler, Channel, "exit-status", false, [?uint32(Status)], 0). @@ -713,29 +860,6 @@ request_success_msg(Data) -> %%%---------------------------------------------------------------- %%% %%% -bind(IP, Port, ChannelPid, Connection) -> - Binds = [{{IP, Port}, ChannelPid} - | lists:keydelete({IP, Port}, 1, - Connection#connection.port_bindings)], - Connection#connection{port_bindings = Binds}. - -unbind(IP, Port, Connection) -> - Connection#connection{ - port_bindings = - lists:keydelete({IP, Port}, 1, - Connection#connection.port_bindings)}. -unbind_channel(ChannelPid, Connection) -> - Binds = [{Bind, ChannelP} || {Bind, ChannelP} - <- Connection#connection.port_bindings, - ChannelP =/= ChannelPid], - Connection#connection{port_bindings = Binds}. - -bound_channel(IP, Port, Connection) -> - case lists:keysearch({IP, Port}, 1, Connection#connection.port_bindings) of - {value, {{IP, Port}, ChannelPid}} -> ChannelPid; - _ -> undefined - end. - encode_ip(Addr) when is_tuple(Addr) -> case catch inet_parse:ntoa(Addr) of {'EXIT',_} -> false; diff --git a/lib/ssh/src/ssh_connection_handler.erl b/lib/ssh/src/ssh_connection_handler.erl index 9df4f1e2d7..e984cbb21b 100644 --- a/lib/ssh/src/ssh_connection_handler.erl +++ b/lib/ssh/src/ssh_connection_handler.erl @@ -414,7 +414,6 @@ init([Role,Socket,Opts]) -> {Protocol, Callback, CloseTag} = ?GET_OPT(transport, Opts), C = #connection{channel_cache = ssh_client_channel:cache_create(), channel_id_seed = 0, - port_bindings = [], requests = [], options = Opts}, D0 = #data{starter = ?GET_INTERNAL_OPT(user_pid, Opts), @@ -2040,7 +2039,13 @@ log(Tag, D, Reason) -> end. -do_log(F, Reason, #data{ssh_params = S}) -> +do_log(F, Reason0, #data{ssh_params = S}) -> + Reason = + try io_lib:format("~s",[Reason0]) + of _ -> Reason0 + catch + _:_ -> io_lib:format("~p",[Reason0]) + end, case S of #ssh{role = Role} when Role==server ; Role==client -> diff --git a/lib/ssh/src/ssh_server_channel.erl b/lib/ssh/src/ssh_server_channel.erl index 555080e9ee..1905c40c98 100644 --- a/lib/ssh/src/ssh_server_channel.erl +++ b/lib/ssh/src/ssh_server_channel.erl @@ -37,7 +37,7 @@ -callback handle_msg(Msg ::term(), State :: term()) -> {ok, State::term()} | {stop, ChannelId::ssh:channel_id(), State::term()}. --callback handle_ssh_msg({ssh_cm, ConnectionRef::ssh:connection_ref(), SshMsg::term()}, +-callback handle_ssh_msg(ssh_connection:event(), State::term()) -> {ok, State::term()} | {stop, ChannelId::ssh:channel_id(), State::term()}. diff --git a/lib/ssh/src/ssh_sftp.erl b/lib/ssh/src/ssh_sftp.erl index 1b2ba5a50b..4b6e187c3a 100644 --- a/lib/ssh/src/ssh_sftp.erl +++ b/lib/ssh/src/ssh_sftp.erl @@ -92,24 +92,63 @@ -define(XF(S), S#state.xf). -define(REQID(S), S#state.req_id). +-type sftp_option() :: {timeout, timeout()} + | {sftp_vsn, pos_integer()} + | {window_size, pos_integer()} + | {packet_size, pos_integer()} . + +-type reason() :: atom() | string() | tuple() . + %%==================================================================== %% API %%==================================================================== + + +%%%================================================================ +%%% + +%%%---------------------------------------------------------------- +%%% start_channel/1 + start_channel(Cm) when is_pid(Cm) -> start_channel(Cm, []); + start_channel(Socket) when is_port(Socket) -> start_channel(Socket, []); -start_channel(Host) when is_list(Host) -> + +start_channel(Host) -> start_channel(Host, []). + +%%%---------------------------------------------------------------- +%%% start_channel/2 + +%%% -spec:s are as if Dialyzer handled signatures for separate +%%% function clauses. + +-spec start_channel(ssh:open_socket(), + [ssh:client_options() | sftp_option()] + ) + -> {ok,pid(),ssh:connection_ref()} | {error,reason()}; + + (ssh:connection_ref(), + [sftp_option()] + ) + -> {ok,pid()} | {ok,pid(),ssh:connection_ref()} | {error,reason()}; + + (ssh:host(), + [ssh:client_options() | sftp_option()] + ) + -> {ok,pid(),ssh:connection_ref()} | {error,reason()} . + start_channel(Socket, UserOptions) when is_port(Socket) -> - {SshOpts, _ChanOpts, SftpOpts} = handle_options(UserOptions), + {SshOpts, ChanOpts, SftpOpts} = handle_options(UserOptions), Timeout = % A mixture of ssh:connect and ssh_sftp:start_channel: proplists:get_value(connect_timeout, SshOpts, proplists:get_value(timeout, SftpOpts, infinity)), case ssh:connect(Socket, SshOpts, Timeout) of {ok,Cm} -> - case start_channel(Cm, UserOptions) of + case start_channel(Cm, ChanOpts ++ SftpOpts) of {ok, Pid} -> {ok, Pid, Cm}; Error -> @@ -144,6 +183,16 @@ start_channel(Cm, UserOptions) when is_pid(Cm) -> start_channel(Host, UserOptions) -> start_channel(Host, 22, UserOptions). + +%%%---------------------------------------------------------------- +%%% start_channel/3 + +-spec start_channel(ssh:host(), + inet:port_number(), + [ssh:client_option() | sftp_option()] + ) + -> {ok,pid(),ssh:connection_ref()} | {error,reason()}. + start_channel(Host, Port, UserOptions) -> {SshOpts, ChanOpts, SftpOpts} = handle_options(UserOptions), Timeout = % A mixture of ssh:connect and ssh_sftp:start_channel: @@ -168,6 +217,15 @@ start_channel(Host, Port, UserOptions) -> Error end. +%%% Helper for start_channel + +wait_for_version_negotiation(Pid, Timeout) -> + call(Pid, wait_for_version_negotiation, Timeout). + +%%%---------------------------------------------------------------- +-spec stop_channel(ChannelPid) -> ok when + ChannelPid :: pid(). + stop_channel(Pid) -> case is_process_alive(Pid) of true -> @@ -185,20 +243,63 @@ stop_channel(Pid) -> ok end. -wait_for_version_negotiation(Pid, Timeout) -> - call(Pid, wait_for_version_negotiation, Timeout). - +%%%---------------------------------------------------------------- +-spec open(ChannelPid, Name, Mode) -> {ok, Handle} | Error when + ChannelPid :: pid(), + Name :: string(), + Mode :: [read | write | append | binary | raw], + Handle :: term(), + Error :: {error, reason()} . open(Pid, File, Mode) -> open(Pid, File, Mode, ?FILEOP_TIMEOUT). +-spec open(ChannelPid, Name, Mode, Timeout) -> {ok, Handle} | Error when + ChannelPid :: pid(), + Name :: string(), + Mode :: [read | write | append | binary | raw], + Timeout :: timeout(), + Handle :: term(), + Error :: {error, reason()} . open(Pid, File, Mode, FileOpTimeout) -> call(Pid, {open, false, File, Mode}, FileOpTimeout). + +-type tar_crypto_spec() :: encrypt_spec() | decrypt_spec() . + +-type encrypt_spec() :: {init_fun(), crypto_fun(), final_fun()} . +-type decrypt_spec() :: {init_fun(), crypto_fun()} . + +-type init_fun() :: fun(() -> {ok,crypto_state()}) + | fun(() -> {ok,crypto_state(),chunk_size()}) . + +-type crypto_fun() :: fun((TextIn::binary(), crypto_state()) -> crypto_result()) . +-type crypto_result() :: {ok,TextOut::binary(),crypto_state()} + | {ok,TextOut::binary(),crypto_state(),chunk_size()} . + +-type final_fun() :: fun((FinalTextIn::binary(),crypto_state()) -> {ok,FinalTextOut::binary()}) . + +-type chunk_size() :: undefined | pos_integer(). +-type crypto_state() :: any() . + + +-spec open_tar(ChannelPid, Path, Mode) -> {ok, Handle} | Error when + ChannelPid :: pid(), + Path :: string(), + Mode :: [read | write | {crypto, tar_crypto_spec()} ], + Handle :: term(), + Error :: {error, reason()} . open_tar(Pid, File, Mode) -> open_tar(Pid, File, Mode, ?FILEOP_TIMEOUT). +-spec open_tar(ChannelPid, Path, Mode, Timeout) -> {ok, Handle} | Error when + ChannelPid :: pid(), + Path :: string(), + Mode :: [read | write | {crypto, tar_crypto_spec()} ], + Timeout :: timeout(), + Handle :: term(), + Error :: {error, reason()} . open_tar(Pid, File, Mode, FileOpTimeout) -> case {lists:member(write,Mode), lists:member(read,Mode), - Mode -- [read,write]} of + Mode -- [write,read]} of {true,false,[]} -> {ok,Handle} = open(Pid, File, [write], FileOpTimeout), erl_tar:init(Pid, write, @@ -264,13 +365,33 @@ open_tar(Pid, File, Mode, FileOpTimeout) -> end. +-spec opendir(ChannelPid, Path) -> {ok, Handle} | Error when + ChannelPid :: pid(), + Path :: string(), + Handle :: term(), + Error :: {error, reason()} . opendir(Pid, Path) -> opendir(Pid, Path, ?FILEOP_TIMEOUT). +-spec opendir(ChannelPid, Path, Timeout) -> {ok, Handle} | Error when + ChannelPid :: pid(), + Path :: string(), + Timeout :: timeout(), + Handle :: term(), + Error :: {error, reason()} . opendir(Pid, Path, FileOpTimeout) -> call(Pid, {opendir, false, Path}, FileOpTimeout). +-spec close(ChannelPid, Handle) -> ok | Error when + ChannelPid :: pid(), + Handle :: term(), + Error :: {error, reason()} . close(Pid, Handle) -> close(Pid, Handle, ?FILEOP_TIMEOUT). +-spec close(ChannelPid, Handle, Timeout) -> ok | Error when + ChannelPid :: pid(), + Handle :: term(), + Timeout :: timeout(), + Error :: {error, reason()} . close(Pid, Handle, FileOpTimeout) -> call(Pid, {close,false,Handle}, FileOpTimeout). @@ -279,47 +400,149 @@ readdir(Pid,Handle) -> readdir(Pid,Handle, FileOpTimeout) -> call(Pid, {readdir,false,Handle}, FileOpTimeout). +-spec pread(ChannelPid, Handle, Position, Len) -> {ok, Data} | eof | Error when + ChannelPid :: pid(), + Handle :: term(), + Position :: integer(), + Len :: integer(), + Data :: string() | binary(), + Error :: {error, reason()}. pread(Pid, Handle, Offset, Len) -> pread(Pid, Handle, Offset, Len, ?FILEOP_TIMEOUT). + +-spec pread(ChannelPid, Handle, Position, Len, Timeout) -> {ok, Data} | eof | Error when + ChannelPid :: pid(), + Handle :: term(), + Position :: integer(), + Len :: integer(), + Timeout :: timeout(), + Data :: string() | binary(), + Error :: {error, reason()}. pread(Pid, Handle, Offset, Len, FileOpTimeout) -> call(Pid, {pread,false,Handle, Offset, Len}, FileOpTimeout). + +-spec read(ChannelPid, Handle, Len) -> {ok, Data} | eof | Error when + ChannelPid :: pid(), + Handle :: term(), + Len :: integer(), + Data :: string() | binary(), + Error :: {error, reason()}. read(Pid, Handle, Len) -> read(Pid, Handle, Len, ?FILEOP_TIMEOUT). + +-spec read(ChannelPid, Handle, Len, Timeout) -> {ok, Data} | eof | Error when + ChannelPid :: pid(), + Handle :: term(), + Len :: integer(), + Timeout :: timeout(), + Data :: string() | binary(), + Error :: {error, reason()}. read(Pid, Handle, Len, FileOpTimeout) -> call(Pid, {read,false,Handle, Len}, FileOpTimeout). + %% TODO this ought to be a cast! Is so in all practical meaning %% even if it is obscure! +-spec apread(ChannelPid, Handle, Position, Len) -> {async, N} | Error when + ChannelPid :: pid(), + Handle :: term(), + Position :: integer(), + Len :: integer(), + Error :: {error, reason()}, + N :: term() . apread(Pid, Handle, Offset, Len) -> call(Pid, {pread,true,Handle, Offset, Len}, infinity). %% TODO this ought to be a cast! +-spec aread(ChannelPid, Handle, Len) -> {async, N} | Error when + ChannelPid :: pid(), + Handle :: term(), + Len :: integer(), + Error :: {error, reason()}, + N :: term() . aread(Pid, Handle, Len) -> call(Pid, {read,true,Handle, Len}, infinity). + +-spec pwrite(ChannelPid, Handle, Position, Data) -> ok | Error when + ChannelPid :: pid(), + Handle :: term(), + Position :: integer(), + Data :: iolist(), + Error :: {error, reason()}. pwrite(Pid, Handle, Offset, Data) -> pwrite(Pid, Handle, Offset, Data, ?FILEOP_TIMEOUT). + +-spec pwrite(ChannelPid, Handle, Position, Data, Timeout) -> ok | Error when + ChannelPid :: pid(), + Handle :: term(), + Position :: integer(), + Data :: iolist(), + Timeout :: timeout(), + Error :: {error, reason()}. pwrite(Pid, Handle, Offset, Data, FileOpTimeout) -> call(Pid, {pwrite,false,Handle,Offset,Data}, FileOpTimeout). + +-spec write(ChannelPid, Handle, Data) -> ok | Error when + ChannelPid :: pid(), + Handle :: term(), + Data :: iodata(), + Error :: {error, reason()}. write(Pid, Handle, Data) -> write(Pid, Handle, Data, ?FILEOP_TIMEOUT). + +-spec write(ChannelPid, Handle, Data, Timeout) -> ok | Error when + ChannelPid :: pid(), + Handle :: term(), + Data :: iodata(), + Timeout :: timeout(), + Error :: {error, reason()}. write(Pid, Handle, Data, FileOpTimeout) -> call(Pid, {write,false,Handle,Data}, FileOpTimeout). %% TODO this ought to be a cast! Is so in all practical meaning %% even if it is obscure! +-spec apwrite(ChannelPid, Handle, Position, Data) -> {async, N} | Error when + ChannelPid :: pid(), + Handle :: term(), + Position :: integer(), + Data :: binary(), + Error :: {error, reason()}, + N :: term() . apwrite(Pid, Handle, Offset, Data) -> call(Pid, {pwrite,true,Handle,Offset,Data}, infinity). %% TODO this ought to be a cast! Is so in all practical meaning %% even if it is obscure! +-spec awrite(ChannelPid, Handle, Data) -> {async, N} | Error when + ChannelPid :: pid(), + Handle :: term(), + Data :: binary(), + Error :: {error, reason()}, + N :: term() . awrite(Pid, Handle, Data) -> call(Pid, {write,true,Handle,Data}, infinity). +-spec position(ChannelPid, Handle, Location) -> {ok, NewPosition} | Error when + ChannelPid :: pid(), + Handle :: term(), + Location :: Offset | {bof, Offset} | {cur, Offset} | {eof, Offset} | bof | cur | eof, + Offset :: integer(), + NewPosition :: integer(), + Error :: {error, reason()}. position(Pid, Handle, Pos) -> position(Pid, Handle, Pos, ?FILEOP_TIMEOUT). + +-spec position(ChannelPid, Handle, Location, Timeout) -> {ok, NewPosition} | Error when + ChannelPid :: pid(), + Handle :: term(), + Location :: Offset | {bof, Offset} | {cur, Offset} | {eof, Offset} | bof | cur | eof, + Timeout :: timeout(), + Offset :: integer(), + NewPosition :: integer(), + Error :: {error, reason()}. position(Pid, Handle, Pos, FileOpTimeout) -> call(Pid, {position, Handle, Pos}, FileOpTimeout). @@ -328,8 +551,21 @@ real_path(Pid, Path) -> real_path(Pid, Path, FileOpTimeout) -> call(Pid, {real_path, false, Path}, FileOpTimeout). + +-spec read_file_info(ChannelPid, Name) -> {ok, FileInfo} | Error when + ChannelPid :: pid(), + Name :: string(), + FileInfo :: file:file_info(), + Error :: {error, reason()}. read_file_info(Pid, Name) -> read_file_info(Pid, Name, ?FILEOP_TIMEOUT). + +-spec read_file_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | Error when + ChannelPid :: pid(), + Name :: string(), + Timeout :: timeout(), + FileInfo :: file:file_info(), + Error :: {error, reason()}. read_file_info(Pid, Name, FileOpTimeout) -> call(Pid, {read_file_info,false,Name}, FileOpTimeout). @@ -338,18 +574,57 @@ get_file_info(Pid, Handle) -> get_file_info(Pid, Handle, FileOpTimeout) -> call(Pid, {get_file_info,false,Handle}, FileOpTimeout). + +-spec write_file_info(ChannelPid, Name, FileInfo) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + FileInfo :: file:file_info(), + Error :: {error, reason()}. write_file_info(Pid, Name, Info) -> write_file_info(Pid, Name, Info, ?FILEOP_TIMEOUT). + +-spec write_file_info(ChannelPid, Name, FileInfo, Timeout) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + FileInfo :: file:file_info(), + Timeout :: timeout(), + Error :: {error, reason()}. write_file_info(Pid, Name, Info, FileOpTimeout) -> call(Pid, {write_file_info,false,Name, Info}, FileOpTimeout). + +-spec read_link_info(ChannelPid, Name) -> {ok, FileInfo} | Error when + ChannelPid :: pid(), + Name :: string(), + FileInfo :: file:file_info(), + Error :: {error, reason()}. read_link_info(Pid, Name) -> read_link_info(Pid, Name, ?FILEOP_TIMEOUT). + +-spec read_link_info(ChannelPid, Name, Timeout) -> {ok, FileInfo} | Error when + ChannelPid :: pid(), + Name :: string(), + FileInfo :: file:file_info(), + Timeout :: timeout(), + Error :: {error, reason()}. read_link_info(Pid, Name, FileOpTimeout) -> call(Pid, {read_link_info,false,Name}, FileOpTimeout). + +-spec read_link(ChannelPid, Name) -> {ok, Target} | Error when + ChannelPid :: pid(), + Name :: string(), + Target :: string(), + Error :: {error, reason()}. read_link(Pid, LinkName) -> read_link(Pid, LinkName, ?FILEOP_TIMEOUT). + +-spec read_link(ChannelPid, Name, Timeout) -> {ok, Target} | Error when + ChannelPid :: pid(), + Name :: string(), + Target :: string(), + Timeout :: timeout(), + Error :: {error, reason()}. read_link(Pid, LinkName, FileOpTimeout) -> case call(Pid, {read_link,false,LinkName}, FileOpTimeout) of {ok, [{Name, _Attrs}]} -> @@ -358,28 +633,79 @@ read_link(Pid, LinkName, FileOpTimeout) -> ErrMsg end. +-spec make_symlink(ChannelPid, Name, Target) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Target :: string(), + Error :: {error, reason()} . make_symlink(Pid, Name, Target) -> make_symlink(Pid, Name, Target, ?FILEOP_TIMEOUT). +-spec make_symlink(ChannelPid, Name, Target, Timeout) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Target :: string(), + Timeout :: timeout(), + Error :: {error, reason()} . make_symlink(Pid, Name, Target, FileOpTimeout) -> call(Pid, {make_symlink,false, Name, Target}, FileOpTimeout). + +-spec rename(ChannelPid, OldName, NewName) -> ok | Error when + ChannelPid :: pid(), + OldName :: string(), + NewName :: string(), + Error :: {error, reason()}. rename(Pid, FromFile, ToFile) -> rename(Pid, FromFile, ToFile, ?FILEOP_TIMEOUT). + +-spec rename(ChannelPid, OldName, NewName, Timeout) -> ok | Error when + ChannelPid :: pid(), + OldName :: string(), + NewName :: string(), + Timeout :: timeout(), + Error :: {error, reason()}. rename(Pid, FromFile, ToFile, FileOpTimeout) -> call(Pid, {rename,false,FromFile, ToFile}, FileOpTimeout). +-spec delete(ChannelPid, Name) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Error :: {error, reason()} . delete(Pid, Name) -> delete(Pid, Name, ?FILEOP_TIMEOUT). +-spec delete(ChannelPid, Name, Timeout) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Timeout :: timeout(), + Error :: {error, reason()} . delete(Pid, Name, FileOpTimeout) -> call(Pid, {delete,false,Name}, FileOpTimeout). +-spec make_dir(ChannelPid, Name) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Error :: {error, reason()} . make_dir(Pid, Name) -> make_dir(Pid, Name, ?FILEOP_TIMEOUT). +-spec make_dir(ChannelPid, Name, Timeout) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Timeout :: timeout(), + Error :: {error, reason()} . make_dir(Pid, Name, FileOpTimeout) -> call(Pid, {make_dir,false,Name}, FileOpTimeout). +-spec del_dir(ChannelPid, Name) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Error :: {error, reason()} . del_dir(Pid, Name) -> del_dir(Pid, Name, ?FILEOP_TIMEOUT). +-spec del_dir(ChannelPid, Name, Timeout) -> ok | Error when + ChannelPid :: pid(), + Name :: string(), + Timeout :: timeout(), + Error :: {error, reason()} . del_dir(Pid, Name, FileOpTimeout) -> call(Pid, {del_dir,false,Name}, FileOpTimeout). @@ -396,9 +722,21 @@ recv_window(Pid, FileOpTimeout) -> call(Pid, recv_window, FileOpTimeout). +-spec list_dir(ChannelPid, Path) -> {ok,FileNames} | Error when + ChannelPid :: pid(), + Path :: string(), + FileNames :: [FileName], + FileName :: string(), + Error :: {error, reason()} . list_dir(Pid, Name) -> list_dir(Pid, Name, ?FILEOP_TIMEOUT). - +-spec list_dir(ChannelPid, Path, Timeout) -> {ok,FileNames} | Error when + ChannelPid :: pid(), + Path :: string(), + Timeout :: timeout(), + FileNames :: [FileName], + FileName :: string(), + Error :: {error, reason()} . list_dir(Pid, Name, FileOpTimeout) -> case opendir(Pid, Name, FileOpTimeout) of {ok,Handle} -> @@ -429,9 +767,20 @@ do_list_dir(Pid, Handle, FileOpTimeout, Acc) -> end. +-spec read_file(ChannelPid, File) -> {ok, Data} | Error when + ChannelPid :: pid(), + File :: string(), + Data :: binary(), + Error :: {error, reason()}. read_file(Pid, Name) -> read_file(Pid, Name, ?FILEOP_TIMEOUT). +-spec read_file(ChannelPid, File, Timeout) -> {ok, Data} | Error when + ChannelPid :: pid(), + File :: string(), + Data :: binary(), + Timeout :: timeout(), + Error :: {error, reason()}. read_file(Pid, Name, FileOpTimeout) -> case open(Pid, Name, [read, binary], FileOpTimeout) of {ok, Handle} -> @@ -453,9 +802,20 @@ read_file_loop(Pid, Handle, PacketSz, FileOpTimeout, Acc) -> Error end. +-spec write_file(ChannelPid, File, Data) -> ok | Error when + ChannelPid :: pid(), + File :: string(), + Data :: iodata(), + Error :: {error, reason()}. write_file(Pid, Name, List) -> write_file(Pid, Name, List, ?FILEOP_TIMEOUT). +-spec write_file(ChannelPid, File, Data, Timeout) -> ok | Error when + ChannelPid :: pid(), + File :: string(), + Data :: iodata(), + Timeout :: timeout(), + Error :: {error, reason()}. write_file(Pid, Name, List, FileOpTimeout) when is_list(List) -> write_file(Pid, Name, list_to_binary(List), FileOpTimeout); write_file(Pid, Name, Bin, FileOpTimeout) -> diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl index 5ec12e2d04..bf921f0ff3 100644 --- a/lib/ssh/src/ssh_sftpd.erl +++ b/lib/ssh/src/ssh_sftpd.erl @@ -58,7 +58,17 @@ %%==================================================================== %% API %%==================================================================== --spec subsystem_spec(list()) -> subsystem_spec(). +-spec subsystem_spec(Options) -> Spec when + Options :: [ {cwd, string()} | + {file_handler, CallbackModule::string()} | + {max_files, integer()} | + {root, string()} | + {sftpd_vsn, integer()} + ], + Spec :: {Name, {CbMod,Options}}, + Name :: string(), + CbMod :: atom() . + subsystem_spec(Options) -> {"sftp", {?MODULE, Options}}. diff --git a/lib/ssl/test/openssl_renegotiate_SUITE.erl b/lib/ssl/test/openssl_renegotiate_SUITE.erl index 91a8175ac6..787b5208b8 100644 --- a/lib/ssl/test/openssl_renegotiate_SUITE.erl +++ b/lib/ssl/test/openssl_renegotiate_SUITE.erl @@ -104,8 +104,9 @@ init_per_group(GroupName, Config) -> true -> case ssl_test_lib:check_sane_openssl_version(GroupName) of true -> - ssl_test_lib:init_tls_version(GroupName, Config); - false -> + ssl_test_lib:check_sane_openssl_renegotaite(ssl_test_lib:init_tls_version(GroupName, Config), + GroupName); + false -> {skip, openssl_does_not_support_version} end; false -> diff --git a/lib/ssl/test/openssl_session_SUITE.erl b/lib/ssl/test/openssl_session_SUITE.erl index 24dcaa7817..7c129633da 100644 --- a/lib/ssl/test/openssl_session_SUITE.erl +++ b/lib/ssl/test/openssl_session_SUITE.erl @@ -56,8 +56,8 @@ groups() -> {'tlsv1.1', [], tests()}, {'tlsv1', [], tests()}, {'sslv3', [], tests()}, - {'dtlsv1.2', [], dtls_tests()}, - {'dtlsv1', [], dtls_tests()} + {'dtlsv1.2', [], tests()}, + {'dtlsv1', [], tests()} ]; false -> [{'tlsv1.2', [], tests()}, @@ -73,11 +73,6 @@ tests() -> reuse_session_erlang_client ]. -dtls_tests() -> - [ - reuse_session_erlang_server - ]. - init_per_suite(Config0) -> case os:find_executable("openssl") of @@ -154,6 +149,7 @@ reuse_session_erlang_server() -> [{doc, "Test erlang server with openssl client that reconnects with the" "same session id, to test reusing of sessions."}]. reuse_session_erlang_server(Config) when is_list(Config) -> + process_flag(trap_exit, true), ServerOpts = ssl_test_lib:ssl_options(server_rsa_opts, Config), {_, ServerNode, Hostname} = ssl_test_lib:run_where(Config), @@ -193,19 +189,20 @@ reuse_session_erlang_client(Config) when is_list(Config) -> ClientOpts = ssl_test_lib:ssl_options(client_rsa_opts, Config), ServerOpts = ssl_test_lib:ssl_options(server_rsa_opts, Config), {ClientNode, _, Hostname} = ssl_test_lib:run_where(Config), - + + Version = ssl_test_lib:protocol_version(Config), Port = ssl_test_lib:inet_port(node()), CertFile = proplists:get_value(certfile, ServerOpts), CACertFile = proplists:get_value(cacertfile, ServerOpts), KeyFile = proplists:get_value(keyfile, ServerOpts), Exe = "openssl", - Args = ["s_server", "-accept", integer_to_list(Port), + Args = ["s_server", "-accept", integer_to_list(Port), ssl_test_lib:version_flag(Version), "-cert", CertFile,"-key", KeyFile, "-CAfile", CACertFile], OpensslPort = ssl_test_lib:portable_open_port(Exe, Args), - ssl_test_lib:wait_for_openssl_server(Port, tls), + ssl_test_lib:wait_for_openssl_server(Port, proplists:get_value(protocol, Config)), Client0 = ssl_test_lib:start_client([{node, ClientNode}, diff --git a/lib/ssl/test/ssl_api_SUITE.erl b/lib/ssl/test/ssl_api_SUITE.erl index fefecc0b65..14e5024b91 100644 --- a/lib/ssl/test/ssl_api_SUITE.erl +++ b/lib/ssl/test/ssl_api_SUITE.erl @@ -1251,8 +1251,9 @@ der_input(Config) when is_list(Config) -> [_, _,_, _, Prop] = StatusInfo, State = ssl_test_lib:state(Prop), [CADb | _] = element(6, State), - + ct:sleep(?SLEEP*2), %%Make sure there is no outstanding clean cert db msg in manager Size = ets:info(CADb, size), + ct:pal("Size ~p", [Size]), SeverVerifyOpts = ssl_test_lib:ssl_options(server_rsa_opts, Config), {ServerCert, ServerKey, ServerCaCerts, DHParams} = der_input_opts([{dhfile, DHParamFile} | @@ -1281,6 +1282,7 @@ der_input(Config) when is_list(Config) -> ssl_test_lib:check_result(Server, ok, Client, ok), ssl_test_lib:close(Server), ssl_test_lib:close(Client), + %% Using only DER input should not increase file indexed DB Size = ets:info(CADb, size). %%-------------------------------------------------------------------- @@ -1902,7 +1904,7 @@ do_recv_close(Socket) -> tls_close(Socket) -> ok = ssl_test_lib:send_recv_result(Socket), - case ssl:close(Socket, 5000) of + case ssl:close(Socket, 10000) of ok -> ok; {error, closed} -> diff --git a/lib/ssl/test/ssl_session_cache_SUITE.erl b/lib/ssl/test/ssl_session_cache_SUITE.erl index b71b15b028..553c2d247b 100644 --- a/lib/ssl/test/ssl_session_cache_SUITE.erl +++ b/lib/ssl/test/ssl_session_cache_SUITE.erl @@ -28,7 +28,7 @@ -include_lib("common_test/include/ct.hrl"). -define(DELAY, 500). --define(SLEEP, 500). +-define(SLEEP, 1000). -define(TIMEOUT, 60000). -define(LONG_TIMEOUT, 600000). -define(MAX_TABLE_SIZE, 5). @@ -207,7 +207,7 @@ session_cleanup(Config) when is_list(Config) -> end, %% Make sure session is registered - ct:sleep(?SLEEP), + ct:sleep(?SLEEP*2), {status, _, _, StatusInfo} = sys:get_status(whereis(ssl_manager)), [_, _,_, _, Prop] = StatusInfo, diff --git a/lib/ssl/test/ssl_test_lib.erl b/lib/ssl/test/ssl_test_lib.erl index 7dd27fb5cb..c4f294771a 100644 --- a/lib/ssl/test/ssl_test_lib.erl +++ b/lib/ssl/test/ssl_test_lib.erl @@ -493,7 +493,10 @@ check_result(Server, ServerMsg, Client, ClientMsg) -> ct:log("~p:~p~n Openssl ~s~n",[?MODULE,?LINE, Debug]), check_result(Server, ServerMsg, Client, ClientMsg); {Port,closed} when is_port(Port) -> - ct:log("~p:~p~n Openssl port ~n",[?MODULE,?LINE]), + ct:log("~p:~p~n Openssl port closed ~n",[?MODULE,?LINE]), + check_result(Server, ServerMsg, Client, ClientMsg); + {'EXIT', epipe} -> + ct:log("~p:~p~n Openssl port died ~n",[?MODULE,?LINE]), check_result(Server, ServerMsg, Client, ClientMsg); Unexpected -> Reason = {{expected, {Client, ClientMsg}}, @@ -2187,6 +2190,13 @@ check_sane_openssl_renegotaite(Config, Version) when Version == 'tlsv1.1'; _ -> check_sane_openssl_renegotaite(Config) end; +check_sane_openssl_renegotaite(Config, 'sslv3') -> + case os:cmd("openssl version") of + "OpenSSL 1" ++ _ -> + {skip, "Known renegotiation bug with sslv3 in OpenSSL"}; + _ -> + check_sane_openssl_renegotaite(Config) + end; check_sane_openssl_renegotaite(Config, _) -> check_sane_openssl_renegotaite(Config). diff --git a/lib/ssl/test/tls_api_SUITE.erl b/lib/ssl/test/tls_api_SUITE.erl index 5a74ec1892..7239d4cb90 100644 --- a/lib/ssl/test/tls_api_SUITE.erl +++ b/lib/ssl/test/tls_api_SUITE.erl @@ -794,16 +794,16 @@ tls_downgrade_result(Socket, Pid) -> {tcp, TCPSocket, <<"Downgraded">>} -> ok; {tcp_closed, TCPSocket} -> - ct:fail("Peer timed out, downgrade aborted"), + ct:fail("Did not receive TCP data"), ok; Other -> {error, Other} end; {error, timeout} -> - ct:fail("Timed out, downgrade aborted"), + ct:comment("Timed out, downgrade aborted"), ok; Fail -> - {error, Fail} + ct:fail(Fail) end. tls_shutdown_result(Socket, server) -> diff --git a/lib/stdlib/doc/src/io_protocol.xml b/lib/stdlib/doc/src/io_protocol.xml index 84b5f62c7f..f05c358866 100644 --- a/lib/stdlib/doc/src/io_protocol.xml +++ b/lib/stdlib/doc/src/io_protocol.xml @@ -5,7 +5,7 @@ <header> <copyright> <year>1999</year> - <year>2016</year> + <year>2019</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -168,16 +168,6 @@ ok returns it "as is".</item> </list> - <p>For backward compatibility, the following <c>Request</c>s are also to be - handled by an I/O server (they are not to be present after - Erlang/OTP R15B):</p> - - <pre> -{put_chars, Characters} -{put_chars, Module, Function, Args}</pre> - - <p>These are to behave as <c>{put_chars, latin1, Characters}</c> and - <c>{put_chars, latin1, Module, Function, Args}</c>, respectively.</p> </section> <section> @@ -332,19 +322,6 @@ eof </item> </list> - <p>For backward compatibility, the following <c>Request</c>s are also to be - handled by an I/O server (they are not to be present after - Erlang/OTP R15B):</p> - - <pre> -{get_until, Prompt, Module, Function, ExtraArgs} -{get_chars, Prompt, N} -{get_line, Prompt}</pre> - - <p>These are to behave as - <c>{get_until, latin1, Prompt, Module, Function, ExtraArgs}</c>, - <c>{get_chars, latin1, Prompt, N}</c>, and - <c>{get_line, latin1, Prompt}</c>, respectively.</p> </section> <section> @@ -637,24 +614,6 @@ request({requests, Reqs}, State) -> function applying the requests in the list one after another, returning the last result.</p> - <p>We need to handle backward compatibility and the - <seealso marker="kernel:file"><c>file</c></seealso> module (which - uses the old requests until backward compatibility with pre-R13 nodes is - no longer needed). Notice that the I/O server does not work with a simple - <c>file:write/2</c> if these are not added:</p> - - <code> -request({put_chars,Chars}, State) -> - request({put_chars,latin1,Chars}, State); -request({put_chars,M,F,As}, State) -> - request({put_chars,latin1,M,F,As}, State); -request({get_chars,Prompt,N}, State) -> - request({get_chars,latin1,Prompt,N}, State); -request({get_line,Prompt}, State) -> - request({get_line,latin1,Prompt}, State); -request({get_until, Prompt,M,F,As}, State) -> - request({get_until,latin1,Prompt,M,F,As}, State);</code> - <p><c>{error, request}</c> must be returned if the request is not recognized:</p> diff --git a/lib/stdlib/src/edlin.erl b/lib/stdlib/src/edlin.erl index f027d05f55..6078c5e67b 100644 --- a/lib/stdlib/src/edlin.erl +++ b/lib/stdlib/src/edlin.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2018. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -352,9 +352,6 @@ do_op({blink,C,M}, Bef=[$$,$$|_], Aft, Rs) -> %% don't blink after a $ do_op({blink,C,_}, Bef=[$$|_], Aft, Rs) -> do_op({insert,C}, Bef, Aft, Rs); -%do_op({blink,C,M}, Bef, [], Rs) -> -% N = over_paren(Bef, C, M), -% {blink,N+1,{[C|Bef],[]},[{move_rel,-(N+1)},{put_chars,[C]}|Rs]}; do_op({blink,C,M}, Bef, Aft, Rs) -> case over_paren(Bef, C, M) of beep -> diff --git a/lib/stdlib/src/io.erl b/lib/stdlib/src/io.erl index 63c9a6bddf..1848aa3628 100644 --- a/lib/stdlib/src/io.erl +++ b/lib/stdlib/src/io.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2018. All Rights Reserved. +%% Copyright Ericsson AB 1996-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -106,7 +106,6 @@ nl() -> IoDevice :: device(). nl(Io) -> -% o_request(Io, {put_chars,io_lib:nl()}). o_request(Io, nl, nl). -spec columns() -> {'ok', pos_integer()} | {'error', 'enotsup'}. @@ -255,8 +254,6 @@ read(Io, Prompt) -> case request(Io, {get_until,unicode,Prompt,erl_scan,tokens,[1]}) of {ok,Toks,_EndLine} -> erl_parse:parse_term(Toks); -% {error, Reason} when atom(Reason) -> -% erlang:error(conv_reason(read, Reason), [Io, Prompt]); {error,E,_EndLine} -> {error,E}; {eof,_EndLine} -> @@ -352,12 +349,7 @@ fread(Prompt, Format) -> | server_no_data(). fread(Io, Prompt, Format) -> - case request(Io, {fread,Prompt,Format}) of -% {error, Reason} when atom(Reason) -> -% erlang:error(conv_reason(fread, Reason), [Io, Prompt, Format]); - Other -> - Other - end. + request(Io, {fread,Prompt,Format}). -spec format(Format) -> 'ok' when Format :: format(). diff --git a/lib/stdlib/src/io_lib.erl b/lib/stdlib/src/io_lib.erl index 21d66c5529..e2823b70f2 100644 --- a/lib/stdlib/src/io_lib.erl +++ b/lib/stdlib/src/io_lib.erl @@ -78,7 +78,7 @@ %% Utilities for collecting characters. -export([collect_chars/3, collect_chars/4, - collect_line/2, collect_line/3, collect_line/4, + collect_line/3, collect_line/4, get_until/3, get_until/4]). %% The following functions were used by Yecc's include-file. @@ -851,6 +851,7 @@ collect_chars({binary,Stack,N}, Data,latin1, _) -> end; collect_chars({list,Stack,N}, Data, _,_) -> collect_chars_list(Stack, N, Data); + %% collect_chars(Continuation, MoreChars, Count) %% Returns: %% {done,Result,RestChars} @@ -881,32 +882,6 @@ collect_chars_list(Stack, N, []) -> collect_chars_list(Stack,N, [H|T]) -> collect_chars_list([H|Stack], N-1, T). -%% collect_line(Continuation, MoreChars) -%% Returns: -%% {done,Result,RestChars} -%% {more,Continuation} -%% -%% XXX Can be removed when compatibility with pre-R12B-5 nodes -%% is no longer required. -%% -collect_line([], Chars) -> - collect_line1(Chars, []); -collect_line({SoFar}, More) -> - collect_line1(More, SoFar). - -collect_line1([$\r, $\n|Rest], Stack) -> - collect_line1([$\n|Rest], Stack); -collect_line1([$\n|Rest], Stack) -> - {done,lists:reverse([$\n|Stack], []),Rest}; -collect_line1([C|Rest], Stack) -> - collect_line1(Rest, [C|Stack]); -collect_line1(eof, []) -> - {done,eof,[]}; -collect_line1(eof, Stack) -> - {done,lists:reverse(Stack, []),[]}; -collect_line1([], Stack) -> - {more,{Stack}}. - %% collect_line(State, Data, _). New in R9C. %% Returns: %% {stop,Result,RestData} diff --git a/lib/stdlib/src/io_lib_pretty.erl b/lib/stdlib/src/io_lib_pretty.erl index 77f02eafe0..838d412d0c 100644 --- a/lib/stdlib/src/io_lib_pretty.erl +++ b/lib/stdlib/src/io_lib_pretty.erl @@ -895,9 +895,6 @@ write_string(S, _Uni) -> io_lib:write_string(S, $"). %" expand({_, _, _Dots=0, no_more} = If, _T, _Dd) -> If; -%% expand({{list,L}, _Len, _, no_more}, T, Dd) -> -%% {NL, NLen, NDots} = expand_list(L, T, Dd, 2), -%% {{list,NL}, NLen, NDots, no_more}; expand({{tuple,IsTagged,L}, _Len, _, no_more}, T, Dd) -> {NL, NLen, NDots} = expand_list(L, T, Dd, 2), {{tuple,IsTagged,NL}, NLen, NDots, no_more}; diff --git a/lib/stdlib/src/ms_transform.erl b/lib/stdlib/src/ms_transform.erl index 97ec785c62..74efe5c513 100644 --- a/lib/stdlib/src/ms_transform.erl +++ b/lib/stdlib/src/ms_transform.erl @@ -1100,6 +1100,8 @@ normalise({bin,_,Fs}) -> B; normalise({cons,_,Head,Tail}) -> [normalise(Head)|normalise(Tail)]; +normalise({op,_,'++',A,B}) -> + normalise(A) ++ normalise(B); normalise({tuple,_,Args}) -> list_to_tuple(normalise_list(Args)); normalise({map,_,Pairs0}) -> diff --git a/lib/stdlib/test/binary_module_SUITE.erl b/lib/stdlib/test/binary_module_SUITE.erl index 9b2033ec4a..be8ab3b98e 100644 --- a/lib/stdlib/test/binary_module_SUITE.erl +++ b/lib/stdlib/test/binary_module_SUITE.erl @@ -716,22 +716,22 @@ referenced(Config) when is_list(Config) -> badarg = ?MASK_ERROR(binary:referenced_byte_size(apa)), badarg = ?MASK_ERROR(binary:referenced_byte_size({})), badarg = ?MASK_ERROR(binary:referenced_byte_size(1)), - A = <<1,2,3>>, - B = binary:copy(A,1000), - 3 = binary:referenced_byte_size(A), - 3000 = binary:referenced_byte_size(B), - <<_:8,C:2/binary>> = A, - 3 = binary:referenced_byte_size(C), - 2 = binary:referenced_byte_size(binary:copy(C)), - <<_:7,D:2/binary,_:1>> = A, - 2 = binary:referenced_byte_size(binary:copy(D)), - 3 = binary:referenced_byte_size(D), - <<_:8,E:2/binary,_/binary>> = B, - 3000 = binary:referenced_byte_size(E), - 2 = binary:referenced_byte_size(binary:copy(E)), - <<_:7,F:2/binary,_:1,_/binary>> = B, - 2 = binary:referenced_byte_size(binary:copy(F)), - 3000 = binary:referenced_byte_size(F), + A = <<0:(1024 * 8)>>, + B = binary:copy(A, 1000), + 1024 = binary:referenced_byte_size(A), + 1024000 = binary:referenced_byte_size(B), + <<_:8,C:1023/binary>> = A, + 1024 = binary:referenced_byte_size(C), + 1023 = binary:referenced_byte_size(binary:copy(C)), + <<_:7,D:1023/binary,_:1>> = A, + 1023 = binary:referenced_byte_size(binary:copy(D)), + 1024 = binary:referenced_byte_size(D), + <<_:8,E:128/binary,_/binary>> = B, + 1024000 = binary:referenced_byte_size(E), + 128 = binary:referenced_byte_size(binary:copy(E)), + <<_:7,F:128/binary,_:1,_/binary>> = B, + 128 = binary:referenced_byte_size(binary:copy(F)), + 1024000 = binary:referenced_byte_size(F), ok. diff --git a/lib/stdlib/test/ets_SUITE.erl b/lib/stdlib/test/ets_SUITE.erl index 05893a92b0..b23cdf5900 100644 --- a/lib/stdlib/test/ets_SUITE.erl +++ b/lib/stdlib/test/ets_SUITE.erl @@ -4984,7 +4984,7 @@ tabfile_ext4(Config) when is_list(Config) -> {error,Y} = ets:file2tab(FName,[{verify,true}]), ets:tab2file(TL,FName,[{extended_info,[md5sum]}]), {X,Y} - end || N <- lists:seq(500,600)], + end || N <- lists:seq(700,800)], io:format("~p~n",[Res]), file:delete(FName) end), diff --git a/lib/stdlib/test/io_proto_SUITE.erl b/lib/stdlib/test/io_proto_SUITE.erl index e497b2fb5d..df6958cfa9 100644 --- a/lib/stdlib/test/io_proto_SUITE.erl +++ b/lib/stdlib/test/io_proto_SUITE.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2009-2017. All Rights Reserved. +%% Copyright Ericsson AB 2009-2019. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -1568,10 +1568,6 @@ request({put_chars, Encoding, Chars}, State) -> request({put_chars, Encoding, Module, Function, Args}, State) -> {ok, ok, State#state{q=[{put_chars, Encoding, Module, Function, Args} | State#state.q ]}}; -request({put_chars,Chars}, State) -> - {ok, ok, State#state{q=[{put_chars, Chars} | State#state.q ]}}; -request({put_chars,M,F,As}, State) -> - {ok, ok, State#state{q=[{put_chars, M,F,As} | State#state.q ]}}; request({get_until, Encoding, Prompt, M, F, As}, State) -> {ok, convert(State#state.nxt, Encoding, State#state.mode), State#state{nxt = eof, q = [{get_until, Encoding, Prompt, M, F, As} | State#state.q]}}; request({get_chars, Encoding, Prompt, N}, State) -> @@ -1583,20 +1579,6 @@ request({get_line, Encoding, Prompt}, State) -> State#state{nxt = eof, q = [{get_line, Encoding, Prompt} | State#state.q]}}; -request({get_until, Prompt, M, F, As}, State) -> - {ok, convert(State#state.nxt, latin1, State#state.mode), - State#state{nxt = eof, - q = [{get_until, Prompt, M, F, As} | State#state.q]}}; -request({get_chars, Prompt, N}, State) -> - {ok, convert(State#state.nxt, latin1, State#state.mode), - State#state{nxt = eof, - q = [{get_chars, Prompt, N} | - State#state.q]}}; -request({get_line, Prompt}, State) -> - {ok, convert(State#state.nxt, latin1, State#state.mode), - State#state{nxt = eof, - q = [{get_line, Prompt} | - State#state.q]}}; request({get_geomentry,_}, State) -> {error, {error,enotsup}, State}; request({setopts, Opts}, State) when Opts =:= [{binary, false}]; Opts =:= [list] -> diff --git a/lib/stdlib/test/ms_transform_SUITE.erl b/lib/stdlib/test/ms_transform_SUITE.erl index d1e6faf863..29423ed032 100644 --- a/lib/stdlib/test/ms_transform_SUITE.erl +++ b/lib/stdlib/test/ms_transform_SUITE.erl @@ -281,6 +281,8 @@ basic_ets(Config) when is_list(Config) -> compile_and_run(<<"ets:fun2ms(fun({A,B}) -> {B,A} end)">>), [{{'$1','$2'},[],[['$2','$1']]}] = compile_and_run(<<"ets:fun2ms(fun({A,B}) -> [B,A] end)">>), + [{{"foo" ++ '_','$1'},[],['$1']}] = + compile_and_run(<<"ets:fun2ms(fun({\"foo\" ++ _, X}) -> X end)">>), ok. %% Tests basic ets:fun2ms. @@ -313,6 +315,8 @@ from_shell(Config) when is_list(Config) -> [{[a,b],[],[{message,banan},{return_trace}]}] = do_eval( "dbg:fun2ms(fun([a,b]) -> message(banan), return_trace() end)"), + [{{"foo" ++ '_','$1'},[],['$1']}] = + do_eval("ets:fun2ms(fun({\"foo\" ++ _, X}) -> X end)"), ok. %% Tests expansion of records in fun2ms. diff --git a/lib/stdlib/test/shell_SUITE.erl b/lib/stdlib/test/shell_SUITE.erl index cdb6031b07..4d85e1f04b 100644 --- a/lib/stdlib/test/shell_SUITE.erl +++ b/lib/stdlib/test/shell_SUITE.erl @@ -3141,25 +3141,16 @@ io_request({get_geometry,columns}, S) -> {ok,80,S}; io_request({get_geometry,rows}, S) -> {ok,24,S}; -io_request({put_chars,Chars}, S) -> - {ok,ok,S#state{reply = [S#state.reply | Chars]}}; io_request({put_chars,latin1,Chars}, S) -> {ok,ok,S#state{reply = [S#state.reply | Chars]}}; io_request({put_chars,unicode,Chars0}, S) -> Chars = unicode:characters_to_list(Chars0), {ok,ok,S#state{reply = [S#state.reply | Chars]}}; -io_request({put_chars,Mod,Func,Args}, S) -> - case catch apply(Mod, Func, Args) of - Chars when is_list(Chars) -> - io_request({put_chars,Chars}, S) - end; io_request({put_chars,Enc,Mod,Func,Args}, S) -> case catch apply(Mod, Func, Args) of Chars when is_list(Chars) -> io_request({put_chars,Enc,Chars}, S) end; -io_request({get_until,_Prompt,Mod,Func,ExtraArgs}, S) -> - get_until(Mod, Func, ExtraArgs, S, latin1); io_request({get_until,Enc,_Prompt,Mod,Func,ExtraArgs}, S) -> get_until(Mod, Func, ExtraArgs, S, Enc). |