summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Gudmundsson <dgud@erlang.org>2023-01-12 16:46:40 +0100
committerDan Gudmundsson <dgud@erlang.org>2023-01-13 15:05:06 +0100
commit137d9f7e8231412181c2d646d17d552d8f6a1242 (patch)
tree0d4bfea027ec112bc3d8608b5a8bf052e254faca
parentd8612205d3319468f3c42d3071cace4f9b4a36ef (diff)
downloaderlang-137d9f7e8231412181c2d646d17d552d8f6a1242.tar.gz
Unlink port_command to avoid EXIT msgs
A {'EXIT', Port, normal} message is always sent after the port is closed. If the user traps exit signal it will end up in the msg queue. Unlink the port to avoid that. If the program doesn't not exist open_port will exit directly, so catch that to improve error handling, also redirect stderr_to_stdout to catch any error messages from the command. Update testcase to catch error on mac
-rw-r--r--lib/public_key/src/pubkey_os_cacerts.erl9
-rw-r--r--lib/public_key/test/public_key_SUITE.erl8
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/public_key/src/pubkey_os_cacerts.erl b/lib/public_key/src/pubkey_os_cacerts.erl
index 5d1d5ac4f1..61ded6d0cf 100644
--- a/lib/public_key/src/pubkey_os_cacerts.erl
+++ b/lib/public_key/src/pubkey_os_cacerts.erl
@@ -133,9 +133,12 @@ load_win32() ->
load_darwin() ->
%% Could/should probably be re-written to use Keychain Access API
KeyChainFile = "/System/Library/Keychains/SystemRootCertificates.keychain",
- case run_cmd("/usr/bin/security", ["export", "-t", "certs", "-f", "pemseq", "-k", KeyChainFile]) of
+ Args = ["export", "-t", "certs", "-f", "pemseq", "-k", KeyChainFile],
+ try run_cmd("/usr/bin/security", Args) of
{ok, Bin} -> decode_result(Bin);
Err -> Err
+ catch error:Reason ->
+ {error, {eopnotsupp, Reason}}
end.
store([]) ->
@@ -162,7 +165,9 @@ sunos_path() ->
"/etc/certs/CA/".
run_cmd(Cmd, Args) ->
- Port = open_port({spawn_executable, Cmd}, [{args, Args}, binary, exit_status]),
+ Opts = [binary, exit_status, stderr_to_stdout],
+ Port = open_port({spawn_executable, Cmd}, [{args, Args}|Opts]),
+ unlink(Port),
cmd_data(Port, <<>>).
cmd_data(Port, Acc) ->
diff --git a/lib/public_key/test/public_key_SUITE.erl b/lib/public_key/test/public_key_SUITE.erl
index 52274dbae5..b4de6f1926 100644
--- a/lib/public_key/test/public_key_SUITE.erl
+++ b/lib/public_key/test/public_key_SUITE.erl
@@ -1349,7 +1349,10 @@ cacerts_load(Config) ->
%% Re-Load default OS certs
try
+ process_flag(trap_exit, true),
+ flush(),
ok = public_key:cacerts_load(),
+ [] = flush(),
ct:log("~p: ~p~n", [os:type(), length(OsCerts)]),
OsCerts = public_key:cacerts_get(),
Ids = cert_info(OsCerts),
@@ -1367,6 +1370,11 @@ cacerts_load(Config) ->
ok
end.
+flush() ->
+ receive Msg -> [Msg|flush()]
+ after 500 -> []
+ end.
+
cert_info([#cert{der=Der, otp=#'OTPCertificate'{tbsCertificate = C0}=Cert}|Rest]) when is_binary(Der) ->
#'OTPTBSCertificate'{subject = Subject, serialNumber = _Nr, issuer = Issuer0} = C0,
C = case public_key:pkix_is_self_signed(Cert) of