From 4f9e2ff3f68d4de2cd5ffc4503fde01f4f08860d Mon Sep 17 00:00:00 2001 From: Unbit Date: Fri, 23 Aug 2013 11:50:18 +0200 Subject: [PATCH] added --perl-exec and --perl-exec-post-fork --- plugins/psgi/psgi.h | 6 +++++- plugins/psgi/psgi_loader.c | 17 +++++++++++++++++ plugins/psgi/psgi_plugin.c | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/psgi/psgi.h b/plugins/psgi/psgi.h index 093747ba..9da90a5b 100644 --- a/plugins/psgi/psgi.h +++ b/plugins/psgi/psgi.h @@ -1,5 +1,5 @@ #undef __USE_GNU -#include "../../uwsgi.h" +#include #ifdef __APPLE__ #define HAS_BOOL 1 @@ -50,6 +50,9 @@ struct uwsgi_perl { SV *atexit; int loaded; + + struct uwsgi_string_list *exec; + struct uwsgi_string_list *exec_post_fork; }; void init_perl_embedded_module(void); @@ -66,3 +69,4 @@ int init_psgi_app(struct wsgi_request *, char *, uint16_t, PerlInterpreter **); PerlInterpreter *uwsgi_perl_new_interpreter(void); int uwsgi_perl_mule(char *); void uwsgi_perl_run_hook(SV *); +void uwsgi_perl_exec(char *); diff --git a/plugins/psgi/psgi_loader.c b/plugins/psgi/psgi_loader.c index 3192bad5..57b64573 100644 --- a/plugins/psgi/psgi_loader.c +++ b/plugins/psgi/psgi_loader.c @@ -483,6 +483,16 @@ void uwsgi_psgi_app() { //load app in the main interpreter list init_psgi_app(NULL, uperl.psgi, strlen(uperl.psgi), uperl.main); } + // create a perl environment (if needed) + else if (uperl.exec) { + PERL_SET_CONTEXT(uperl.main[0]); + perl_parse(uperl.main[0], xs_init, 2, uperl.embedding, NULL); + } + + struct uwsgi_string_list *usl; + uwsgi_foreach(usl, uperl.exec) { + uwsgi_perl_exec(usl->value); + } } @@ -502,3 +512,10 @@ int uwsgi_perl_mule(char *opt) { } + +void uwsgi_perl_exec(char *filename) { + size_t size = 0; + char *buf = uwsgi_open_and_read(filename, &size, 1, NULL); + perl_eval_pv(buf, 0); + free(buf); +} diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index 987ada01..915da55d 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -21,6 +21,8 @@ struct uwsgi_option uwsgi_perl_options[] = { #endif {"perl-args", required_argument, 0, "add items (space separated) to @ARGV", uwsgi_opt_set_str, &uperl.argv_items, 0}, {"perl-arg", required_argument, 0, "add an item to @ARGV", uwsgi_opt_add_string_list, &uperl.argv_item, 0}, + {"perl-exec", required_argument, 0, "exec the specified perl file before fork()", uwsgi_opt_add_string_list, &uperl.exec, 0}, + {"perl-exec-post-fork", required_argument, 0, "exec the specified perl file after fork()", uwsgi_opt_add_string_list, &uperl.exec_post_fork, 0}, {0, 0, 0, 0, 0, 0, 0}, }; @@ -588,6 +590,11 @@ void uwsgi_perl_post_fork() { SvREADONLY_on(GvSV(tmpgv)); } + struct uwsgi_string_list *usl; + uwsgi_foreach(usl, uperl.exec_post_fork) { + uwsgi_perl_exec(usl->value); + } + if (uperl.postfork) { uwsgi_perl_run_hook(uperl.postfork); }