From 114d71af8df3976ab2f0634e2f47e6da65d5fb9f Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Fri, 16 Nov 2012 19:57:54 +0000 Subject: [PATCH] implemented register_signal in the psgi plugin --- plugins/psgi/psgi_plugin.c | 28 ++++++++++++++++++++++++++++ plugins/psgi/uwsgi_plmodule.c | 24 ++++++++++++++++++++++++ test.psgi | 11 +++++++++++ 3 files changed, 63 insertions(+) diff --git a/plugins/psgi/psgi_plugin.c b/plugins/psgi/psgi_plugin.c index 3d057a5e..d71d9d2d 100644 --- a/plugins/psgi/psgi_plugin.c +++ b/plugins/psgi/psgi_plugin.c @@ -595,6 +595,33 @@ void uwsgi_perl_enable_threads(void) { #endif } +int uwsgi_perl_signal_handler(uint8_t sig, void *handler) { + + int ret = 0; + + dSP; + ENTER; + SAVETMPS; + PUSHMARK(SP); + XPUSHs( sv_2mortal(newSViv(sig))); + PUTBACK; + + call_sv( SvRV((SV*)handler), G_DISCARD); + + if(SvTRUE(ERRSV)) { + uwsgi_log("[uwsgi-perl error] %s\n", SvPV_nolen(ERRSV)); + ret = -1; + } + + SPAGAIN; + PUTBACK; + FREETMPS; + LEAVE; + + return ret; +} + + struct uwsgi_plugin psgi_plugin = { .name = "psgi", @@ -606,6 +633,7 @@ struct uwsgi_plugin psgi_plugin = { .mount_app = uwsgi_perl_mount_app, .init_thread = uwsgi_perl_init_thread, + .signal_handler = uwsgi_perl_signal_handler, .post_fork = uwsgi_perl_post_fork, .request = uwsgi_perl_request, diff --git a/plugins/psgi/uwsgi_plmodule.c b/plugins/psgi/uwsgi_plmodule.c index c1b3eba8..b567d86f 100644 --- a/plugins/psgi/uwsgi_plmodule.c +++ b/plugins/psgi/uwsgi_plmodule.c @@ -1,6 +1,7 @@ #include "psgi.h" extern struct uwsgi_server uwsgi; +extern struct uwsgi_plugin psgi_plugin; #ifdef UWSGI_ASYNC @@ -149,6 +150,27 @@ clear: } +XS(XS_register_signal) { + dXSARGS; + + if (!uwsgi.master_process) { + XSRETURN_NO; + } + + psgi_check_args(3); + + uint8_t signum = SvIV(ST(0)); + STRLEN kindlen; + char *kind = SvPV(ST(1), kindlen); + + if (uwsgi_register_signal(signum, kind, (void *) newRV_inc(ST(2)), psgi_plugin.modifier1)) { + XSRETURN_NO; + } + + XSRETURN_YES; + +} + XS(XS_log) { dXSARGS; @@ -219,6 +241,7 @@ XS(XS_suspend) { XSRETURN_UNDEF; } + void init_perl_embedded_module() { psgi_xs(reload); psgi_xs(cache_set); @@ -231,5 +254,6 @@ void init_perl_embedded_module() { psgi_xs(async_connect); psgi_xs(suspend); psgi_xs(signal); + psgi_xs(register_signal); } diff --git a/test.psgi b/test.psgi index 318ade7c..fdc58d84 100644 --- a/test.psgi +++ b/test.psgi @@ -19,6 +19,14 @@ my $two = sub { print "two\n"; }; +my $four = sub { + my $signum = shift; + print "i am signal ".$signum."\n" ; +}; + +uwsgi::register_signal(17, '', $four); +uwsgi::register_signal(30, '', $two); + my $three = sub { my $env = shift; sleep(1); @@ -27,6 +35,9 @@ my $three = sub { my $app = sub { my $env = shift; + uwsgi::signal(17); + uwsgi::signal(30); + if ($env->{'psgix.cleanup'}) { print "cleanup supported\n"; push @{$env->{'psgix.cleanup.handlers'}}, $one;