application:start(crypto)

Claes Wikstrom <>
Tue Jan 31 15:33:53 CET 2006


I was writing code that checks that crypto application
is properly started. There exists a number of reasons for
crypto to fail to start - one common is that the version of
libcrypto.so on the box is < 0.9.7.

Thus:

Eshell V5.4.10  (abort with ^G)
1> application:start(crypto).


returns 'ok' even when libcrypto.so is bad or even nonexistant.
A huge error report is written, but the return value from
application:start() is 'ok'.

This patch remedies this:



[]src > svn diff -rPREV crypto_server.erl
Index: crypto_server.erl
===================================================================
--- crypto_server.erl   (revision 1258)
+++ crypto_server.erl   (working copy)
@@ -35,6 +35,7 @@
  start_link() ->
      gen_server:start_link({local, crypto_server}, crypto_server, [], []).

+
  init([]) ->
      process_flag(trap_exit, true),
      erl_ddll:start(),
@@ -43,9 +44,17 @@
      erl_ddll:load_driver(LibDir, crypto_drv),
      Cmd = "crypto_drv elibcrypto " ++ filename:join([LibDir, "elibcrypto"]),
      Port = open_port({spawn, Cmd}, []),
-    T = ets:new(crypto_server_table, [set, protected, named_table]),
-    ets:insert(T, {port, Port}),
-    {ok, {Port, []}}.
+    %% check that driver is loaded, linked and working
+    %% since crypto_drv links towards libcrypto, this is a good thing
+    %% since libcrypto is known to be bad with backwards compatibility
+    case catch port_control(Port, 0, []) of
+       {'EXIT', _} ->
+           {stop, nodriver};
+       _ ->
+           T = ets:new(crypto_server_table, [set, protected, named_table]),
+           ets:insert(T, {port, Port}),
+           {ok, {Port, []}}
+    end.

  %%% --------------------------------------------------------
  %%% The call-back functions.



/klacke

-- 
Claes Wikstrom                        -- Caps lock is nowhere and
http://www.tail-f.com                 -- everything is under control
cellphone: +46 70 2097763



More information about the erlang-questions mailing list