Browse Source

Add lua default path for distributed core lua scripts

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent
commit
2d57e56bdc
  1. 9
      doc/Makefile.am
  2. 3
      src/modules/Makefile.am
  3. 35
      src/modules/mod_lua.c

9
doc/Makefile.am

@ -1,9 +1,12 @@
dist_man8_MANS=lighttpd2.8 lighttpd2-worker.8
EXTRA_DIST=angel.conf lighttpd.conf mimetypes.conf service \
core__cached_html.lua \
default.html
# see src/modules/Makefile.am
luadir = $(datarootdir)/lighttpd2/lua
dist_lua_DATA = core__cached_html.lua \
core.lua \
core__xsendfile.lua \
secdownload.lua \
secdownload__secdownload.lua \
default.html
secdownload__secdownload.lua

3
src/modules/Makefile.am

@ -6,6 +6,8 @@ common_libs = $(GTHREAD_LIBS) $(LIBEV_LIBS) $(LUA_LIBS)
common_ldflags = -module -export-dynamic -avoid-version -no-undefined $(common_libs)
common_libadd = ../common/liblighttpd2-common.la ../main/liblighttpd2-shared.la
luadir = $(datarootdir)/lighttpd2/lua
AM_CPPFLAGS = $(common_cflags)
install_libs += libmod_access.la
@ -77,6 +79,7 @@ libmod_limit_la_LIBADD = $(common_libadd)
if USE_LUA
install_libs += libmod_lua.la
libmod_lua_la_CPPFLAGS = $(AM_CPPFLAGS) -DDEFAULT_LUADIR='"$(luadir)"'
libmod_lua_la_SOURCES = mod_lua.c
libmod_lua_la_LDFLAGS = $(common_ldflags)
libmod_lua_la_LIBADD = $(common_libadd)

35
src/modules/mod_lua.c

@ -43,6 +43,10 @@
#include <lualib.h>
#include <lauxlib.h>
#ifndef DEFAULT_LUADIR
#define DEFAULT_LUADIR "/usr/local/share/lighttpd2/lua"
#endif
LI_API gboolean mod_lua_init(liModules *mods, liModule *mod);
LI_API gboolean mod_lua_free(liModules *mods, liModule *mod);
@ -71,6 +75,32 @@ struct lua_config {
liPlugin *p;
};
static gboolean lua_find_file(GString *filename) {
gboolean res = TRUE;
struct stat st;
if (-1 == stat(filename->str, &st) || !S_ISREG(st.st_mode)) {
GString *tmp;
if (filename->str[0] == '/') return FALSE;
tmp = g_string_sized_new(0);
/* try DEFAULT_LUADIR */
li_string_assign_len(tmp, CONST_STR_LEN(DEFAULT_LUADIR "/"));
g_string_append_len(tmp, GSTR_LEN(filename));
if (-1 != stat(tmp->str, &st) && S_ISREG(st.st_mode)) {
li_string_assign_len(filename, GSTR_LEN(tmp));
} else {
res = FALSE;
}
g_string_free(tmp, TRUE);
}
return res;
}
static liHandlerResult lua_handle(liVRequest *vr, gpointer param, gpointer *context) {
lua_config *conf = (lua_config*) param;
lua_worker_config *wc;
@ -144,11 +174,14 @@ static void lua_config_free(liServer *srv, gpointer param) {
static lua_config* lua_config_new(liServer *srv, liPlugin *p, GString *filename, guint ttl, liValue *args) {
module_config *mc = p->data;
lua_config *conf = g_slice_new0(lua_config);
conf->filename = filename;
conf->ttl = ttl;
conf->p = p;
conf->args = args;
lua_find_file(filename);
if (LI_SERVER_INIT != g_atomic_int_get(&srv->state)) {
conf->worker_config = g_slice_alloc0(sizeof(lua_worker_config) * srv->worker_count);
} else {
@ -446,6 +479,8 @@ static gboolean lua_plugin_load(liServer *srv, liPlugin *p, GString *filename, l
li_lua_new_globals(L);
lua_find_file(filename);
if (0 != luaL_loadfile(L, filename->str)) {
ERROR(srv, "Loading lua plugin '%s' failed: %s", filename->str, lua_tostring(L, -1));
goto failed_unlock_lua;

Loading…
Cancel
Save