added --perl-exec and --perl-exec-post-fork

This commit is contained in:
Unbit
2013-08-23 11:50:18 +02:00
parent ce8dd001bf
commit 4f9e2ff3f6
3 changed files with 29 additions and 1 deletions
+5 -1
View File
@@ -1,5 +1,5 @@
#undef __USE_GNU
#include "../../uwsgi.h"
#include <uwsgi.h>
#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 *);
+17
View File
@@ -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);
}
+7
View File
@@ -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);
}