Rev 88 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 87 | magnus | 1 | --- /dev/null |
| 2 | +++ b/shared/dlopen_templates.c |
||
| 3 | @@ -0,0 +1,51 @@ |
||
| 4 | +#include <dlfcn.h> |
||
| 5 | +#include "shared.h" |
||
| 6 | + |
||
| 7 | +struct template_map_index *template_map_index = 0; |
||
| 8 | + |
||
| 9 | +void |
||
| 10 | +dlopen_templates(struct config *config, const char *suffix, struct pool *pool) |
||
| 11 | +{ |
||
| 12 | + if (config->template_list && !template_map_index) { |
||
| 13 | + struct list_item *li; |
||
| 14 | + struct template_map_index *tmi; |
||
| 15 | + |
||
| 16 | + template_map_index = tmi = pool_alloc |
||
| 17 | + (pool, |
||
| 18 | + (config->template_list->length+1) |
||
| 19 | + * sizeof(struct template_map_index)); |
||
| 20 | + |
||
| 21 | + for (li = config->template_list->head; li; li = li->next) { |
||
| 22 | + char *filename = pool_printf(NIL, "/usr/lib/prayer/templates/%s%s.so", |
||
| 23 | + li->name, suffix); |
||
| 24 | + char *map_symbol = pool_printf(NIL, "template_map_%s", |
||
| 25 | + li->name); |
||
| 26 | + char *count_symbol = pool_printf(NIL, "template_map_%s_count", |
||
| 27 | + li->name); |
||
| 28 | + |
||
| 29 | + tmi->name = pool_strdup(pool, li->name); |
||
| 30 | + if (!(tmi->handle = dlopen(filename, RTLD_NOW)) |
||
| 31 | + || !(tmi->template_map = dlsym(tmi->handle, map_symbol)) |
||
| 32 | + || !(tmi->count = dlsym(tmi->handle, count_symbol))) { |
||
| 33 | + log_fatal("Failed to load template library: \"%s\": %s", |
||
| 34 | + filename, dlerror()); |
||
| 35 | + } |
||
| 36 | + log_debug("Loaded library %s with %d templates", filename, *tmi->count); |
||
| 37 | + free(filename); |
||
| 38 | + tmi++; |
||
| 39 | + } |
||
| 40 | + *tmi = (struct template_map_index){0}; |
||
| 41 | + } |
||
| 42 | +} |
||
| 43 | + |
||
| 44 | +void |
||
| 45 | +dlopen_templates_close() |
||
| 46 | +{ |
||
| 47 | + if (template_map_index) { |
||
| 48 | + struct template_map_index *tmi = &template_map_index[0]; |
||
| 49 | + |
||
| 50 | + while (tmi->name) { |
||
| 51 | + dlclose(tmi->handle); |
||
| 52 | + } |
||
| 53 | + } |
||
| 54 | +} |
||
| 55 | --- /dev/null |
||
| 56 | +++ b/shared/dlopen_templates.h |
||
| 57 | @@ -0,0 +1,2 @@ |
||
| 58 | +void dlopen_templates(struct config *config, const char *suffix, struct pool *pool); |
||
| 59 | +void dlopen_templates_close(); |
||
| 60 | --- a/templates/cam/Makefile |
||
| 61 | +++ b/templates/cam/Makefile |
||
| 62 | @@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS) |
||
| 63 | |||
| 64 | TYPE=cam |
||
| 65 | |||
| 66 | -TARGETS=templates.a templates_frontend.a |
||
| 67 | +TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so |
||
| 68 | |||
| 69 | T_FILES_FRONTEND=login.t login_hermes.t \ |
||
| 70 | frontend_login_error.t frontend_security.t frontend_session.t \ |
||
| 71 | @@ -111,6 +111,12 @@ templates.a: $(O_FILES) |
||
| 72 | rm -f templates.a |
||
| 73 | ar q templates.a $(O_FILES) |
||
| 74 | |||
| 75 | +$(TYPE)_frontend.so: $(O_FILES_FRONTEND) |
||
| 76 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND) |
||
| 77 | + |
||
| 78 | +$(TYPE).so: $(O_FILES) |
||
| 79 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES) |
||
| 80 | + |
||
| 81 | %.o: %.c Makefile |
||
| 82 | $(CC) $(CFLAGS) -I../../lib -c $< |
||
| 83 | |||
| 84 | @@ -129,8 +135,12 @@ install: |
||
| 85 | cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
| 86 | cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
| 87 | |||
| 88 | + $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \ |
||
| 89 | + $(BROOT)$(LIB_PREFIX)/templates |
||
| 90 | + cp *.so $(BROOT)$(LIB_PREFIX)/templates/ |
||
| 91 | + |
||
| 92 | clean: |
||
| 93 | - rm -f $(TARGETS) *.html *.o *.c \#*\# *~ |
||
| 94 | + rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~ |
||
| 95 | |||
| 96 | include Makefile.deps |
||
| 97 | |||
| 98 | --- a/templates/old/Makefile |
||
| 99 | +++ b/templates/old/Makefile |
||
| 100 | @@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS) |
||
| 101 | |||
| 102 | TYPE=old |
||
| 103 | |||
| 104 | -TARGETS=templates.a templates_frontend.a |
||
| 105 | +TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so |
||
| 106 | |||
| 107 | T_FILES_FRONTEND=login.t \ |
||
| 108 | frontend_login_error.t frontend_security.t frontend_session.t \ |
||
| 109 | @@ -110,6 +110,12 @@ templates.a: $(O_FILES) |
||
| 110 | rm -f templates.a |
||
| 111 | ar q templates.a $(O_FILES) |
||
| 112 | |||
| 113 | +$(TYPE)_frontend.so: $(O_FILES_FRONTEND) |
||
| 114 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND) |
||
| 115 | + |
||
| 116 | +$(TYPE).so: $(O_FILES) |
||
| 117 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES) |
||
| 118 | + |
||
| 119 | %.o: %.c Makefile |
||
| 120 | $(CC) $(CFLAGS) -I../../lib -c $< |
||
| 121 | |||
| 122 | @@ -128,8 +134,12 @@ install: |
||
| 123 | cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
| 124 | cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
| 125 | |||
| 126 | + $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \ |
||
| 127 | + $(BROOT)$(LIB_PREFIX)/templates |
||
| 128 | + cp *.so $(BROOT)$(LIB_PREFIX)/templates/ |
||
| 129 | + |
||
| 130 | clean: |
||
| 131 | - rm -f $(TARGETS) *.html *.o *.c \#*\# *~ |
||
| 132 | + rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~ |
||
| 133 | |||
| 134 | include Makefile.deps |
||
| 135 | |||
| 136 | --- a/servers/prayer_chroot.c |
||
| 137 | +++ b/servers/prayer_chroot.c |
||
| 138 | @@ -327,6 +327,8 @@ int main(int argc, char *argv[]) |
||
| 139 | config_extract_ssl(config, &ssl_config); |
||
| 140 | iostream_init(&ssl_config); |
||
| 141 | |||
| 142 | + dlopen_templates(config, "_frontend", prayer->pool); |
||
| 143 | + |
||
| 144 | prayer_main_write_pid(config); |
||
| 145 | |||
| 146 | if (want_prefork && !want_foreground) |
||
| 147 | --- a/servers/session_main.c |
||
| 148 | +++ b/servers/session_main.c |
||
| 149 | @@ -187,6 +187,8 @@ int main(int argc, char *argv[]) |
||
| 150 | if (config->tmp_dir) |
||
| 151 | chdir(config->tmp_dir); |
||
| 152 | |||
| 153 | + dlopen_templates(config, "", config->pool); |
||
| 154 | + |
||
| 155 | session_main_write_pid(config); |
||
| 156 | |||
| 157 | session_server(config, want_foreground); |
||
| 158 | --- a/shared/Makefile |
||
| 159 | +++ b/shared/Makefile |
||
| 160 | @@ -33,7 +33,7 @@ MYCFLAGS = $(BASECFLAGS) |
||
| 161 | |||
| 162 | SHARED_OBJS = \ |
||
| 163 | config.o gzip.o html_common.o log.o \ |
||
| 164 | - request.o response.o user_agent.o |
||
| 165 | + request.o response.o user_agent.o dlopen_templates.o |
||
| 166 | |||
| 167 | |||
| 168 | all: $(SHARED_OBJS) |
||
| 169 | --- a/servers/prayer_main.c |
||
| 170 | +++ b/servers/prayer_main.c |
||
| 171 | @@ -328,6 +328,8 @@ int main(int argc, char *argv[]) |
||
| 172 | config_extract_ssl(config, &ssl_config); |
||
| 173 | iostream_init(&ssl_config); |
||
| 174 | |||
| 175 | + dlopen_templates(config, "_frontend", prayer->pool); |
||
| 176 | + |
||
| 177 | if (config->prayer_background && !want_foreground) { |
||
| 178 | pid_t pid = fork(); |
||
| 179 | |||
| 180 | --- a/lib/template.h |
||
| 181 | +++ b/lib/template.h |
||
| 182 | @@ -22,6 +22,7 @@ struct template_map_index { |
||
| 183 | char *name; |
||
| 184 | struct template_map *template_map; |
||
| 185 | unsigned long *count; |
||
| 186 | + void *handle; |
||
| 187 | }; |
||
| 188 | |||
| 189 | struct template_map { |
||
| 190 | --- a/servers/prayer_shared.h |
||
| 191 | +++ b/servers/prayer_shared.h |
||
| 192 | @@ -44,3 +44,4 @@ extern int errno; /* just |
||
| 193 | #include "mymutex.h" |
||
| 194 | #include "log.h" |
||
| 195 | #include "utf8.h" |
||
| 196 | +#include "dlopen_templates.h" |
||
| 197 | --- a/shared/shared.h |
||
| 198 | +++ b/shared/shared.h |
||
| 199 | @@ -40,3 +40,4 @@ extern int errno; /* just |
||
| 200 | #include "setproctitle.h" |
||
| 201 | #include "mymutex.h" |
||
| 202 | #include "log.h" |
||
| 203 | +#include "dlopen_templates.h" |
||
| 204 | --- a/servers/Makefile |
||
| 205 | +++ b/servers/Makefile |
||
| 206 | @@ -73,7 +73,7 @@ ifeq ($(strip $(CCLIENT_KERB_ENABLE)), t |
||
| 207 | endif |
||
| 208 | |||
| 209 | MYCFLAGS = $(BASECFLAGS) $(SERVER_SSL_INCLUDE) $(CCLIENT_INCLUDE) |
||
| 210 | -MYLDFLAGS = $(BASELDFLAGS) |
||
| 211 | +MYLDFLAGS = $(BASELDFLAGS) -ldl |
||
| 212 | |||
| 213 | TEMPLATES= ../templates/index.o \ |
||
| 214 | ../templates/old/templates.a \ |
||
| 215 | @@ -84,15 +84,13 @@ TEMPLATES_FRONTEND= ../templates/index.o |
||
| 216 | ../templates/cam/templates_frontend.a |
||
| 217 | |||
| 218 | PRAYER_OBJS= prayer.o prayer_login.o prayer_server.o portlist.o \ |
||
| 219 | - ../shared/shared.a $(LIB) $(TEMPLATES_FRONTEND) |
||
| 220 | + ../shared/shared.a $(LIB) |
||
| 221 | |||
| 222 | SESSION_OBJS= \ |
||
| 223 | session_config.o session_exchange.o session_unix.o session_server.o \ |
||
| 224 | session_main.o portlist.o ../cmd/cmd.a ../session/session.a \ |
||
| 225 | ../shared/shared.a ../lib/lib_nossl.a |
||
| 226 | |||
| 227 | -SESSION_OBJS += $(TEMPLATES) |
||
| 228 | - |
||
| 229 | ######################################################################### |
||
| 230 | |||
| 231 | all: $(BIN) |
||
| 232 | --- a/Makefile |
||
| 233 | +++ b/Makefile |
||
| 234 | @@ -28,7 +28,7 @@ install-cert: |
||
| 235 | install: |
||
| 236 | $(MAKE) -C files install |
||
| 237 | $(MAKE) -C man install |
||
| 238 | -# $(MAKE) -C templates install |
||
| 239 | + $(MAKE) -C templates install |
||
| 240 | $(MAKE) -C servers install |
||
| 241 | $(MAKE) -C utils install |
||
| 242 | ifeq ($(strip $(ACCOUNTD_ENABLE)), true) |
||
| 243 | --- a/lib/template.c |
||
| 244 | +++ b/lib/template.c |
||
| 245 | @@ -190,12 +190,12 @@ template_getexpr(char **sp, struct pool |
||
| 246 | |||
| 247 | /* ====================================================================== */ |
||
| 248 | |||
| 249 | -extern struct template_map_index template_map_index[]; |
||
| 250 | +extern struct template_map_index *template_map_index; |
||
| 251 | |||
| 252 | struct template * |
||
| 253 | template_find(char *set, char *name, struct pool *pool) |
||
| 254 | { |
||
| 255 | - struct template_map_index *tmi = &template_map_index[0]; |
||
| 256 | + struct template_map_index *tmi = template_map_index; |
||
| 257 | struct template_map *tm; |
||
| 258 | unsigned long count; |
||
| 259 | unsigned long first, last, middle; |