?revision_form?Rev ?revision_input??revision_submit??revision_endform?
Rev 88 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
--- /dev/null
+++ b/shared/dlopen_templates.c
@@ -0,0 +1,51 @@
+#include <dlfcn.h>
+#include "shared.h"
+
+struct template_map_index *template_map_index = 0;
+
+void
+dlopen_templates(struct config *config, const char *suffix, struct pool *pool)
+{
+ if (config->template_list && !template_map_index) {
+ struct list_item *li;
+ struct template_map_index *tmi;
+
+ template_map_index = tmi = pool_alloc
+ (pool,
+ (config->template_list->length+1)
+ * sizeof(struct template_map_index));
+
+ for (li = config->template_list->head; li; li = li->next) {
+ char *filename = pool_printf(NIL, "/usr/lib/prayer/templates/%s%s.so",
+ li->name, suffix);
+ char *map_symbol = pool_printf(NIL, "template_map_%s",
+ li->name);
+ char *count_symbol = pool_printf(NIL, "template_map_%s_count",
+ li->name);
+
+ tmi->name = pool_strdup(pool, li->name);
+ if (!(tmi->handle = dlopen(filename, RTLD_NOW))
+ || !(tmi->template_map = dlsym(tmi->handle, map_symbol))
+ || !(tmi->count = dlsym(tmi->handle, count_symbol))) {
+ log_fatal("Failed to load template library: \"%s\": %s",
+ filename, dlerror());
+ }
+ log_debug("Loaded library %s with %d templates", filename, *tmi->count);
+ free(filename);
+ tmi++;
+ }
+ *tmi = (struct template_map_index){0};
+ }
+}
+
+void
+dlopen_templates_close()
+{
+ if (template_map_index) {
+ struct template_map_index *tmi = &template_map_index[0];
+
+ while (tmi->name) {
+ dlclose(tmi->handle);
+ }
+ }
+}
--- /dev/null
+++ b/shared/dlopen_templates.h
@@ -0,0 +1,2 @@
+void dlopen_templates(struct config *config, const char *suffix, struct pool *pool);
+void dlopen_templates_close();
--- a/templates/cam/Makefile
+++ b/templates/cam/Makefile
@@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS)
TYPE=cam
-TARGETS=templates.a templates_frontend.a
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
T_FILES_FRONTEND=login.t login_hermes.t \
frontend_login_error.t frontend_security.t frontend_session.t \
@@ -111,6 +111,12 @@ templates.a: $(O_FILES)
rm -f templates.a
ar q templates.a $(O_FILES)
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND)
+
+$(TYPE).so: $(O_FILES)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES)
+
%.o: %.c Makefile
$(CC) $(CFLAGS) -I../../lib -c $<
@@ -129,8 +135,12 @@ install:
cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
+ $(BROOT)$(LIB_PREFIX)/templates
+ cp *.so $(BROOT)$(LIB_PREFIX)/templates/
+
clean:
- rm -f $(TARGETS) *.html *.o *.c \#*\# *~
+ rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~
include Makefile.deps
--- a/templates/old/Makefile
+++ b/templates/old/Makefile
@@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS)
TYPE=old
-TARGETS=templates.a templates_frontend.a
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
T_FILES_FRONTEND=login.t \
frontend_login_error.t frontend_security.t frontend_session.t \
@@ -110,6 +110,12 @@ templates.a: $(O_FILES)
rm -f templates.a
ar q templates.a $(O_FILES)
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND)
+
+$(TYPE).so: $(O_FILES)
+ $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES)
+
%.o: %.c Makefile
$(CC) $(CFLAGS) -I../../lib -c $<
@@ -128,8 +134,12 @@ install:
cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
+ $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
+ $(BROOT)$(LIB_PREFIX)/templates
+ cp *.so $(BROOT)$(LIB_PREFIX)/templates/
+
clean:
- rm -f $(TARGETS) *.html *.o *.c \#*\# *~
+ rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~
include Makefile.deps
--- a/servers/prayer_chroot.c
+++ b/servers/prayer_chroot.c
@@ -327,6 +327,8 @@ int main(int argc, char *argv[])
config_extract_ssl(config, &ssl_config);
iostream_init(&ssl_config);
+ dlopen_templates(config, "_frontend", prayer->pool);
+
prayer_main_write_pid(config);
if (want_prefork && !want_foreground)
--- a/servers/session_main.c
+++ b/servers/session_main.c
@@ -187,6 +187,8 @@ int main(int argc, char *argv[])
if (config->tmp_dir)
chdir(config->tmp_dir);
+ dlopen_templates(config, "", config->pool);
+
session_main_write_pid(config);
session_server(config, want_foreground);
--- a/shared/Makefile
+++ b/shared/Makefile
@@ -33,7 +33,7 @@ MYCFLAGS = $(BASECFLAGS)
SHARED_OBJS = \
config.o gzip.o html_common.o log.o \
- request.o response.o user_agent.o
+ request.o response.o user_agent.o dlopen_templates.o
all: $(SHARED_OBJS)
--- a/servers/prayer_main.c
+++ b/servers/prayer_main.c
@@ -328,6 +328,8 @@ int main(int argc, char *argv[])
config_extract_ssl(config, &ssl_config);
iostream_init(&ssl_config);
+ dlopen_templates(config, "_frontend", prayer->pool);
+
if (config->prayer_background && !want_foreground) {
pid_t pid = fork();
--- a/lib/template.h
+++ b/lib/template.h
@@ -22,6 +22,7 @@ struct template_map_index {
char *name;
struct template_map *template_map;
unsigned long *count;
+ void *handle;
};
struct template_map {
--- a/servers/prayer_shared.h
+++ b/servers/prayer_shared.h
@@ -44,3 +44,4 @@ extern int errno; /* just
#include "mymutex.h"
#include "log.h"
#include "utf8.h"
+#include "dlopen_templates.h"
--- a/shared/shared.h
+++ b/shared/shared.h
@@ -40,3 +40,4 @@ extern int errno; /* just
#include "setproctitle.h"
#include "mymutex.h"
#include "log.h"
+#include "dlopen_templates.h"
--- a/servers/Makefile
+++ b/servers/Makefile
@@ -73,7 +73,7 @@ ifeq ($(strip $(CCLIENT_KERB_ENABLE)), t
endif
MYCFLAGS = $(BASECFLAGS) $(SERVER_SSL_INCLUDE) $(CCLIENT_INCLUDE)
-MYLDFLAGS = $(BASELDFLAGS)
+MYLDFLAGS = $(BASELDFLAGS) -ldl
TEMPLATES= ../templates/index.o \
../templates/old/templates.a \
@@ -84,15 +84,13 @@ TEMPLATES_FRONTEND= ../templates/index.o
../templates/cam/templates_frontend.a
PRAYER_OBJS= prayer.o prayer_login.o prayer_server.o portlist.o \
- ../shared/shared.a $(LIB) $(TEMPLATES_FRONTEND)
+ ../shared/shared.a $(LIB)
SESSION_OBJS= \
session_config.o session_exchange.o session_unix.o session_server.o \
session_main.o portlist.o ../cmd/cmd.a ../session/session.a \
../shared/shared.a ../lib/lib_nossl.a
-SESSION_OBJS += $(TEMPLATES)
-
#########################################################################
all: $(BIN)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ install-cert:
install:
$(MAKE) -C files install
$(MAKE) -C man install
-# $(MAKE) -C templates install
+ $(MAKE) -C templates install
$(MAKE) -C servers install
$(MAKE) -C utils install
ifeq ($(strip $(ACCOUNTD_ENABLE)), true)
--- a/lib/template.c
+++ b/lib/template.c
@@ -190,12 +190,12 @@ template_getexpr(char **sp, struct pool
/* ====================================================================== */
-extern struct template_map_index template_map_index[];
+extern struct template_map_index *template_map_index;
struct template *
template_find(char *set, char *name, struct pool *pool)
{
- struct template_map_index *tmi = &template_map_index[0];
+ struct template_map_index *tmi = template_map_index;
struct template_map *tm;
unsigned long count;
unsigned long first, last, middle;