From b83c42d381b3b8aaf8f5a564b1abbeb48a17a01c Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 19 Mar 2013 14:28:39 +0100 Subject: [os_mon] Quote path to programs run with open_port({spawn,... This is to allow space in the path. --- lib/os_mon/src/nteventlog.erl | 6 +++--- lib/os_mon/src/os_sup.erl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/os_mon/src/nteventlog.erl b/lib/os_mon/src/nteventlog.erl index d624048c29..97eaf07179 100644 --- a/lib/os_mon/src/nteventlog.erl +++ b/lib/os_mon/src/nteventlog.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2009. All Rights Reserved. +%% Copyright Ericsson AB 1998-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -122,8 +122,8 @@ code_change(_OldVsn, State, _Extra) -> start_portprogram(Identifier) -> Command = - filename:join([code:priv_dir(os_mon),"bin","nteventlog.exe"]) ++ - " " ++ make_list(Identifier), + "\"" ++ filename:join([code:priv_dir(os_mon),"bin","nteventlog.exe"]) ++ + "\" " ++ make_list(Identifier), open_port({spawn,Command},[{packet,2}]). make_list(X) when is_atom(X) -> diff --git a/lib/os_mon/src/os_sup.erl b/lib/os_mon/src/os_sup.erl index f5c6c138ba..3ad8b6e990 100644 --- a/lib/os_mon/src/os_sup.erl +++ b/lib/os_mon/src/os_sup.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2009. All Rights Reserved. +%% Copyright Ericsson AB 1996-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -228,8 +228,8 @@ code_change(_OldVsn, State, _Extra) -> start_portprogram() -> OwnPath = os_mon:get_env(os_sup, os_sup_own), Command = - filename:join([code:priv_dir(os_mon), "bin", "ferrule"]) ++ - " " ++ OwnPath, + "\"" ++ filename:join([code:priv_dir(os_mon), "bin", "ferrule"]) ++ + "\" " ++ OwnPath, open_port({spawn, Command}, [{packet, 2}]). %% os:cmd(cmd_str(enable)) should be done BEFORE starting os_sup -- cgit v1.2.3 From 0841aaf3a09b4ddcf5ea52a6c781f5e11cf85227 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 19 Mar 2013 14:32:02 +0100 Subject: [sasl] Quote path to program run with open_port({spawn,... This is to allow space in the path. --- lib/sasl/src/erlsrv.erl | 6 +++--- lib/sasl/test/release_handler_SUITE.erl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sasl/src/erlsrv.erl b/lib/sasl/src/erlsrv.erl index 086dc7c651..58d43cda34 100644 --- a/lib/sasl/src/erlsrv.erl +++ b/lib/sasl/src/erlsrv.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1998-2011. All Rights Reserved. +%% Copyright Ericsson AB 1998-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -39,7 +39,7 @@ current_version() -> run_erlsrv(Command) -> run_erlsrv(current_version(),Command). run_erlsrv(EVer, Command) -> - case catch(open_port({spawn, erlsrv(EVer) ++ " " ++ Command}, + case catch(open_port({spawn, "\"" ++ erlsrv(EVer) ++ "\" " ++ Command}, [{line,1000}, in, eof])) of {'EXIT',{Reason,_}} -> {port_error, Reason}; @@ -53,7 +53,7 @@ run_erlsrv(EVer, Command) -> end. run_erlsrv_interactive(EVer, Commands) -> - case catch(open_port({spawn, erlsrv(EVer) ++ " readargs"}, + case catch(open_port({spawn, "\""++ erlsrv(EVer) ++ "\" readargs"}, [{line,1000}, eof])) of {'EXIT',{Reason,_}} -> {port_error, Reason}; diff --git a/lib/sasl/test/release_handler_SUITE.erl b/lib/sasl/test/release_handler_SUITE.erl index 97ba70c9bd..501220d3c6 100644 --- a/lib/sasl/test/release_handler_SUITE.erl +++ b/lib/sasl/test/release_handler_SUITE.erl @@ -2676,7 +2676,7 @@ rpc_inst(Node,Func,Args) -> delete_all_services() -> ErlSrv = erlsrv:erlsrv(erlang:system_info(version)), - [_|Serviceinfo] = string:tokens(os:cmd(ErlSrv ++ " list"),"\n"), + [_|Serviceinfo] = string:tokens(os:cmd("\"" ++ ErlSrv ++ "\" list"),"\n"), Services = [lists:takewhile(fun($\t) -> false; (_) -> true end,S) || S <- Serviceinfo], -- cgit v1.2.3 From 1e25a41af35e6dea65166bbc2d5f0c4c1433ffee Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 19 Mar 2013 14:41:43 +0100 Subject: Quote path to erl executable in slave to allow space in path --- lib/stdlib/src/slave.erl | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/stdlib/src/slave.erl b/lib/stdlib/src/slave.erl index 9c74041f56..3e647635bc 100644 --- a/lib/stdlib/src/slave.erl +++ b/lib/stdlib/src/slave.erl @@ -289,7 +289,8 @@ register_unique_name(Number) -> %% If the node should run on the local host, there is %% no need to use rsh. -mk_cmd(Host, Name, Args, Waiter, Prog) -> +mk_cmd(Host, Name, Args, Waiter, Prog0) -> + Prog = quote_progname(Prog0), BasicCmd = lists:concat([Prog, " -detached -noinput -master ", node(), " ", long_or_short(), Name, "@", Host, @@ -309,6 +310,31 @@ mk_cmd(Host, Name, Args, Waiter, Prog) -> end end. +%% This is an attempt to distinguish between spaces in the program +%% path and spaces that separate arguments. The program is quoted to +%% allow spaces in the path. +%% +%% Arguments could exist either if the executable is excplicitly given +%% (through start/5) or if the -program switch to beam is used and +%% includes arguments (typically done by cerl in OTP test environment +%% in order to ensure that slave/peer nodes are started with the same +%% emulator and flags as the test node. The return from lib:progname() +%% could then typically be '//cerl -gcov'). +quote_progname(Progname) -> + do_quote_progname(string:tokens(to_list(Progname)," ")). + +do_quote_progname([Prog]) -> + "\""++Prog++"\""; +do_quote_progname([Prog,Arg|Args]) -> + case os:find_executable(Prog) of + false -> + do_quote_progname([Prog++" "++Arg | Args]); + _ -> + %% this one has an executable - we assume the rest are arguments + "\""++Prog++"\""++ + lists:flatten(lists:map(fun(X) -> [" ",X] end, [Arg|Args])) + end. + %% Give the user an opportunity to run another program, %% than the "rsh". On HP-UX rsh is called remsh; thus HP users %% must start erlang as erl -rsh remsh. -- cgit v1.2.3 From 34ef3e83e67a7b137579a12ee0a8e2620bf9339b Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 19 Mar 2013 14:43:59 +0100 Subject: [test_server] Quote path to erl executable when starting slave nodes This is to allow space in path. --- lib/test_server/src/test_server_node.erl | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/test_server/src/test_server_node.erl b/lib/test_server/src/test_server_node.erl index 619fd463de..582abb2153 100644 --- a/lib/test_server/src/test_server_node.erl +++ b/lib/test_server/src/test_server_node.erl @@ -82,7 +82,7 @@ start_tracer_node(TraceFile,TI) -> Cookie = TI#target_info.cookie, {ok,LSock} = gen_tcp:listen(0,[binary,{reuseaddr,true},{packet,2}]), {ok,TracePort} = inet:port(LSock), - Prog = pick_erl_program(default), + Prog = quote_progname(pick_erl_program(default)), Cmd = lists:concat([Prog, " -sname tracer -hidden -setcookie ", Cookie, " -s ", ?MODULE, " trc ", TraceFile, " ", TracePort, " ", TI#target_info.os_family]), @@ -312,7 +312,7 @@ start_node_peer(SlaveName, OptList, From, TI) -> FailOnError = start_node_get_option_value(fail_on_error, OptList, true), Pa = TI#target_info.test_server_dir, Prog0 = start_node_get_option_value(erl, OptList, default), - Prog = pick_erl_program(Prog0), + Prog = quote_progname(pick_erl_program(Prog0)), Args = case string:str(SuppliedArgs,"-setcookie") of 0 -> "-setcookie " ++ TI#target_info.cookie ++ " " ++ SuppliedArgs; @@ -589,7 +589,32 @@ pick_erl_program(L) -> {release, S} -> find_release(S); this -> - lib:progname() + cast_to_list(lib:progname()) + end. + +%% This is an attempt to distinguish between spaces in the program +%% path and spaces that separate arguments. The program is quoted to +%% allow spaces in the path. +%% +%% Arguments could exist either if the executable is excplicitly given +%% ({prog,String}) or if the -program switch to beam is used and +%% includes arguments (typically done by cerl in OTP test environment +%% in order to ensure that slave/peer nodes are started with the same +%% emulator and flags as the test node. The return from lib:progname() +%% could then typically be '//cerl -gcov'). +quote_progname(Progname) -> + do_quote_progname(string:tokens(Progname," ")). + +do_quote_progname([Prog]) -> + "\""++Prog++"\""; +do_quote_progname([Prog,Arg|Args]) -> + case os:find_executable(Prog) of + false -> + do_quote_progname([Prog++" "++Arg | Args]); + _ -> + %% this one has an executable - we assume the rest are arguments + "\""++Prog++"\""++ + lists:flatten(lists:map(fun(X) -> [" ",X] end, [Arg|Args])) end. random_element(L) -> -- cgit v1.2.3 From dd850c00803939e44d7f2ea6659825d0ab861b9d Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Wed, 8 May 2013 11:36:34 +0200 Subject: [sasl] In test, quote erlsrv executable in call to open_port/2 --- lib/sasl/test/rh_test_lib.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sasl/test/rh_test_lib.erl b/lib/sasl/test/rh_test_lib.erl index 99a7f919a7..c9a425c729 100644 --- a/lib/sasl/test/rh_test_lib.erl +++ b/lib/sasl/test/rh_test_lib.erl @@ -13,7 +13,8 @@ erlsrv(Erlsrv,Action,Name) -> erlsrv(Erlsrv,Action,Name,""). erlsrv(Erlsrv,Action,Name,Rest) -> - Cmd = Erlsrv ++ " " ++ atom_to_list(Action) ++ " " ++ Name ++ " " ++ Rest, + Cmd = "\"" ++ Erlsrv ++ "\" " ++ atom_to_list(Action) ++ " " ++ + Name ++ " " ++ Rest, io:format("erlsrv cmd: ~p~n",[Cmd]), Port = open_port({spawn, Cmd}, [stream, {line, 100}, eof, in]), Res = recv_prog_output(Port), -- cgit v1.2.3