diff --git a/buildconf/default.ini b/buildconf/default.ini index fc9a0b76..4a2ac8b7 100644 --- a/buildconf/default.ini +++ b/buildconf/default.ini @@ -34,6 +34,8 @@ event = auto timer = auto filemonitor = auto +embed_files = + embed_config = [python] diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index e2fcdbfe..c97297c0 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -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) { diff --git a/utils.c b/utils.c index 99769429..56ee5801 100644 --- a/utils.c +++ b/utils.c @@ -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); diff --git a/uwsgi.c b/uwsgi.c index fa449e41..29b929b6 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -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 diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 4f8e8988..2a189f9d 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -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), @@ -445,6 +448,11 @@ class uConf(object): 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)