BUG/MINOR: hlua: enforce proper running context for register_x functions

register_{init, converters, fetches, action, service, cli, filter} are
meant to run exclusively from body context according to the
documentation (unlike register_task which is designed to work from both
init and runtime contexts)

A quick code inspection confirms that only register_task implements
the required precautions to make it safe out of init context.

Trying to use those register_* functions from a runtime lua task will
lead to a program crash since they all assume that they are running from
the main lua context and with no concurrent runs:

    core.register_task(function()
      core.register_init(function()
      end)
    end)

When loaded from the config, the above example would segfault.

To prevent this undefined behavior, we now report an explicit error if
the user tries to use such functions outside of init/body context.

This should be backported in every stable versions.
[prior to 2.5 lua filter API did not exist, the hlua_register_filter()
part should be skipped]

(cherry picked from commit 87f52974ba9ae91479fb4ea01dee52ebc6536d1b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 625ed9ed70b994ee1fecaaa9a5c675106b1585d0)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 01ce298976e45d0f27a8617017b2cd7e8b5ff5b6)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 75fd34071e4c991bbb07bfc9019cc0207e8e04f9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
1 file changed