Skip to content

Commit

Permalink
Checked in LiteSpeed SAPI 7.5, addressed two main problems in "clean …
Browse files Browse the repository at this point in the history
…shutdown" introduced in 7.4.3,

1. falls in an infinite loop because PHP engine's inconsistent state, now override the ITIMER_PROF to 0.1 second, clean shutdown must finish before that.
2. generate too much error log, we completely disable "error_reporting" before calling php_request_shutdown().
  • Loading branch information
George Wang committed Jul 21, 2019
1 parent c8c183e commit eb7e45f
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions sapi/litespeed/lsapi_main.c
Expand Up @@ -66,6 +66,7 @@
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/time.h>

#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
#include "lscriu.c"
Expand Down Expand Up @@ -620,7 +621,7 @@ static int sapi_lsapi_activate()
static sapi_module_struct lsapi_sapi_module =
{
"litespeed",
"LiteSpeed V7.4.3",
"LiteSpeed V7.5",

php_lsapi_startup, /* startup */
php_module_shutdown_wrapper, /* shutdown */
Expand Down Expand Up @@ -703,66 +704,90 @@ static void lsapi_sigsegv( int signal )

static int clean_onexit = 1;

static void lsapi_sigterm( int signal )

static void lsapi_clean_shutdown()
{
struct sigaction act, old_act;
struct sigaction act;
int sa_rc;
struct itimerval tmv;
#if PHP_MAJOR_VERSION >= 7
zend_string * key;
#endif
clean_onexit = 1;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = lsapi_sigsegv;
sa_rc = sigaction(SIGINT, &act, NULL);
sa_rc = sigaction(SIGQUIT, &act, NULL);
sa_rc = sigaction(SIGILL, &act, NULL);
sa_rc = sigaction(SIGABRT, &act, NULL);
sa_rc = sigaction(SIGBUS, &act, NULL);
sa_rc = sigaction(SIGSEGV, &act, NULL);
sa_rc = sigaction(SIGTERM, &act, NULL);

sa_rc = sigaction(SIGPROF, &act, NULL);
memset(&tmv, 0, sizeof(struct itimerval));
tmv.it_value.tv_sec = 0;
tmv.it_value.tv_usec = 100000;
setitimer(ITIMER_PROF, &tmv, NULL);

#if PHP_MAJOR_VERSION >= 7
key = zend_string_init("error_reporting", 15, 1);
zend_alter_ini_entry_chars_ex(key, "0", 1,
PHP_INI_SYSTEM, PHP_INI_STAGE_SHUTDOWN, 1);
zend_string_release(key);
#else
zend_alter_ini_entry("error_reporting", 16, "0", 1,
PHP_INI_SYSTEM, PHP_INI_STAGE_SHUTDOWN);
#endif

zend_try {
php_request_shutdown(NULL);
} zend_end_try();
}

static void lsapi_sigterm(int signal)
{

// fprintf(stderr, "lsapi_sigterm: %d: clean_onexit %d\n", getpid(), clean_onexit );
if(!clean_onexit)
{
clean_onexit = 1;
act.sa_flags = 0;
act.sa_handler = lsapi_sigsegv;
sa_rc = sigaction( SIGINT, &act, &old_act );
sa_rc = sigaction( SIGQUIT, &act, &old_act );
sa_rc = sigaction( SIGILL, &act, &old_act );
sa_rc = sigaction( SIGABRT, &act, &old_act );
sa_rc = sigaction( SIGBUS, &act, &old_act );
sa_rc = sigaction( SIGSEGV, &act, &old_act );
sa_rc = sigaction( SIGTERM, &act, &old_act );

zend_try {
php_request_shutdown(NULL);
} zend_end_try();
lsapi_clean_shutdown();
}
exit(1);
}

static void lsapi_atexit( void )
static void lsapi_atexit(void)
{
struct sigaction act, old_act;
int sa_rc;

//fprintf(stderr, "lsapi_atexit: %d: clean_onexit %d\n", getpid(), clean_onexit );
if(!clean_onexit)
{
clean_onexit = 1;
act.sa_flags = 0;
act.sa_handler = lsapi_sigsegv;
sa_rc = sigaction( SIGINT, &act, &old_act );
sa_rc = sigaction( SIGQUIT, &act, &old_act );
sa_rc = sigaction( SIGILL, &act, &old_act );
sa_rc = sigaction( SIGABRT, &act, &old_act );
sa_rc = sigaction( SIGBUS, &act, &old_act );
sa_rc = sigaction( SIGSEGV, &act, &old_act );
sa_rc = sigaction( SIGTERM, &act, &old_act );

//fprintf(stderr, "lsapi_atexit: %d: before php_request_shutdown\n", getpid(), clean_onexit );
zend_try {
php_request_shutdown(NULL);
} zend_end_try();
lsapi_clean_shutdown();
}
}


static int lsapi_module_main(int show_source)
{
struct sigaction act;
int sa_rc;
zend_file_handle file_handle;
memset(&file_handle, 0, sizeof(file_handle));
if (php_request_startup() == FAILURE ) {
return -1;
}

sigemptyset(&act.sa_mask);
act.sa_flags = SA_NODEFER;
act.sa_handler = lsapi_sigterm;
sa_rc = sigaction( SIGINT, &act, NULL);
sa_rc = sigaction( SIGQUIT, &act, NULL);
sa_rc = sigaction( SIGILL, &act, NULL);
sa_rc = sigaction( SIGABRT, &act, NULL);
sa_rc = sigaction( SIGBUS, &act, NULL);
sa_rc = sigaction( SIGSEGV, &act, NULL);
sa_rc = sigaction( SIGTERM, &act, NULL);

clean_onexit = 0;

if (show_source) {
Expand Down Expand Up @@ -1397,6 +1422,7 @@ void start_children( int children )
setsid();

/* Set up handler to kill children upon exit */
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = litespeed_cleanup;
if( sigaction( SIGTERM, &act, &old_term ) ||
Expand Down Expand Up @@ -1473,15 +1499,6 @@ int main( int argc, char * argv[] )
int slow_script_msec = 0;
char time_buf[40];

struct sigaction act, old_act;
struct sigaction INT_act;
struct sigaction QUIT_act;
struct sigaction ILL_act;
struct sigaction ABRT_act;
struct sigaction BUS_act;
struct sigaction SEGV_act;
struct sigaction TERM_act;
int sa_rc;

#ifdef HAVE_SIGNAL_H
#if defined(SIGPIPE) && defined(SIG_IGN)
Expand Down Expand Up @@ -1584,15 +1601,6 @@ int main( int argc, char * argv[] )
int iRequestsProcessed = 0;
int result;

act.sa_flags = SA_NODEFER;
act.sa_handler = lsapi_sigterm;
sa_rc = sigaction( SIGINT, &act, &INT_act );
sa_rc = sigaction( SIGQUIT, &act, &QUIT_act );
sa_rc = sigaction( SIGILL, &act, &ILL_act );
sa_rc = sigaction( SIGABRT, &act, &ABRT_act );
sa_rc = sigaction( SIGBUS, &act, &BUS_act );
sa_rc = sigaction( SIGSEGV, &act, &SEGV_act );
sa_rc = sigaction( SIGTERM, &act, &TERM_act );
atexit(lsapi_atexit);

while( ( result = LSAPI_Prefork_Accept_r( &g_req )) >= 0 ) {
Expand Down Expand Up @@ -1625,14 +1633,6 @@ int main( int argc, char * argv[] )
}
}

sa_rc = sigaction( SIGINT, &INT_act, &old_act );
sa_rc = sigaction( SIGQUIT, &QUIT_act, &old_act );
sa_rc = sigaction( SIGILL, &ILL_act, &old_act );
sa_rc = sigaction( SIGABRT, &ABRT_act, &old_act );
sa_rc = sigaction( SIGBUS, &BUS_act, &old_act );
sa_rc = sigaction( SIGSEGV, &SEGV_act, &old_act );
sa_rc = sigaction( SIGTERM, &TERM_act, &old_act );

php_module_shutdown();

#ifdef ZTS
Expand Down

0 comments on commit eb7e45f

Please sign in to comment.