mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 13:41:28 +00:00
implemented register_signal in the psgi plugin
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user