File 7571-erts-Add-init-get_argument-bindir-and-use-it-for-ine.patch of Package erlang
From 3ec709a5b83b43602a4cd308cfb955c4bf7ea66f Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Fri, 1 Apr 2022 13:28:18 +0200
Subject: [PATCH 1/2] erts: Add init:get_argument(bindir) and use it for
inet_gethost
Closes #5826
---
erts/etc/common/erlexec.c | 2 ++
erts/preloaded/src/init.erl | 9 +++++++
lib/kernel/src/inet_gethost_native.erl | 34 ++++++--------------------
3 files changed, 19 insertions(+), 26 deletions(-)
diff --git a/erts/etc/common/erlexec.c b/erts/etc/common/erlexec.c
index 8dc9363af6..7c3c91224c 100644
--- a/erts/etc/common/erlexec.c
+++ b/erts/etc/common/erlexec.c
@@ -1080,6 +1080,8 @@ int main(int argc, char **argv)
add_Eargs("--");
add_Eargs("-root");
add_Eargs(rootdir);
+ add_Eargs("-bindir");
+ add_Eargs(bindir);
add_Eargs("-progname");
add_Eargs(progname);
add_Eargs("--");
diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl
index 4f64273f41..5ea349511d 100644
--- a/erts/preloaded/src/init.erl
+++ b/erts/preloaded/src/init.erl
@@ -889,6 +889,7 @@ do_boot(Flags,Start) ->
do_boot(Init,Flags,Start) ->
process_flag(trap_exit,true),
Root = get_root(Flags),
+ true = check_bindir(Flags),
Path = get_flag_list(path, Flags, false),
{Pa,Pz} = PathFls = path_flags(Flags),
start_prim_loader(Init, bs2ss(Path), PathFls),
@@ -923,6 +924,14 @@ get_root(Flags) ->
exit(no_or_multiple_root_variables)
end.
+check_bindir(Flags) ->
+ case get_argument(bindir, Flags) of
+ {ok,[[_Bindir]]} ->
+ true;
+ _ ->
+ exit(no_or_multiple_bindir_variables)
+ end.
+
get_boot_vars(Root, Flags) ->
BootVars = get_boot_vars_1(#{}, Flags),
RootKey = <<"ROOT">>,
diff --git a/lib/kernel/src/inet_gethost_native.erl b/lib/kernel/src/inet_gethost_native.erl
index 090f9b9ef9..328cb01e05 100644
--- a/lib/kernel/src/inet_gethost_native.erl
+++ b/lib/kernel/src/inet_gethost_native.erl
@@ -394,38 +394,20 @@ do_open_port(Poolsize, ExtraArgs) ->
Args = [integer_to_list(Poolsize)] ++ ExtraArgs,
%% open_executable/2 below assumes overlapped_io is at the head
Opts = [overlapped_io, {args, Args}, {packet,4}, eof, binary],
- RootDir = code:root_dir(),
- Prog = filename:join([RootDir, erts(), "bin", ?PORT_PROGRAM]),
- Cont =
- fun () ->
- [filename:join([RootDir, "bin", target(), ?PORT_PROGRAM])]
- end,
- open_executable([Prog|Cont], Opts).
-
-open_executable([Prog|Tail] = Progs, Opts) ->
+ {ok,[BinDir]} = init:get_argument(bindir),
+ Prog = filename:join(BinDir, ?PORT_PROGRAM),
+ open_executable(Prog, Opts).
+
+open_executable(Prog, Opts) ->
try open_port({spawn_executable, Prog}, Opts)
catch
error : badarg when hd(Opts) =:= overlapped_io ->
- open_executable(Progs, tl(Opts));
- error : enoent ->
- open_executable(Tail, Opts);
+ open_executable(Prog, tl(Opts));
error : Reason ->
erlang:halt(
"Can not execute "++Prog++" : "++term2string(Reason))
- end;
-open_executable([], _Opts) ->
- erlang:halt(
- "Can not find "++?PORT_PROGRAM++" for "++erts()++"/"++target());
-open_executable(Cont, Opts) ->
- open_executable(Cont(), Opts).
-%% We regard not being able to start the resolver helper program
-%% as a node fatal error to avoid getting weird malfunction
-%% of name lookups
-
-erts() ->
- "erts-"++erlang:system_info(version).
-target() ->
- erlang:system_info(system_architecture).
+ end.
+
term2string(Term) ->
unicode:characters_to_list(io_lib:format("~tw", [Term])).
--
2.34.1