File 1052-erlexec-Improve-error-message-when-unable-to-open-in.patch of Package erlang
From 50e8166131da4de6e469c7565a4f925b9c2374c1 Mon Sep 17 00:00:00 2001
From: Luis Rascao <luis.rascao@miniclip.com>
Date: Thu, 29 Oct 2020 09:23:12 +0000
Subject: [PATCH] erlexec: Improve error message when unable to open included
args_file
By specifying `-args_file` in a supplied `vm.args` it is possible to
extend the VM options, the path supplied is relative to the current
working directory. Improve the error message when unable to open such
a file to ease the process.
---
erts/etc/common/erlexec.c | 12 +++++++++++-
erts/test/erlexec_SUITE.erl | 32 ++++++++++++++++++++++++++++----
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c
index 028c3a6789..6a8f393b76 100644
--- a/erts/etc/common/erlexec.c
+++ b/erts/etc/common/erlexec.c
@@ -1879,8 +1879,18 @@ read_args_file(char *filename)
file = fopen(filename, "r");
} while (!file && errno == EINTR);
if (!file) {
- usage_format("Failed to open arguments file \"%s\": %s\n",
+#ifdef __WIN32__
+ char cwd[MAX_PATH];
+ if (_getcwd(cwd, sizeof(cwd)) == NULL) {
+#else
+ char cwd[PATH_MAX];
+ if (getcwd(cwd, sizeof(cwd)) == NULL) {
+#endif
+ cwd[0] = '\0';
+ }
+ usage_format("Failed to open arguments file \"%s\" at \"%s\": %s\n",
filename,
+ cwd,
errno_string());
}
diff --git a/erts/test/erlexec_SUITE.erl b/erts/test/erlexec_SUITE.erl
index c210c5479b..5794f7e309 100644
--- a/erts/test/erlexec_SUITE.erl
+++ b/erts/test/erlexec_SUITE.erl
@@ -29,7 +29,7 @@
-export([all/0, suite/0, init_per_testcase/2, end_per_testcase/2]).
--export([args_file/1, evil_args_file/1, env/1, args_file_env/1,
+-export([args_file/1, evil_args_file/1, missing_args_file/1, env/1, args_file_env/1,
otp_7461/1, otp_7461_remote/1, otp_8209/1,
zdbbl_dist_buf_busy_limit/1]).
@@ -50,7 +50,7 @@ suite() ->
{timetrap, {minutes, 1}}].
all() ->
- [args_file, evil_args_file, env, args_file_env,
+ [args_file, evil_args_file, missing_args_file, env, args_file_env,
otp_7461, otp_8209, zdbbl_dist_buf_busy_limit].
%% Test that plain first argument does not
@@ -204,8 +204,23 @@ evil_args_file(Config) when is_list(Config) ->
ANums),
Misc),
ok.
-
-
+
+missing_args_file(Config) when is_list(Config) ->
+ % supply an unexisting args file as parameter
+ CmdLine = "-args_file "++ "missing_vm_args_file",
+ % we're expecting a failure, capture the output
+ % and check for the correct error message
+ Output = emu_args(CmdLine, [return_output]),
+ % the output message format in case of failure can be consulted
+ % at read_args_file@erts/etc/common/erlexec.c
+ case re:run(Output, "Failed to open arguments file [^ ]+ at [^ ]+: No such file or directory.*") of
+ {match,[{0, MatchEnd}]} when MatchEnd > 0 ->
+ % a simple match on the regex is sufficient to decide
+ % that the output is properly formatted
+ ok;
+ Error ->
+ exit({unexpected_args_output, Output, Error})
+ end.
env(Config) when is_list(Config) ->
os:putenv("ERL_AFLAGS", "-MiscArg1 +#100 -extra +XtraArg1 +XtraArg2"),
@@ -396,11 +411,19 @@ verify_not_args(Xs, Ys) ->
end, Xs).
emu_args(CmdLineArgs) ->
- io:format("CmdLineArgs = ~ts~n", [CmdLineArgs]),
+ emu_args(CmdLineArgs, []).
+
+emu_args(CmdLineArgs, Opts) ->
+ io:format("CmdLineArgs = ~ts, Opts = ~p~n", [CmdLineArgs, Opts]),
{ok,[[Erl]]} = init:get_argument(progname),
EmuCL = os:cmd(Erl ++ " -emu_args_exit " ++ CmdLineArgs),
io:format("EmuCL = ~ts", [EmuCL]),
- split_emu_clt(string:tokens(EmuCL, [$ ,$\t,$\n,$\r])).
+ case lists:member(return_output, Opts) of
+ true ->
+ EmuCL;
+ false ->
+ split_emu_clt(string:tokens(EmuCL, [$ ,$\t,$\n,$\r]))
+ end.
split_emu_clt(EmuCLT) ->
split_emu_clt(EmuCLT, [], [], [], emu).
--
2.26.2