summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Wang <gwang@php.net>2021-03-05 11:00:53 -0500
committerGeorge Wang <gwang@php.net>2021-03-05 11:00:53 -0500
commit8462a3de1a1092e5526940e5e447bcf6a7a9a5d1 (patch)
tree7b6a357d083f0d844ab6bd4cc36d8b79693b3a24
parentae23852e41ca695e866832b4339905a172d0d913 (diff)
parent8fc0bdfb0ad559d6a91fed0aaffd91b17f8ace9d (diff)
downloadphp-git-8462a3de1a1092e5526940e5e447bcf6a7a9a5d1.tar.gz
Merge branch 'PHP-7.4' into PHP-8.0
-rw-r--r--sapi/litespeed/lsapi_main.c2
-rw-r--r--sapi/litespeed/lsapilib.c89
2 files changed, 54 insertions, 37 deletions
diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c
index 24703ef75c..d82e82556e 100644
--- a/sapi/litespeed/lsapi_main.c
+++ b/sapi/litespeed/lsapi_main.c
@@ -592,7 +592,7 @@ static int sapi_lsapi_activate()
static sapi_module_struct lsapi_sapi_module =
{
"litespeed",
- "LiteSpeed V7.7",
+ "LiteSpeed V7.9",
php_lsapi_startup, /* startup */
php_module_shutdown_wrapper, /* shutdown */
diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c
index 46905f917a..444872de7f 100644
--- a/sapi/litespeed/lsapilib.c
+++ b/sapi/litespeed/lsapilib.c
@@ -150,7 +150,7 @@ static int s_ppid;
static int s_restored_ppid = 0;
static int s_pid = 0;
static int s_slow_req_msecs = 0;
-static int s_keepListener = 0;
+static int s_keep_listener = 1;
static int s_dump_debug_info = 0;
static int s_pid_dump_debug_info = 0;
static int s_req_processed = 0;
@@ -242,8 +242,8 @@ void LSAPI_Log(int flag, const char * fmt, ...)
{
char buf[1024];
char *p = buf;
- if ((flag & LSAPI_LOG_TIMESTAMP_BITS) &&
- !((flag & LSAPI_LOG_TIMESTAMP_STDERR) && s_stderr_is_pipe))
+ if ((flag & LSAPI_LOG_TIMESTAMP_BITS)
+ && !(s_stderr_is_pipe))
{
struct timeval tv;
struct tm tm;
@@ -270,7 +270,7 @@ void LSAPI_Log(int flag, const char * fmt, ...)
if (flag & LSAPI_LOG_PID)
{
- p += snprintf(p, 100, "[%d] ", s_pid);
+ p += snprintf(p, 100, "[UID:%d][%d] ", getuid(), s_pid);
}
if (p > buf)
@@ -292,7 +292,13 @@ void LSAPI_Log(int flag, const char * fmt, ...)
#endif
-#define lsapi_log(...) LSAPI_Log(LSAPI_LOG_TIMESTAMP_FULL|LSAPI_LOG_TIMESTAMP_STDERR|LSAPI_LOG_PID, __VA_ARGS__)
+#define lsapi_log(...) LSAPI_Log(LSAPI_LOG_TIMESTAMP_FULL|LSAPI_LOG_PID, __VA_ARGS__)
+
+
+void lsapi_perror(const char * pMessage, int err_no)
+{
+ lsapi_log("%s, errno: %d (%s)\n", pMessage, err_no, strerror(err_no));
+}
static int lsapi_parent_dead()
@@ -891,7 +897,8 @@ int LSAPI_is_suEXEC_Daemon(void)
static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char *pErr2 )
{
char achError[4096];
- int n = snprintf(achError, sizeof(achError), "[%d] %s:%s: %s\n", getpid(),
+ int n = snprintf(achError, sizeof(achError), "[UID:%d][%d] %s:%s: %s\n",
+ getuid(), getpid(),
pErr1, (pErr2)?pErr2:"", strerror(errno));
if (n > (int)sizeof(achError))
n = sizeof(achError);
@@ -937,7 +944,7 @@ static int lsapi_enterLVE( LSAPI_Request * pReq, uid_t uid )
ret = (*fp_lve_enter)(s_lve, uid, -1, -1, &cookie);
if ( ret < 0 )
{
- lsapi_log("enter LVE (%d) : result: %d !\n", uid, ret );
+ //lsapi_log("enter LVE (%d) : ressult: %d !\n", uid, ret );
LSAPI_perror_r(pReq, "LSAPI: lve_enter() failure, reached resource limit.", NULL );
lsapi_lve_error( pReq );
return -1;
@@ -2936,6 +2943,7 @@ static void lsapi_sigchild( int signal )
static int lsapi_init_children_status(void)
{
+ char * pBuf;
int size = 4096;
int max_children;
if (g_prefork_server->m_pChildrenStatus)
@@ -2943,7 +2951,6 @@ static int lsapi_init_children_status(void)
max_children = g_prefork_server->m_iMaxChildren
+ g_prefork_server->m_iExtraChildren;
- char * pBuf;
size = max_children * sizeof( lsapi_child_status ) * 2 + 3 * sizeof(int);
size = (size + 4095) / 4096 * 4096;
pBuf =( char*) mmap( NULL, size, PROT_READ | PROT_WRITE,
@@ -2976,9 +2983,9 @@ static void dump_debug_info( lsapi_child_status * pStatus, long tmCur )
return;
}
- lsapi_log("Possible runaway process, PPID: %d, PID: %d, "
+ lsapi_log("Possible runaway process, UID: %d, PPID: %d, PID: %d, "
"reqCount: %d, process time: %ld, checkpoint time: %ld, start "
- "time: %ld\n", getpid(), pStatus->m_pid,
+ "time: %ld\n", getuid(), getppid(), pStatus->m_pid,
pStatus->m_iReqCounter, tmCur - pStatus->m_tmReqBegin,
tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart );
@@ -3006,12 +3013,11 @@ static void lsapi_check_child_status( long tmCur )
while( pStatus < pEnd )
{
tobekilled = 0;
- if ( pStatus->m_pid != 0 )
+ if ( pStatus->m_pid != 0 && pStatus->m_pid != -1)
{
++count;
if ( !pStatus->m_inProcess )
{
-
if (g_prefork_server->m_iCurChildren - dying
> g_prefork_server->m_iMaxChildren
|| idle > g_prefork_server->m_iMaxIdleChildren)
@@ -3028,7 +3034,7 @@ static void lsapi_check_child_status( long tmCur )
//tobekilled = SIGUSR1;
}
}
- if ( !tobekilled )
+ if (!pStatus->m_iKillSent)
++idle;
}
else
@@ -3182,6 +3188,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
*s_avail_pages = sysconf(_SC_AVPHYS_PAGES);
+// lsapi_log("Memory total: %zd, free: %zd, free %%%zd\n",
+// s_total_pages, *s_avail_pages, *s_avail_pages * 100 / s_total_pages);
+
#endif
FD_ZERO( &readfds );
FD_SET( pServer->m_fd, &readfds );
@@ -3194,7 +3203,8 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
if (s_accepting_workers)
accepting = __sync_add_and_fetch(s_accepting_workers, 0);
- if (pServer->m_iCurChildren > 0 && accepting > 0)
+ if (pServer->m_iCurChildren > 0
+ && accepting > 0)
{
usleep(400);
while(accepting-- > 0)
@@ -3263,10 +3273,10 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
__sync_add_and_fetch(s_busy_workers, 1);
lsapi_set_nblock( pReq->m_fd, 0 );
//keep it open if busy_count is used.
- if (s_busy_workers
+ if (!s_keep_listener && s_busy_workers
&& *s_busy_workers > (pServer->m_iMaxChildren >> 1))
- s_keepListener = 1;
- if ((s_uid == 0 || !s_keepListener || !is_enough_free_mem())
+ s_keep_listener = 1;
+ if ((s_uid == 0 || !s_keep_listener || !is_enough_free_mem())
&& pReq->m_fdListen != -1 )
{
close( pReq->m_fdListen );
@@ -3287,7 +3297,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
}
else if ( pid == -1 )
{
- perror( "fork() failed, please increase process limit" );
+ lsapi_perror("fork() failed, please increase process limit", errno);
+ if (child_status)
+ child_status->m_pid = 0;
}
else
{
@@ -3310,7 +3322,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
{
if (( errno == EINTR )||( errno == EAGAIN))
continue;
- perror( "accept() failed" );
+ lsapi_perror("accept() failed", errno);
return -1;
}
}
@@ -3348,10 +3360,10 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
__sync_add_and_fetch(s_busy_workers, 1);
lsapi_set_nblock( pReq->m_fd, 0 );
//keep it open if busy_count is used.
- if (s_busy_workers
+ if (!s_keep_listener && s_busy_workers
&& *s_busy_workers > (max_children >> 1))
- s_keepListener = 1;
- if ((s_uid == 0 || !s_keepListener || !is_enough_free_mem())
+ s_keep_listener = 1;
+ if ((s_uid == 0 || !s_keep_listener || !is_enough_free_mem())
&& pReq->m_fdListen != -1 )
{
close(pReq->m_fdListen);
@@ -3510,7 +3522,7 @@ int LSAPI_Accept_Before_Fork(LSAPI_Request * pReq)
{
if ((errno == EINTR) || (errno == EAGAIN))
continue;
- perror( "accept() failed" );
+ lsapi_perror("accept() failed", errno);
ret = -1;
break;
}
@@ -3526,13 +3538,6 @@ int LSAPI_Accept_Before_Fork(LSAPI_Request * pReq)
}
-void lsapi_perror( const char * pMessage, int err_no )
-{
- lsapi_log("%s, errno: %d (%s)\n", pMessage, err_no,
- strerror( err_no ) );
-}
-
-
int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
{
int fd;
@@ -3618,9 +3623,21 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
if ( s_worker_status )
{
s_worker_status->m_inProcess = 0;
- if (fd == pReq->m_fdListen
- && (s_keepListener != 2 || !is_enough_free_mem()))
- return -1;
+ if (fd == pReq->m_fdListen)
+ {
+ if (s_keep_listener == 0 || !is_enough_free_mem())
+ return -1;
+ if (s_keep_listener == 1)
+ {
+ int wait_time = 10;
+ if (s_busy_workers)
+ wait_time += *s_busy_workers * 10;
+ if (s_accepting_workers)
+ wait_time >>= (*s_accepting_workers);
+ if (wait_secs >= wait_time)
+ return -1;
+ }
+ }
}
++wait_secs;
if (( s_max_idle_secs > 0 )&&(wait_secs >= s_max_idle_secs ))
@@ -3655,7 +3672,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
lsapi_set_nblock( fd, 0 );
//init_conn_key( pReq->m_fd );
- if (!s_keepListener)
+ if (!s_keep_listener)
{
close( pReq->m_fdListen );
pReq->m_fdListen = -1;
@@ -3947,7 +3964,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
if ( p )
{
n = atoi( p );
- s_keepListener = n;
+ s_keep_listener = n;
}
p = getenv( "LSAPI_AVOID_FORK" );
@@ -3956,7 +3973,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
avoidFork = atoi( p );
if (avoidFork)
{
- s_keepListener = 2;
+ s_keep_listener = 2;
ch = *(p + strlen(p) - 1);
if ( ch == 'G' || ch == 'g' )
avoidFork *= 1024 * 1024 * 1024;