Skip to content

Commit 8462a3d

Browse files
author
George Wang
committed
Merge branch 'PHP-7.4' into PHP-8.0
2 parents ae23852 + 8fc0bdf commit 8462a3d

File tree

2 files changed

+54
-37
lines changed

2 files changed

+54
-37
lines changed

sapi/litespeed/lsapi_main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int sapi_lsapi_activate()
592592
static sapi_module_struct lsapi_sapi_module =
593593
{
594594
"litespeed",
595-
"LiteSpeed V7.7",
595+
"LiteSpeed V7.9",
596596

597597
php_lsapi_startup, /* startup */
598598
php_module_shutdown_wrapper, /* shutdown */

sapi/litespeed/lsapilib.c

+53-36
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ static int s_ppid;
150150
static int s_restored_ppid = 0;
151151
static int s_pid = 0;
152152
static int s_slow_req_msecs = 0;
153-
static int s_keepListener = 0;
153+
static int s_keep_listener = 1;
154154
static int s_dump_debug_info = 0;
155155
static int s_pid_dump_debug_info = 0;
156156
static int s_req_processed = 0;
@@ -242,8 +242,8 @@ void LSAPI_Log(int flag, const char * fmt, ...)
242242
{
243243
char buf[1024];
244244
char *p = buf;
245-
if ((flag & LSAPI_LOG_TIMESTAMP_BITS) &&
246-
!((flag & LSAPI_LOG_TIMESTAMP_STDERR) && s_stderr_is_pipe))
245+
if ((flag & LSAPI_LOG_TIMESTAMP_BITS)
246+
&& !(s_stderr_is_pipe))
247247
{
248248
struct timeval tv;
249249
struct tm tm;
@@ -270,7 +270,7 @@ void LSAPI_Log(int flag, const char * fmt, ...)
270270

271271
if (flag & LSAPI_LOG_PID)
272272
{
273-
p += snprintf(p, 100, "[%d] ", s_pid);
273+
p += snprintf(p, 100, "[UID:%d][%d] ", getuid(), s_pid);
274274
}
275275

276276
if (p > buf)
@@ -292,7 +292,13 @@ void LSAPI_Log(int flag, const char * fmt, ...)
292292

293293
#endif
294294

295-
#define lsapi_log(...) LSAPI_Log(LSAPI_LOG_TIMESTAMP_FULL|LSAPI_LOG_TIMESTAMP_STDERR|LSAPI_LOG_PID, __VA_ARGS__)
295+
#define lsapi_log(...) LSAPI_Log(LSAPI_LOG_TIMESTAMP_FULL|LSAPI_LOG_PID, __VA_ARGS__)
296+
297+
298+
void lsapi_perror(const char * pMessage, int err_no)
299+
{
300+
lsapi_log("%s, errno: %d (%s)\n", pMessage, err_no, strerror(err_no));
301+
}
296302

297303

298304
static int lsapi_parent_dead()
@@ -891,7 +897,8 @@ int LSAPI_is_suEXEC_Daemon(void)
891897
static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char *pErr2 )
892898
{
893899
char achError[4096];
894-
int n = snprintf(achError, sizeof(achError), "[%d] %s:%s: %s\n", getpid(),
900+
int n = snprintf(achError, sizeof(achError), "[UID:%d][%d] %s:%s: %s\n",
901+
getuid(), getpid(),
895902
pErr1, (pErr2)?pErr2:"", strerror(errno));
896903
if (n > (int)sizeof(achError))
897904
n = sizeof(achError);
@@ -937,7 +944,7 @@ static int lsapi_enterLVE( LSAPI_Request * pReq, uid_t uid )
937944
ret = (*fp_lve_enter)(s_lve, uid, -1, -1, &cookie);
938945
if ( ret < 0 )
939946
{
940-
lsapi_log("enter LVE (%d) : result: %d !\n", uid, ret );
947+
//lsapi_log("enter LVE (%d) : ressult: %d !\n", uid, ret );
941948
LSAPI_perror_r(pReq, "LSAPI: lve_enter() failure, reached resource limit.", NULL );
942949
lsapi_lve_error( pReq );
943950
return -1;
@@ -2936,14 +2943,14 @@ static void lsapi_sigchild( int signal )
29362943

29372944
static int lsapi_init_children_status(void)
29382945
{
2946+
char * pBuf;
29392947
int size = 4096;
29402948
int max_children;
29412949
if (g_prefork_server->m_pChildrenStatus)
29422950
return 0;
29432951
max_children = g_prefork_server->m_iMaxChildren
29442952
+ g_prefork_server->m_iExtraChildren;
29452953

2946-
char * pBuf;
29472954
size = max_children * sizeof( lsapi_child_status ) * 2 + 3 * sizeof(int);
29482955
size = (size + 4095) / 4096 * 4096;
29492956
pBuf =( char*) mmap( NULL, size, PROT_READ | PROT_WRITE,
@@ -2976,9 +2983,9 @@ static void dump_debug_info( lsapi_child_status * pStatus, long tmCur )
29762983
return;
29772984
}
29782985

2979-
lsapi_log("Possible runaway process, PPID: %d, PID: %d, "
2986+
lsapi_log("Possible runaway process, UID: %d, PPID: %d, PID: %d, "
29802987
"reqCount: %d, process time: %ld, checkpoint time: %ld, start "
2981-
"time: %ld\n", getpid(), pStatus->m_pid,
2988+
"time: %ld\n", getuid(), getppid(), pStatus->m_pid,
29822989
pStatus->m_iReqCounter, tmCur - pStatus->m_tmReqBegin,
29832990
tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart );
29842991

@@ -3006,12 +3013,11 @@ static void lsapi_check_child_status( long tmCur )
30063013
while( pStatus < pEnd )
30073014
{
30083015
tobekilled = 0;
3009-
if ( pStatus->m_pid != 0 )
3016+
if ( pStatus->m_pid != 0 && pStatus->m_pid != -1)
30103017
{
30113018
++count;
30123019
if ( !pStatus->m_inProcess )
30133020
{
3014-
30153021
if (g_prefork_server->m_iCurChildren - dying
30163022
> g_prefork_server->m_iMaxChildren
30173023
|| idle > g_prefork_server->m_iMaxIdleChildren)
@@ -3028,7 +3034,7 @@ static void lsapi_check_child_status( long tmCur )
30283034
//tobekilled = SIGUSR1;
30293035
}
30303036
}
3031-
if ( !tobekilled )
3037+
if (!pStatus->m_iKillSent)
30323038
++idle;
30333039
}
30343040
else
@@ -3182,6 +3188,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
31823188

31833189
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
31843190
*s_avail_pages = sysconf(_SC_AVPHYS_PAGES);
3191+
// lsapi_log("Memory total: %zd, free: %zd, free %%%zd\n",
3192+
// s_total_pages, *s_avail_pages, *s_avail_pages * 100 / s_total_pages);
3193+
31853194
#endif
31863195
FD_ZERO( &readfds );
31873196
FD_SET( pServer->m_fd, &readfds );
@@ -3194,7 +3203,8 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
31943203
if (s_accepting_workers)
31953204
accepting = __sync_add_and_fetch(s_accepting_workers, 0);
31963205

3197-
if (pServer->m_iCurChildren > 0 && accepting > 0)
3206+
if (pServer->m_iCurChildren > 0
3207+
&& accepting > 0)
31983208
{
31993209
usleep(400);
32003210
while(accepting-- > 0)
@@ -3263,10 +3273,10 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
32633273
__sync_add_and_fetch(s_busy_workers, 1);
32643274
lsapi_set_nblock( pReq->m_fd, 0 );
32653275
//keep it open if busy_count is used.
3266-
if (s_busy_workers
3276+
if (!s_keep_listener && s_busy_workers
32673277
&& *s_busy_workers > (pServer->m_iMaxChildren >> 1))
3268-
s_keepListener = 1;
3269-
if ((s_uid == 0 || !s_keepListener || !is_enough_free_mem())
3278+
s_keep_listener = 1;
3279+
if ((s_uid == 0 || !s_keep_listener || !is_enough_free_mem())
32703280
&& pReq->m_fdListen != -1 )
32713281
{
32723282
close( pReq->m_fdListen );
@@ -3287,7 +3297,9 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
32873297
}
32883298
else if ( pid == -1 )
32893299
{
3290-
perror( "fork() failed, please increase process limit" );
3300+
lsapi_perror("fork() failed, please increase process limit", errno);
3301+
if (child_status)
3302+
child_status->m_pid = 0;
32913303
}
32923304
else
32933305
{
@@ -3310,7 +3322,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer,
33103322
{
33113323
if (( errno == EINTR )||( errno == EAGAIN))
33123324
continue;
3313-
perror( "accept() failed" );
3325+
lsapi_perror("accept() failed", errno);
33143326
return -1;
33153327
}
33163328
}
@@ -3348,10 +3360,10 @@ int LSAPI_Postfork_Child(LSAPI_Request * pReq)
33483360
__sync_add_and_fetch(s_busy_workers, 1);
33493361
lsapi_set_nblock( pReq->m_fd, 0 );
33503362
//keep it open if busy_count is used.
3351-
if (s_busy_workers
3363+
if (!s_keep_listener && s_busy_workers
33523364
&& *s_busy_workers > (max_children >> 1))
3353-
s_keepListener = 1;
3354-
if ((s_uid == 0 || !s_keepListener || !is_enough_free_mem())
3365+
s_keep_listener = 1;
3366+
if ((s_uid == 0 || !s_keep_listener || !is_enough_free_mem())
33553367
&& pReq->m_fdListen != -1 )
33563368
{
33573369
close(pReq->m_fdListen);
@@ -3510,7 +3522,7 @@ int LSAPI_Accept_Before_Fork(LSAPI_Request * pReq)
35103522
{
35113523
if ((errno == EINTR) || (errno == EAGAIN))
35123524
continue;
3513-
perror( "accept() failed" );
3525+
lsapi_perror("accept() failed", errno);
35143526
ret = -1;
35153527
break;
35163528
}
@@ -3526,13 +3538,6 @@ int LSAPI_Accept_Before_Fork(LSAPI_Request * pReq)
35263538
}
35273539

35283540

3529-
void lsapi_perror( const char * pMessage, int err_no )
3530-
{
3531-
lsapi_log("%s, errno: %d (%s)\n", pMessage, err_no,
3532-
strerror( err_no ) );
3533-
}
3534-
3535-
35363541
int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
35373542
{
35383543
int fd;
@@ -3618,9 +3623,21 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
36183623
if ( s_worker_status )
36193624
{
36203625
s_worker_status->m_inProcess = 0;
3621-
if (fd == pReq->m_fdListen
3622-
&& (s_keepListener != 2 || !is_enough_free_mem()))
3623-
return -1;
3626+
if (fd == pReq->m_fdListen)
3627+
{
3628+
if (s_keep_listener == 0 || !is_enough_free_mem())
3629+
return -1;
3630+
if (s_keep_listener == 1)
3631+
{
3632+
int wait_time = 10;
3633+
if (s_busy_workers)
3634+
wait_time += *s_busy_workers * 10;
3635+
if (s_accepting_workers)
3636+
wait_time >>= (*s_accepting_workers);
3637+
if (wait_secs >= wait_time)
3638+
return -1;
3639+
}
3640+
}
36243641
}
36253642
++wait_secs;
36263643
if (( s_max_idle_secs > 0 )&&(wait_secs >= s_max_idle_secs ))
@@ -3655,7 +3672,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq )
36553672

36563673
lsapi_set_nblock( fd, 0 );
36573674
//init_conn_key( pReq->m_fd );
3658-
if (!s_keepListener)
3675+
if (!s_keep_listener)
36593676
{
36603677
close( pReq->m_fdListen );
36613678
pReq->m_fdListen = -1;
@@ -3947,7 +3964,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
39473964
if ( p )
39483965
{
39493966
n = atoi( p );
3950-
s_keepListener = n;
3967+
s_keep_listener = n;
39513968
}
39523969

39533970
p = getenv( "LSAPI_AVOID_FORK" );
@@ -3956,7 +3973,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp )
39563973
avoidFork = atoi( p );
39573974
if (avoidFork)
39583975
{
3959-
s_keepListener = 2;
3976+
s_keep_listener = 2;
39603977
ch = *(p + strlen(p) - 1);
39613978
if ( ch == 'G' || ch == 'g' )
39623979
avoidFork *= 1024 * 1024 * 1024;

0 commit comments

Comments
 (0)