Rev 88 | Rev 92 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
90 | magnus | 1 | Experimental support for dynamically loading templates. Low-level template handling is unchanged; |
2 | main programs call dlopen_templates() at appropriate times. If template set has changed, the old |
||
3 | one is unloaded first. |
||
87 | magnus | 4 | --- /dev/null |
5 | +++ b/shared/dlopen_templates.c |
||
88 | magnus | 6 | @@ -0,0 +1,40 @@ |
87 | magnus | 7 | +#include <dlfcn.h> |
8 | +#include "shared.h" |
||
9 | + |
||
88 | magnus | 10 | +struct template_map_index template_map_index[] = { |
11 | + {NIL, NIL, NIL}, |
||
12 | + {NIL, NIL, NIL} |
||
13 | +}; |
||
87 | magnus | 14 | + |
88 | magnus | 15 | +struct template_map_index * |
16 | +dlopen_templates(const char *set, const char *suffix) |
||
87 | magnus | 17 | +{ |
88 | magnus | 18 | + struct template_map_index *tmi = &template_map_index[0]; |
19 | + static void *handle = 0; |
||
87 | magnus | 20 | + |
88 | magnus | 21 | + if (!handle || strcmp(tmi->name, set)) { |
22 | + char *filename = pool_printf(NIL, "/usr/lib/prayer/templates/%s%s.so", |
||
23 | + set, suffix); |
||
24 | + char *map_symbol = pool_printf(NIL, "template_map_%s", |
||
25 | + set); |
||
26 | + char *count_symbol = pool_printf(NIL, "template_map_%s_count", |
||
27 | + set); |
||
87 | magnus | 28 | + |
88 | magnus | 29 | + if (handle) { |
30 | + dlclose(handle); |
||
31 | + free(tmi->name); |
||
87 | magnus | 32 | + } |
88 | magnus | 33 | + tmi->name = pool_strdup(NIL, set); |
34 | + if (!(handle = dlopen(filename, RTLD_NOW)) |
||
35 | + || !(tmi->template_map = dlsym(handle, map_symbol)) |
||
36 | + || !(tmi->count = dlsym(handle, count_symbol))) { |
||
37 | + log_fatal("Failed to load template library: \"%s\": %s", |
||
38 | + filename, dlerror()); |
||
87 | magnus | 39 | + } |
88 | magnus | 40 | + log_debug("Loaded library %s with %d templates", filename, *tmi->count); |
41 | + free(filename); |
||
42 | + free(map_symbol); |
||
43 | + free(count_symbol); |
||
87 | magnus | 44 | + } |
88 | magnus | 45 | + return tmi; |
87 | magnus | 46 | +} |
47 | --- /dev/null |
||
48 | +++ b/shared/dlopen_templates.h |
||
88 | magnus | 49 | @@ -0,0 +1 @@ |
50 | +struct template_map_index *dlopen_templates(const char *set, const char *suffix); |
||
87 | magnus | 51 | --- a/templates/cam/Makefile |
52 | +++ b/templates/cam/Makefile |
||
53 | @@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS) |
||
54 | |||
55 | TYPE=cam |
||
56 | |||
57 | -TARGETS=templates.a templates_frontend.a |
||
58 | +TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so |
||
59 | |||
60 | T_FILES_FRONTEND=login.t login_hermes.t \ |
||
61 | frontend_login_error.t frontend_security.t frontend_session.t \ |
||
62 | @@ -111,6 +111,12 @@ templates.a: $(O_FILES) |
||
63 | rm -f templates.a |
||
64 | ar q templates.a $(O_FILES) |
||
65 | |||
66 | +$(TYPE)_frontend.so: $(O_FILES_FRONTEND) |
||
67 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND) |
||
68 | + |
||
69 | +$(TYPE).so: $(O_FILES) |
||
70 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES) |
||
71 | + |
||
72 | %.o: %.c Makefile |
||
73 | $(CC) $(CFLAGS) -I../../lib -c $< |
||
74 | |||
75 | @@ -129,8 +135,12 @@ install: |
||
76 | cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
77 | cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
78 | |||
79 | + $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \ |
||
80 | + $(BROOT)$(LIB_PREFIX)/templates |
||
81 | + cp *.so $(BROOT)$(LIB_PREFIX)/templates/ |
||
82 | + |
||
83 | clean: |
||
84 | - rm -f $(TARGETS) *.html *.o *.c \#*\# *~ |
||
85 | + rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~ |
||
86 | |||
87 | include Makefile.deps |
||
88 | |||
89 | --- a/templates/old/Makefile |
||
90 | +++ b/templates/old/Makefile |
||
91 | @@ -11,7 +11,7 @@ LDFLAGS = $(BASELDFLAGS) |
||
92 | |||
93 | TYPE=old |
||
94 | |||
95 | -TARGETS=templates.a templates_frontend.a |
||
96 | +TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so |
||
97 | |||
98 | T_FILES_FRONTEND=login.t \ |
||
99 | frontend_login_error.t frontend_security.t frontend_session.t \ |
||
100 | @@ -110,6 +110,12 @@ templates.a: $(O_FILES) |
||
101 | rm -f templates.a |
||
102 | ar q templates.a $(O_FILES) |
||
103 | |||
104 | +$(TYPE)_frontend.so: $(O_FILES_FRONTEND) |
||
105 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES_FRONTEND) |
||
106 | + |
||
107 | +$(TYPE).so: $(O_FILES) |
||
108 | + $(CC) $(LDFLAGS) -ldl -shared -o $@ $(O_FILES) |
||
109 | + |
||
110 | %.o: %.c Makefile |
||
111 | $(CC) $(CFLAGS) -I../../lib -c $< |
||
112 | |||
113 | @@ -128,8 +134,12 @@ install: |
||
114 | cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
115 | cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE) |
||
116 | |||
117 | + $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \ |
||
118 | + $(BROOT)$(LIB_PREFIX)/templates |
||
119 | + cp *.so $(BROOT)$(LIB_PREFIX)/templates/ |
||
120 | + |
||
121 | clean: |
||
122 | - rm -f $(TARGETS) *.html *.o *.c \#*\# *~ |
||
123 | + rm -f $(TARGETS) *.html *.o *.so *.c \#*\# *~ |
||
124 | |||
125 | include Makefile.deps |
||
126 | |||
127 | --- a/servers/prayer_chroot.c |
||
128 | +++ b/servers/prayer_chroot.c |
||
129 | @@ -327,6 +327,8 @@ int main(int argc, char *argv[]) |
||
130 | config_extract_ssl(config, &ssl_config); |
||
131 | iostream_init(&ssl_config); |
||
132 | |||
88 | magnus | 133 | + dlopen_templates(config->template_set, "_frontend"); |
87 | magnus | 134 | + |
135 | prayer_main_write_pid(config); |
||
136 | |||
137 | if (want_prefork && !want_foreground) |
||
138 | --- a/shared/Makefile |
||
139 | +++ b/shared/Makefile |
||
140 | @@ -33,7 +33,7 @@ MYCFLAGS = $(BASECFLAGS) |
||
141 | |||
142 | SHARED_OBJS = \ |
||
143 | config.o gzip.o html_common.o log.o \ |
||
144 | - request.o response.o user_agent.o |
||
145 | + request.o response.o user_agent.o dlopen_templates.o |
||
146 | |||
147 | |||
148 | all: $(SHARED_OBJS) |
||
149 | --- a/servers/prayer_main.c |
||
150 | +++ b/servers/prayer_main.c |
||
88 | magnus | 151 | @@ -350,6 +350,8 @@ int main(int argc, char *argv[]) |
152 | open("/dev/null", O_WRONLY); /* Reopen stderr */ |
||
153 | } |
||
87 | magnus | 154 | |
88 | magnus | 155 | + dlopen_templates(config->template_set, "_frontend"); |
87 | magnus | 156 | + |
88 | magnus | 157 | prayer_main_write_pid(config); |
87 | magnus | 158 | |
88 | magnus | 159 | if (want_prefork && !want_foreground) |
87 | magnus | 160 | --- a/shared/shared.h |
161 | +++ b/shared/shared.h |
||
162 | @@ -40,3 +40,4 @@ extern int errno; /* just |
||
163 | #include "setproctitle.h" |
||
164 | #include "mymutex.h" |
||
165 | #include "log.h" |
||
166 | +#include "dlopen_templates.h" |
||
167 | --- a/servers/Makefile |
||
168 | +++ b/servers/Makefile |
||
169 | @@ -73,7 +73,7 @@ ifeq ($(strip $(CCLIENT_KERB_ENABLE)), t |
||
170 | endif |
||
171 | |||
172 | MYCFLAGS = $(BASECFLAGS) $(SERVER_SSL_INCLUDE) $(CCLIENT_INCLUDE) |
||
173 | -MYLDFLAGS = $(BASELDFLAGS) |
||
174 | +MYLDFLAGS = $(BASELDFLAGS) -ldl |
||
175 | |||
176 | TEMPLATES= ../templates/index.o \ |
||
177 | ../templates/old/templates.a \ |
||
178 | @@ -84,15 +84,13 @@ TEMPLATES_FRONTEND= ../templates/index.o |
||
179 | ../templates/cam/templates_frontend.a |
||
180 | |||
181 | PRAYER_OBJS= prayer.o prayer_login.o prayer_server.o portlist.o \ |
||
182 | - ../shared/shared.a $(LIB) $(TEMPLATES_FRONTEND) |
||
183 | + ../shared/shared.a $(LIB) |
||
184 | |||
185 | SESSION_OBJS= \ |
||
186 | session_config.o session_exchange.o session_unix.o session_server.o \ |
||
187 | session_main.o portlist.o ../cmd/cmd.a ../session/session.a \ |
||
188 | ../shared/shared.a ../lib/lib_nossl.a |
||
189 | |||
190 | -SESSION_OBJS += $(TEMPLATES) |
||
191 | - |
||
192 | ######################################################################### |
||
193 | |||
194 | all: $(BIN) |
||
195 | --- a/Makefile |
||
196 | +++ b/Makefile |
||
197 | @@ -28,7 +28,7 @@ install-cert: |
||
198 | install: |
||
199 | $(MAKE) -C files install |
||
200 | $(MAKE) -C man install |
||
201 | -# $(MAKE) -C templates install |
||
202 | + $(MAKE) -C templates install |
||
203 | $(MAKE) -C servers install |
||
204 | $(MAKE) -C utils install |
||
205 | ifeq ($(strip $(ACCOUNTD_ENABLE)), true) |
||
88 | magnus | 206 | --- a/servers/session_exchange.c |
207 | +++ b/servers/session_exchange.c |
||
208 | @@ -212,6 +212,8 @@ BOOL session_exchange(struct session * s |
||
209 | else |
||
210 | template_set = config->template_set; /* Safe default */ |
||
87 | magnus | 211 | |
88 | magnus | 212 | + dlopen_templates(template_set, ""); |
213 | + |
||
214 | /* Set up template_vars ready for dispatch */ |
||
215 | session->template_vals = tvals |
||
216 | = template_vals_create(request->pool, |