Permalink
Browse files

Ensure the C port is stopped on terminate

  • Loading branch information...
1 parent d8cb906 commit f0c59d6ab7937a4fec316b2abd35807f8316f4b1 @msantos committed Apr 11, 2012
Showing with 4 additions and 5 deletions.
  1. +4 −5 src/epcap.erl
View
@@ -60,6 +60,7 @@ start_link(Pid, Options) ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [Pid, Options], []).
init([Pid, Options]) ->
+ process_flag(trap_exit, true),
Chroot = chroot_path(),
Cmd = make_args(Options ++ [{chroot, Chroot}]),
Port = open_port({spawn, Cmd}, [{packet, 2}, binary, exit_status]),
@@ -76,11 +77,9 @@ handle_cast(_Msg, State) ->
{noreply, State}.
terminate(_Reason, #state{port = Port}) ->
- try erlang:port_close(Port) of
- true -> ok
- catch
- _:_ -> ok
- end.
+ catch erlang:port_close(Port),
+ ok.
+
code_change(_OldVsn, State, _Extra) ->
{ok, State}.

0 comments on commit f0c59d6

Please sign in to comment.