Skip to content

Commit

Permalink
Set ETS table heir, so ext_mod process inherits the table
Browse files Browse the repository at this point in the history
An ETS table is automatically destroyed when its parent process dies.
When mod_cron is installed using the module_install command,
the calling process dies immediately, and ETS table gets destroyed.

That problem didn't appear when the module is already installed
and configured when ejabberd starts: in that case the calling process
is ext_mod, which is always alive.
  • Loading branch information
badlop committed Jul 25, 2024
1 parent 1b533e3 commit b7c36ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mod_cron/src/mod_cron.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ start(Host, Opts) ->
ejabberd_hooks:add(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, web_page_host, 50),
Tasks = gen_mod:get_opt(tasks, Opts),
catch ets:new(cron_tasks, [ordered_set, named_table, public, {keypos, 2}]),
Heir = {heir, whereis(ext_mod), ?MODULE},
catch ets:new(cron_tasks, [ordered_set, named_table, public, {keypos, 2}, Heir]),
[add_task(Host, Task) || Task <- Tasks],
ok.

Expand Down
3 changes: 2 additions & 1 deletion mod_webpresence/src/mod_webpresence.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ start(Host, Opts) ->
PP ->
PP
end,
catch ets:new(pixmaps_dirs, [named_table, public]),
Heir = {heir, whereis(ext_mod), ?MODULE},
catch ets:new(pixmaps_dirs, [named_table, public, Heir]),
ets:insert(pixmaps_dirs, {directory, Dir}),
case gen_mod:start_child(?MODULE, Host, Opts) of
{ok, Ref} ->
Expand Down

0 comments on commit b7c36ca

Please sign in to comment.