2
0
Fork 0

[core] Add --module-resident commandline parameter to prevent module unloading. Useful for valgrind or tcmalloc

personal/stbuehler/wip
Thomas Porzelt 2010-05-06 22:42:47 +02:00
parent 46b9a28f87
commit 86e039e6d2
10 changed files with 22 additions and 13 deletions

View File

@ -72,7 +72,7 @@ struct liPlugins {
GPtrArray *plugins, *load_plugins; /* plugin* */
};
LI_API void li_plugins_init(liServer *srv, const gchar *module_dir);
LI_API void li_plugins_init(liServer *srv, const gchar *module_dir, gboolean module_resident);
LI_API void li_plugins_clear(liServer *srv);
LI_API void li_plugins_config_clean(liServer *srv);

View File

@ -63,7 +63,7 @@ struct liInstanceResource {
gpointer data;
};
LI_API liServer* li_server_new(const gchar *module_dir);
LI_API liServer* li_server_new(const gchar *module_dir, gboolean module_resident);
LI_API void li_server_free(liServer* srv);
LI_API void li_server_stop(liServer *srv);

View File

@ -46,11 +46,12 @@ struct liModules {
gpointer main; /**< pointer to a application specific main structure, e.g. server */
GArray *mods; /**< array of (module*) */
gchar *module_dir;
gboolean module_resident; /** if true, call g_module_make_resident() when loading a module */
guint8 sizeof_off_t; /** holds the value of sizeof(off_t) to check if loaded module was compiled with the same flags */
};
LI_API liModules* li_modules_new(gpointer main, const gchar *module_dir);
LI_API liModules* li_modules_new(gpointer main, const gchar *module_dir, gboolean make_resident);
LI_API void li_modules_free(liModules *mods);
/** Loads a module if not loaded yet and returns the module struct for it (after increasing refcount)

View File

@ -129,7 +129,7 @@ struct liServer {
};
LI_API liServer* li_server_new(const gchar *module_dir);
LI_API liServer* li_server_new(const gchar *module_dir, gboolean module_resident);
LI_API void li_server_free(liServer* srv);
LI_API gboolean li_server_loop_init(liServer *srv);

View File

@ -26,6 +26,7 @@ int main(int argc, char *argv[]) {
gboolean show_version = FALSE, no_fork = FALSE;
gchar const *const def_module_dir = DEFAULT_LIBDIR;
gchar const *module_dir = def_module_dir;
gboolean module_resident = FALSE;
gchar const *config_path = NULL, *pidfile = NULL;
gboolean res;
@ -35,6 +36,7 @@ int main(int argc, char *argv[]) {
GOptionEntry entries[] = {
{ "config", 'c', 0, G_OPTION_ARG_FILENAME, &config_path, "filename/path of the config", "PATH" },
{ "module-dir", 'm', 0, G_OPTION_ARG_STRING, &module_dir, "module directory [default: " DEFAULT_LIBDIR "]", "PATH" },
{ "module-resident", 0, 0, G_OPTION_ARG_NONE, &module_resident, "never unload modules (e.g. for valgrind)", NULL },
{ "no-daemon", 'n', 0, G_OPTION_ARG_NONE, &no_fork, "Don't fork (for daemontools)", NULL },
{ "pid-file", 0, 0, G_OPTION_ARG_STRING, &pidfile, "Location of the pid file (only valid in daemon mode)", "PATH" },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, "show version and exit", NULL },
@ -76,7 +78,7 @@ int main(int argc, char *argv[]) {
/* initialize threading */
g_thread_init(NULL);
srv = li_server_new(module_dir);
srv = li_server_new(module_dir, module_resident);
if (!li_plugins_config_load(srv, config_path)) {
result = -1;

View File

@ -80,10 +80,10 @@ static server_module* server_module_new(liServer *srv, const gchar *name) { /* m
return sm;
}
void li_plugins_init(liServer *srv, const gchar *module_dir) {
void li_plugins_init(liServer *srv, const gchar *module_dir, gboolean module_resident) {
liPlugins *ps = &srv->plugins;
ps->modules = li_modules_new(srv, module_dir);
ps->modules = li_modules_new(srv, module_dir, module_resident);
ps->items = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, _server_item_free);
ps->load_items = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, _server_item_free);

View File

@ -25,7 +25,7 @@ static void sigpipe_cb(struct ev_loop *loop, struct ev_signal *w, int revents) {
UNUSED(loop); UNUSED(w); UNUSED(revents);
}
liServer* li_server_new(const gchar *module_dir) {
liServer* li_server_new(const gchar *module_dir, gboolean module_resident) {
liServer *srv = g_slice_new0(liServer);
srv->loop = ev_default_loop(0);
@ -35,7 +35,7 @@ liServer* li_server_new(const gchar *module_dir) {
CATCH_SIGNAL(srv->loop, sigpipe_cb, PIPE);
li_log_init(srv);
li_plugins_init(srv, module_dir);
li_plugins_init(srv, module_dir, module_resident);
return srv;
}

View File

@ -1,13 +1,14 @@
#include <lighttpd/module.h>
liModules *li_modules_new(gpointer main, const gchar *module_dir) {
liModules *li_modules_new(gpointer main, const gchar *module_dir, gboolean module_resident) {
liModules *m = g_slice_new(liModules);
m->version = MODULE_VERSION;
m->main = main;
m->mods = g_array_new(FALSE, TRUE, sizeof(liModule*));
m->module_dir = g_strdup(module_dir);
m->module_resident = module_resident;
m->sizeof_off_t = sizeof(off_t);
return m;
@ -101,6 +102,9 @@ liModule* li_module_load(liModules *mods, const gchar* name) {
return NULL;
}
if (mods->module_resident)
g_module_make_resident(mod->module);
/* insert into free slot */
for (i = 0; i < mods->mods->len; i++) {
if (!g_array_index(mods->mods, liModule*, i))

View File

@ -27,6 +27,7 @@ int main(int argc, char *argv[]) {
gchar *config_path = NULL;
const gchar *def_module_dir = DEFAULT_LIBDIR;
const gchar *module_dir = def_module_dir;
gboolean module_resident = FALSE;
gboolean luaconfig = FALSE;
gboolean test_config = FALSE;
gboolean show_version = FALSE;
@ -37,6 +38,7 @@ int main(int argc, char *argv[]) {
{ "lua", 'l', 0, G_OPTION_ARG_NONE, &luaconfig, "use the lua config frontend", NULL },
{ "test", 't', 0, G_OPTION_ARG_NONE, &test_config, "test config and exit", NULL },
{ "module-dir", 'm', 0, G_OPTION_ARG_STRING, &module_dir, "module directory [default: " DEFAULT_LIBDIR "]", "PATH" },
{ "module-resident", 0, 0, G_OPTION_ARG_NONE, &module_resident, "never unload modules (e.g. for valgrind)", NULL },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, "show version and exit", NULL },
{ "angel", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &use_angel, "spawned by angel", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
@ -79,7 +81,7 @@ int main(int argc, char *argv[]) {
/* initialize threading */
g_thread_init(NULL);
srv = li_server_new(module_dir);
srv = li_server_new(module_dir, module_resident);
li_server_loop_init(srv);
/* load core plugin */

View File

@ -88,7 +88,7 @@ static void sigpipe_cb(struct ev_loop *loop, struct ev_signal *w, int revents) {
UNUSED(loop); UNUSED(w); UNUSED(revents);
}
liServer* li_server_new(const gchar *module_dir) {
liServer* li_server_new(const gchar *module_dir, gboolean module_resident) {
liServer* srv = g_slice_new0(liServer);
srv->magic = LIGHTTPD_SERVER_MAGIC;
@ -116,7 +116,7 @@ liServer* li_server_new(const gchar *module_dir) {
srv->sockets = g_ptr_array_new();
srv->modules = li_modules_new(srv, module_dir);
srv->modules = li_modules_new(srv, module_dir, module_resident);
srv->plugins = g_hash_table_new(g_str_hash, g_str_equal);
srv->options = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, server_option_free);