From 13f82176e38893ebd4d9770a264fe8498e894e02 Mon Sep 17 00:00:00 2001 From: Unbit Date: Sun, 11 Aug 2013 10:22:36 +0200 Subject: [PATCH] added init_func support for plugins, and --need-plugin variant --- core/plugins.c | 12 ++++++++++++ core/uwsgi.c | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/core/plugins.c b/core/plugins.c index 6ce44623..d3964f1d 100644 --- a/core/plugins.c +++ b/core/plugins.c @@ -98,6 +98,12 @@ void *uwsgi_load_plugin(int modifier, char *plugin, char *has_option) { colon[0] = ':'; } + char *init_func = strchr(plugin_name, '|'); + if (init_func) { + init_func[0] = 0; + init_func++; + } + if (!uwsgi_endswith(plugin_name, "_plugin.so")) { plugin_name = uwsgi_concat2(plugin_name, "_plugin.so"); need_free = 1; @@ -157,6 +163,12 @@ success: uwsgi_log("!!! UNABLE to load uWSGI plugin: %s !!!\n", dlerror()); } else { + if (init_func) { + void (*plugin_init_func)() = dlsym(plugin_handle, init_func); + if (plugin_init_func) { + plugin_init_func(); + } + } char *plugin_entry_symbol = uwsgi_concat2n(plugin_symbol_name_start, strlen(plugin_symbol_name_start) - 3, "", 0); up = dlsym(plugin_handle, plugin_entry_symbol); if (!up) { diff --git a/core/uwsgi.c b/core/uwsgi.c index 122e23a7..7d03e576 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -702,6 +702,8 @@ static struct uwsgi_option uwsgi_base_options[] = { {"daemons-honour-stdin", no_argument, 0, "do not change the stdin of external daemons to /dev/null", uwsgi_opt_true, &uwsgi.daemons_honour_stdin, UWSGI_OPT_MASTER}, {"plugins", required_argument, 0, "load uWSGI plugins", uwsgi_opt_load_plugin, NULL, UWSGI_OPT_IMMEDIATE}, {"plugin", required_argument, 0, "load uWSGI plugins", uwsgi_opt_load_plugin, NULL, UWSGI_OPT_IMMEDIATE}, + {"need-plugins", required_argument, 0, "load uWSGI plugins (exit on error)", uwsgi_opt_load_plugin, NULL, UWSGI_OPT_IMMEDIATE}, + {"need-plugin", required_argument, 0, "load uWSGI plugins (exit on error)", uwsgi_opt_load_plugin, NULL, UWSGI_OPT_IMMEDIATE}, {"plugins-dir", required_argument, 0, "add a directory to uWSGI plugin search path", uwsgi_opt_add_string_list, &uwsgi.plugins_dir, UWSGI_OPT_IMMEDIATE}, {"plugin-dir", required_argument, 0, "add a directory to uWSGI plugin search path", uwsgi_opt_add_string_list, &uwsgi.plugins_dir, UWSGI_OPT_IMMEDIATE}, {"plugins-list", no_argument, 0, "list enabled plugins", uwsgi_opt_true, &uwsgi.plugins_list, 0}, @@ -3728,6 +3730,10 @@ void uwsgi_opt_load_plugin(char *opt, char *value, void *none) { if (uwsgi_load_plugin(-1, p, NULL)) { build_options(); } + else if (!uwsgi_startswith(opt, "need-", 5)) { + uwsgi_log("unable to load plugin \"%s\"\n", p); + exit(1); + } p = strtok(NULL, ","); } free(p);