Skip to content

Commit eb7e45f

Browse files
author
George Wang
committed
Checked in LiteSpeed SAPI 7.5, addressed two main problems in "clean 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().
1 parent c8c183e commit eb7e45f

File tree

1 file changed

+62
-62
lines changed

1 file changed

+62
-62
lines changed

sapi/litespeed/lsapi_main.c

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include <sys/socket.h>
6767
#include <arpa/inet.h>
6868
#include <netinet/in.h>
69+
#include <sys/time.h>
6970

7071
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
7172
#include "lscriu.c"
@@ -620,7 +621,7 @@ static int sapi_lsapi_activate()
620621
static sapi_module_struct lsapi_sapi_module =
621622
{
622623
"litespeed",
623-
"LiteSpeed V7.4.3",
624+
"LiteSpeed V7.5",
624625

625626
php_lsapi_startup, /* startup */
626627
php_module_shutdown_wrapper, /* shutdown */
@@ -703,66 +704,90 @@ static void lsapi_sigsegv( int signal )
703704

704705
static int clean_onexit = 1;
705706

706-
static void lsapi_sigterm( int signal )
707+
708+
static void lsapi_clean_shutdown()
707709
{
708-
struct sigaction act, old_act;
710+
struct sigaction act;
709711
int sa_rc;
712+
struct itimerval tmv;
713+
#if PHP_MAJOR_VERSION >= 7
714+
zend_string * key;
715+
#endif
716+
clean_onexit = 1;
717+
sigemptyset(&act.sa_mask);
718+
act.sa_flags = 0;
719+
act.sa_handler = lsapi_sigsegv;
720+
sa_rc = sigaction(SIGINT, &act, NULL);
721+
sa_rc = sigaction(SIGQUIT, &act, NULL);
722+
sa_rc = sigaction(SIGILL, &act, NULL);
723+
sa_rc = sigaction(SIGABRT, &act, NULL);
724+
sa_rc = sigaction(SIGBUS, &act, NULL);
725+
sa_rc = sigaction(SIGSEGV, &act, NULL);
726+
sa_rc = sigaction(SIGTERM, &act, NULL);
727+
728+
sa_rc = sigaction(SIGPROF, &act, NULL);
729+
memset(&tmv, 0, sizeof(struct itimerval));
730+
tmv.it_value.tv_sec = 0;
731+
tmv.it_value.tv_usec = 100000;
732+
setitimer(ITIMER_PROF, &tmv, NULL);
733+
734+
#if PHP_MAJOR_VERSION >= 7
735+
key = zend_string_init("error_reporting", 15, 1);
736+
zend_alter_ini_entry_chars_ex(key, "0", 1,
737+
PHP_INI_SYSTEM, PHP_INI_STAGE_SHUTDOWN, 1);
738+
zend_string_release(key);
739+
#else
740+
zend_alter_ini_entry("error_reporting", 16, "0", 1,
741+
PHP_INI_SYSTEM, PHP_INI_STAGE_SHUTDOWN);
742+
#endif
743+
744+
zend_try {
745+
php_request_shutdown(NULL);
746+
} zend_end_try();
747+
}
748+
749+
static void lsapi_sigterm(int signal)
750+
{
710751

711752
// fprintf(stderr, "lsapi_sigterm: %d: clean_onexit %d\n", getpid(), clean_onexit );
712753
if(!clean_onexit)
713754
{
714-
clean_onexit = 1;
715-
act.sa_flags = 0;
716-
act.sa_handler = lsapi_sigsegv;
717-
sa_rc = sigaction( SIGINT, &act, &old_act );
718-
sa_rc = sigaction( SIGQUIT, &act, &old_act );
719-
sa_rc = sigaction( SIGILL, &act, &old_act );
720-
sa_rc = sigaction( SIGABRT, &act, &old_act );
721-
sa_rc = sigaction( SIGBUS, &act, &old_act );
722-
sa_rc = sigaction( SIGSEGV, &act, &old_act );
723-
sa_rc = sigaction( SIGTERM, &act, &old_act );
724-
725-
zend_try {
726-
php_request_shutdown(NULL);
727-
} zend_end_try();
755+
lsapi_clean_shutdown();
728756
}
729757
exit(1);
730758
}
731759

732-
static void lsapi_atexit( void )
760+
static void lsapi_atexit(void)
733761
{
734-
struct sigaction act, old_act;
735-
int sa_rc;
736-
737762
//fprintf(stderr, "lsapi_atexit: %d: clean_onexit %d\n", getpid(), clean_onexit );
738763
if(!clean_onexit)
739764
{
740-
clean_onexit = 1;
741-
act.sa_flags = 0;
742-
act.sa_handler = lsapi_sigsegv;
743-
sa_rc = sigaction( SIGINT, &act, &old_act );
744-
sa_rc = sigaction( SIGQUIT, &act, &old_act );
745-
sa_rc = sigaction( SIGILL, &act, &old_act );
746-
sa_rc = sigaction( SIGABRT, &act, &old_act );
747-
sa_rc = sigaction( SIGBUS, &act, &old_act );
748-
sa_rc = sigaction( SIGSEGV, &act, &old_act );
749-
sa_rc = sigaction( SIGTERM, &act, &old_act );
750-
751-
//fprintf(stderr, "lsapi_atexit: %d: before php_request_shutdown\n", getpid(), clean_onexit );
752-
zend_try {
753-
php_request_shutdown(NULL);
754-
} zend_end_try();
765+
lsapi_clean_shutdown();
755766
}
756767
}
757768

769+
758770
static int lsapi_module_main(int show_source)
759771
{
772+
struct sigaction act;
773+
int sa_rc;
760774
zend_file_handle file_handle;
761775
memset(&file_handle, 0, sizeof(file_handle));
762776
if (php_request_startup() == FAILURE ) {
763777
return -1;
764778
}
765779

780+
sigemptyset(&act.sa_mask);
781+
act.sa_flags = SA_NODEFER;
782+
act.sa_handler = lsapi_sigterm;
783+
sa_rc = sigaction( SIGINT, &act, NULL);
784+
sa_rc = sigaction( SIGQUIT, &act, NULL);
785+
sa_rc = sigaction( SIGILL, &act, NULL);
786+
sa_rc = sigaction( SIGABRT, &act, NULL);
787+
sa_rc = sigaction( SIGBUS, &act, NULL);
788+
sa_rc = sigaction( SIGSEGV, &act, NULL);
789+
sa_rc = sigaction( SIGTERM, &act, NULL);
790+
766791
clean_onexit = 0;
767792

768793
if (show_source) {
@@ -1397,6 +1422,7 @@ void start_children( int children )
13971422
setsid();
13981423

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

1476-
struct sigaction act, old_act;
1477-
struct sigaction INT_act;
1478-
struct sigaction QUIT_act;
1479-
struct sigaction ILL_act;
1480-
struct sigaction ABRT_act;
1481-
struct sigaction BUS_act;
1482-
struct sigaction SEGV_act;
1483-
struct sigaction TERM_act;
1484-
int sa_rc;
14851502

14861503
#ifdef HAVE_SIGNAL_H
14871504
#if defined(SIGPIPE) && defined(SIG_IGN)
@@ -1584,15 +1601,6 @@ int main( int argc, char * argv[] )
15841601
int iRequestsProcessed = 0;
15851602
int result;
15861603

1587-
act.sa_flags = SA_NODEFER;
1588-
act.sa_handler = lsapi_sigterm;
1589-
sa_rc = sigaction( SIGINT, &act, &INT_act );
1590-
sa_rc = sigaction( SIGQUIT, &act, &QUIT_act );
1591-
sa_rc = sigaction( SIGILL, &act, &ILL_act );
1592-
sa_rc = sigaction( SIGABRT, &act, &ABRT_act );
1593-
sa_rc = sigaction( SIGBUS, &act, &BUS_act );
1594-
sa_rc = sigaction( SIGSEGV, &act, &SEGV_act );
1595-
sa_rc = sigaction( SIGTERM, &act, &TERM_act );
15961604
atexit(lsapi_atexit);
15971605

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

1628-
sa_rc = sigaction( SIGINT, &INT_act, &old_act );
1629-
sa_rc = sigaction( SIGQUIT, &QUIT_act, &old_act );
1630-
sa_rc = sigaction( SIGILL, &ILL_act, &old_act );
1631-
sa_rc = sigaction( SIGABRT, &ABRT_act, &old_act );
1632-
sa_rc = sigaction( SIGBUS, &BUS_act, &old_act );
1633-
sa_rc = sigaction( SIGSEGV, &SEGV_act, &old_act );
1634-
sa_rc = sigaction( SIGTERM, &TERM_act, &old_act );
1635-
16361636
php_module_shutdown();
16371637

16381638
#ifdef ZTS

0 commit comments

Comments
 (0)