Skip to content

Commit

Permalink
added embed_files
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@natty32 committed Jul 10, 2011
1 parent 615348c commit b87e7c0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions buildconf/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ event = auto
timer = auto
filemonitor = auto

embed_files =

embed_config =

[python]
Expand Down
2 changes: 1 addition & 1 deletion plugins/python/python_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ PyObject *uwsgi_pyimport_by_filename(char *name, char *filename) {
char *real_filename = filename;


if (strncmp(filename, "http://", 7)) {
if (strncmp(filename, "http://", 7) && strncmp(filename, "sym://", 6)) {

pyfile = fopen(filename, "r");
if (!pyfile) {
Expand Down
25 changes: 25 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,31 @@ char *uwsgi_open_and_read(char *url, int *size, int add_zero, char *magic_table[
memcpy(buffer, &UWSGI_EMBED_CONFIG, &UWSGI_EMBED_CONFIG_END-&UWSGI_EMBED_CONFIG);
}
#endif
else if (!strncmp("sym://", url, 6)) {
char *symbol = uwsgi_concat3("_binary_", url+6, "_start") ;
void *sym_start_ptr = dlsym(RTLD_DEFAULT, symbol);
if (!sym_start_ptr) {
uwsgi_log("unable to find symbol %s\n", symbol);
exit(1);
}
free(symbol);
symbol = uwsgi_concat3("_binary_", url+6, "_end");
void *sym_end_ptr = dlsym(RTLD_DEFAULT, symbol);
if (!sym_end_ptr) {
uwsgi_log("unable to find symbol %s\n", symbol);
exit(1);
}
free(symbol);

*size = sym_end_ptr - sym_start_ptr;
if (add_zero) {
*size+=1;
}
buffer = uwsgi_malloc(*size);
memset(buffer, 0, *size);
memcpy(buffer, sym_start_ptr, sym_end_ptr - sym_start_ptr);

}
// fallback to file
else {
fd = open(url, O_RDONLY);
Expand Down
1 change: 0 additions & 1 deletion uwsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,6 @@ int main(int argc, char *argv[], char *envp[]) {
magic_table['v'] = uwsgi.cwd;
magic_table['h'] = uwsgi.hostname;


#ifdef UWSGI_EMBED_CONFIG
uwsgi_ini_config("", magic_table);
#endif
Expand Down
8 changes: 8 additions & 0 deletions uwsgiconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def build_uwsgi(uc):

if uc.get('embed_config'):
gcc_list.append(uc.get('embed_config'))
if uc.get('embed_files'):
for ef in uc.get('embed_files').split(','):
gcc_list.append(ef)

print("*** uWSGI linking ***")
ldline = "%s -o %s %s %s %s" % (GCC, bin_name, ' '.join(ldflags),
Expand Down Expand Up @@ -445,6 +448,11 @@ def get_gcll(self):
os.system(binary_link_cmd)
self.cflags.append("-DUWSGI_EMBED_CONFIG=_binary_%s_start" % self.get('embed_config').replace('.','_'))
self.cflags.append("-DUWSGI_EMBED_CONFIG_END=_binary_%s_end" % self.get('embed_config').replace('.','_'))
if self.get('embed_files'):
for ef in self.get('embed_files').split(','):
binary_link_cmd = "ld -r -b binary -o %s.o %s" % (ef, ef)
print(binary_link_cmd)
os.system(binary_link_cmd)



Expand Down

0 comments on commit b87e7c0

Please sign in to comment.