From dd63bef92e7e07510c71bf4450f453f89091c7cd Mon Sep 17 00:00:00 2001 From: Unbit Date: Sat, 23 Feb 2013 13:28:51 +0100 Subject: [PATCH] backported --perl-arg and --perl-args --- plugins/psgi/psgi.h | 3 +++ plugins/psgi/psgi_loader.c | 17 +++++++++++++++++ plugins/psgi/psgi_plugin.c | 2 ++ 3 files changed, 22 insertions(+) diff --git a/plugins/psgi/psgi.h b/plugins/psgi/psgi.h index 4b80a09d..7d0b4407 100644 --- a/plugins/psgi/psgi.h +++ b/plugins/psgi/psgi.h @@ -23,6 +23,9 @@ struct uwsgi_perl { int no_die_catch; int stacktrace_available; + char *argv_items; + struct uwsgi_string_list *argv_item; + // this is a pointer to the main list of interpreters (required for signals, rpc....); PerlInterpreter **main; diff --git a/plugins/psgi/psgi_loader.c b/plugins/psgi/psgi_loader.c index 369d806b..dcd3c77d 100644 --- a/plugins/psgi/psgi_loader.c +++ b/plugins/psgi/psgi_loader.c @@ -413,6 +413,23 @@ int init_psgi_app(struct wsgi_request *wsgi_req, char *app, uint16_t app_len, Pe } } + if (uperl.argv_items || uperl.argv_item) { + AV *uperl_argv = GvAV(PL_argvgv); + if (uperl.argv_items) { + char *argv_list = uwsgi_str(uperl.argv_items); + char *p = strtok(argv_list, " "); + while(p) { + av_push(uperl_argv, newSVpv(p, 0)); + p = strtok(NULL, " "); + } + } + struct uwsgi_string_list *usl = uperl.argv_item; + while(usl) { + av_push(uperl_argv, newSVpv(usl->value, usl->len)); + usl = usl->next; + } + } + SV *dollar_zero = get_sv("0", GV_ADD); sv_setsv(dollar_zero, newSVpv(app, app_len)); diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index 89156a5d..23b1bad3 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -19,6 +19,8 @@ struct uwsgi_option uwsgi_perl_options[] = { #ifdef PERL_VERSION_STRING {"perl-version", no_argument, 0, "print perl version", uwsgi_opt_print, PERL_VERSION_STRING, UWSGI_OPT_IMMEDIATE}, #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}, {0, 0, 0, 0, 0, 0, 0}, };