Merge branch 'PHP-7.2'

Conflicts:
	sapi/litespeed/lsapi_main.c
This commit is contained in:
George Wang 2018-02-27 13:57:06 -05:00
commit 2ec012fa2a
5 changed files with 2048 additions and 265 deletions

View File

@ -67,6 +67,9 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
#include "lscriu.c"
#endif
#define SAPI_LSAPI_MAX_HEADER_LENGTH 2048
@ -91,6 +94,7 @@ static int ignore_php_ini = 0;
static char * argv0 = NULL;
static int engine = 1;
static int parse_user_ini = 0;
#ifdef ZTS
zend_compiler_globals *compiler_globals;
zend_executor_globals *executor_globals;
@ -178,7 +182,7 @@ static size_t sapi_lsapi_ub_write(const char *str, size_t str_length)
/* {{{ sapi_lsapi_flush
*/
static void sapi_lsapi_flush( void * server_context )
static void sapi_lsapi_flush(void * server_context)
{
if ( lsapi_mode ) {
if ( LSAPI_Flush() == -1) {
@ -193,8 +197,7 @@ static void sapi_lsapi_flush( void * server_context )
*/
static int sapi_lsapi_deactivate(void)
{
if ( SG(request_info).path_translated )
{
if ( SG(request_info).path_translated ) {
efree( SG(request_info).path_translated );
SG(request_info).path_translated = NULL;
}
@ -235,44 +238,44 @@ static int add_variable( const char * pKey, int keyLen, const char * pValue, int
static void litespeed_php_import_environment_variables(zval *array_ptr)
{
char buf[128];
char **env, *p, *t = buf;
size_t alloc_size = sizeof(buf);
unsigned long nlen; /* ptrdiff_t is not portable */
char buf[128];
char **env, *p, *t = buf;
size_t alloc_size = sizeof(buf);
unsigned long nlen; /* ptrdiff_t is not portable */
if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) &&
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0
) {
zend_array_destroy(Z_ARR_P(array_ptr));
Z_ARR_P(array_ptr) = zend_array_dup(Z_ARR(PG(http_globals)[TRACK_VARS_ENV]));
return;
) {
zval_dtor(array_ptr);
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]);
return;
} else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) &&
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0
) {
zend_array_destroy(Z_ARR_P(array_ptr));
Z_ARR_P(array_ptr) = zend_array_dup(Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]));
return;
}
) {
zval_dtor(array_ptr);
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]);
return;
}
for (env = environ; env != NULL && *env != NULL; env++) {
p = strchr(*env, '=');
if (!p) { /* malformed entry? */
continue;
}
nlen = p - *env;
if (nlen >= alloc_size) {
alloc_size = nlen + 64;
t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
}
memcpy(t, *env, nlen);
t[nlen] = '\0';
add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr);
}
if (t != buf && t != NULL) {
efree(t);
}
for (env = environ; env != NULL && *env != NULL; env++) {
p = strchr(*env, '=');
if (!p) { /* malformed entry? */
continue;
}
nlen = p - *env;
if (nlen >= alloc_size) {
alloc_size = nlen + 64;
t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
}
memcpy(t, *env, nlen);
t[nlen] = '\0';
add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr);
}
if (t != buf && t != NULL) {
efree(t);
}
}
/* {{{ sapi_lsapi_register_variables
@ -286,9 +289,9 @@ static void sapi_lsapi_register_variables(zval *track_vars_array)
litespeed_php_import_environment_variables(track_vars_array);
LSAPI_ForeachHeader( add_variable, track_vars_array );
LSAPI_ForeachEnv( add_variable, track_vars_array );
add_variable("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array );
LSAPI_ForeachHeader( add_variable, track_vars_array );
LSAPI_ForeachEnv( add_variable, track_vars_array );
add_variable("PHP_SELF", 8, php_self, strlen( php_self ), track_vars_array );
} else {
php_import_environment_variables(track_vars_array);
@ -405,11 +408,53 @@ static void log_message (const char *fmt, ...)
#define DEBUG_MESSAGE(fmt, ...)
#endif
static int lsapi_activate_user_ini(TSRMLS_D);
static int lsapi_activate_user_ini();
static int sapi_lsapi_activate(TSRMLS_D)
static int sapi_lsapi_activate()
{
if (parse_user_ini && lsapi_activate_user_ini(TSRMLS_C) == FAILURE) {
char *path, *doc_root, *server_name;
size_t path_len, doc_root_len, server_name_len;
/* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */
if (!SG(request_info).path_translated) {
return FAILURE;
}
if (php_ini_has_per_host_config()) {
server_name = sapi_lsapi_getenv("SERVER_NAME", 0);
/* SERVER_NAME should also be defined at this stage..but better check it anyway */
if (server_name) {
server_name_len = strlen(server_name);
server_name = estrndup(server_name, server_name_len);
zend_str_tolower(server_name, server_name_len);
php_ini_activate_per_host_config(server_name, server_name_len);
efree(server_name);
}
}
if (php_ini_has_per_dir_config()) {
/* Prepare search path */
path_len = strlen(SG(request_info).path_translated);
/* Make sure we have trailing slash! */
if (!IS_SLASH(SG(request_info).path_translated[path_len])) {
path = emalloc(path_len + 2);
memcpy(path, SG(request_info).path_translated, path_len + 1);
path_len = zend_dirname(path, path_len);
path[path_len++] = DEFAULT_SLASH;
} else {
path = estrndup(SG(request_info).path_translated, path_len);
path_len = zend_dirname(path, path_len);
}
path[path_len] = 0;
/* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
php_ini_activate_per_dir_config(path, path_len); /* Note: for global settings sake we check from root to path */
efree(path);
}
if (parse_user_ini && lsapi_activate_user_ini() == FAILURE) {
return FAILURE;
}
return SUCCESS;
@ -419,7 +464,7 @@ static int sapi_lsapi_activate(TSRMLS_D)
static sapi_module_struct lsapi_sapi_module =
{
"litespeed",
"LiteSpeed V6.11",
"LiteSpeed V7.0",
php_lsapi_startup, /* startup */
php_module_shutdown_wrapper, /* shutdown */
@ -443,8 +488,8 @@ static sapi_module_struct lsapi_sapi_module =
sapi_lsapi_register_variables, /* register server variables */
sapi_lsapi_log_message, /* Log message */
NULL, /* Get request time */
NULL, /* Child terminate */
NULL, /* Get request time */
NULL, /* Child terminate */
STANDARD_SAPI_MODULE_PROPERTIES
@ -455,7 +500,7 @@ static void init_request_info( void )
{
char * pContentType = LSAPI_GetHeader( H_CONTENT_TYPE );
char * pAuth;
SG(request_info).content_type = pContentType ? pContentType : "";
SG(request_info).request_method = LSAPI_GetRequestMethod();
SG(request_info).query_string = LSAPI_GetQueryString();
@ -465,7 +510,7 @@ static void init_request_info( void )
/* It is not reset by zend engine, set it to 200. */
SG(sapi_headers).http_response_code = 200;
pAuth = LSAPI_GetHeader( H_AUTHORIZATION );
php_handle_auth_data(pAuth);
}
@ -521,9 +566,8 @@ static int lsapi_module_main(int show_source)
static int alter_ini( const char * pKey, int keyLen, const char * pValue, int valLen,
void * arg )
{
#if PHP_MAJOR_VERSION >= 7
zend_string * psKey;
#endif
int type = ZEND_INI_PERDIR;
int stage = PHP_INI_STAGE_RUNTIME;
if ( '\001' == *pKey ) {
@ -544,18 +588,12 @@ static int alter_ini( const char * pKey, int keyLen, const char * pValue, int va
}
else
{
#if PHP_MAJOR_VERSION >= 7
--keyLen;
psKey = zend_string_init(pKey, keyLen, 1);
zend_alter_ini_entry_chars(psKey,
(char *)pValue, valLen,
type, stage);
zend_string_release(psKey);
#else
zend_alter_ini_entry((char *)pKey, keyLen,
(char *)pValue, valLen,
type, stage);
#endif
}
}
return 1;
@ -685,7 +723,6 @@ static int lsapi_activate_user_ini_mk_path(_lsapi_activate_user_ini_ctx *ctx,
ctx->path_len = strlen(ctx->path);
path = ctx->path = estrndup(SG(request_info).path_translated, ctx->path_len);
ctx->path_len = zend_dirname(path, ctx->path_len);
DEBUG_MESSAGE("dirname: %s", ctx->path);
if (*fn_next) {
rc = (*fn_next)(ctx, fn_next + 1);
@ -709,9 +746,7 @@ static int lsapi_activate_user_ini_mk_realpath(_lsapi_activate_user_ini_ctx *ctx
}
ctx->path = real_path;
ctx->path_len = strlen(ctx->path);
DEBUG_MESSAGE("calculated tsrm realpath: %s", real_path);
} else {
DEBUG_MESSAGE("%s is an absolute path", ctx->path);
real_path = NULL;
}
@ -732,10 +767,8 @@ static int lsapi_activate_user_ini_mk_user_config(_lsapi_activate_user_ini_ctx *
/* Find cached config entry: If not found, create one */
ctx->entry = zend_hash_str_find_ptr(&user_config_cache, ctx->path, ctx->path_len);
if (ctx->entry) {
DEBUG_MESSAGE("found entry for %s", ctx->path);
} else {
DEBUG_MESSAGE("entry for %s not found, creating new entry", ctx->path);
if (!ctx->entry)
{
ctx->entry = pemalloc(sizeof(user_config_cache_entry), 1);
ctx->entry->expires = 0;
zend_hash_init(&ctx->entry->user_config, 0, NULL,
@ -758,7 +791,6 @@ static void walk_down_the_path_callback(char* begin,
_lsapi_activate_user_ini_ctx *ctx = data;
char tmp = end[0];
end[0] = 0;
DEBUG_MESSAGE("parsing %s%c%s", begin, DEFAULT_SLASH, PG(user_ini_filename));
php_parse_user_ini_file(begin, PG(user_ini_filename), &ctx->entry->user_config);
end[0] = tmp;
}
@ -805,8 +837,7 @@ static int lsapi_activate_user_ini_finally(_lsapi_activate_user_ini_ctx *ctx,
int rc = SUCCESS;
fn_activate_user_ini_chain_t *fn_next = next;
DEBUG_MESSAGE("calling php_ini_activate_config()");
php_ini_activate_config(&ctx->entry->user_config, PHP_INI_PERDIR,
php_ini_activate_config(&ctx->entry->user_config, PHP_INI_PERDIR,
PHP_INI_STAGE_HTACCESS);
if (*fn_next) {
@ -850,7 +881,7 @@ static void override_ini()
}
static int processReq( void )
static int processReq(void)
{
int ret = 0;
zend_first_try {
@ -862,7 +893,7 @@ static int processReq( void )
override_ini();
if ( engine ) {
init_request_info( );
init_request_info();
if ( lsapi_module_main( source_highlight ) == -1 ) {
ret = -1;
@ -876,7 +907,7 @@ static int processReq( void )
return ret;
}
static void cli_usage( void )
static void cli_usage(void)
{
static const char * usage =
"Usage: php\n"
@ -977,9 +1008,7 @@ static int cli_main( int argc, char * argv[] )
char ** argend= &argv[argc];
int ret = -1;
int c;
#if PHP_MAJOR_VERSION >= 7
zend_string * psKey;
#endif
zend_string *psKey;
lsapi_mode = 0; /* enter CLI mode */
#ifdef PHP_WIN32
@ -1000,17 +1029,11 @@ static int cli_main( int argc, char * argv[] )
EG(uninitialized_zval_ptr) = NULL;
#endif
for( ini = ini_defaults; *ini; ini+=2 ) {
#if PHP_MAJOR_VERSION >= 7
psKey = zend_string_init(*ini, strlen( *ini ), 1);
psKey = zend_string_init(*ini, strlen( *ini ), 1);
zend_alter_ini_entry_chars(psKey,
(char *)*(ini+1), strlen( *(ini+1) ),
PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
zend_string_release(psKey);
#else
zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1,
(char *)*(ini+1), strlen( *(ini+1) ),
PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
#endif
zend_string_release(psKey);
}
while (( p < argend )&&(**p == '-' )) {
@ -1232,8 +1255,12 @@ int main( int argc, char * argv[] )
tsrm_startup(1, 1, 0, NULL);
#endif
zend_signal_startup();
#if PHP_MAJOR_VERSION >= 7
#if defined(ZEND_SIGNALS) || PHP_MINOR_VERSION > 0
zend_signal_startup();
#endif
#endif
if (argc > 1 ) {
if ( parse_opt( argc, argv, &climode,
&php_ini_path, &php_bind ) == -1 ) {
@ -1301,6 +1328,10 @@ int main( int argc, char * argv[] )
LSAPI_Init();
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
int is_criu = LSCRIU_Init(); // Must be called before the regular init as it unsets the parameters.
#endif
LSAPI_Init_Env_Parameters( NULL );
lsapi_mode = 1;
@ -1312,7 +1343,15 @@ int main( int argc, char * argv[] )
php_bind = NULL;
}
while( LSAPI_Prefork_Accept_r( &g_req ) >= 0 ) {
int iRequestsProcessed = 0;
int result;
while( ( result = LSAPI_Prefork_Accept_r( &g_req )) >= 0 ) {
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__)
if (is_criu && !result) {
LSCRIU_inc_req_procssed();
}
#endif
if ( slow_script_msec ) {
gettimeofday( &tv_req_begin, NULL );
}
@ -1486,11 +1525,7 @@ PHP_FUNCTION(apache_get_modules)
array_init(return_value);
while( *name )
{
add_next_index_string(return_value, *name
#if PHP_MAJOR_VERSION < 7
, 1
#endif
);
add_next_index_string(return_value, *name);
++name;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@
*/
/*
Copyright (c) 2002-2015, Lite Speed Technologies Inc.
Copyright (c) 2002-2018, Lite Speed Technologies Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -56,9 +56,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
extern "C" {
#endif
#include <stddef.h>
#include <lsapidef.h>
#include "lsapidef.h"
#include <stddef.h>
#include <sys/time.h>
#include <sys/types.h>
@ -169,7 +169,6 @@ int LSAPI_ForeachSpecialEnv_r( LSAPI_Request * pReq,
char * LSAPI_GetEnv_r( LSAPI_Request * pReq, const char * name );
ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t len );
int LSAPI_ReqBodyGetChar_r( LSAPI_Request * pReq );
@ -294,28 +293,28 @@ static inline int LSAPI_ForeachSpecialEnv( LSAPI_CB_EnvHandler fn, void * arg )
static inline char * LSAPI_GetEnv( const char * name )
{ return LSAPI_GetEnv_r( &g_req, name ); }
static inline char * LSAPI_GetQueryString()
static inline char * LSAPI_GetQueryString(void)
{ return LSAPI_GetQueryString_r( &g_req ); }
static inline char * LSAPI_GetScriptFileName()
static inline char * LSAPI_GetScriptFileName(void)
{ return LSAPI_GetScriptFileName_r( &g_req ); }
static inline char * LSAPI_GetScriptName()
static inline char * LSAPI_GetScriptName(void)
{ return LSAPI_GetScriptName_r( &g_req ); }
static inline char * LSAPI_GetRequestMethod()
static inline char * LSAPI_GetRequestMethod(void)
{ return LSAPI_GetRequestMethod_r( &g_req ); }
static inline off_t LSAPI_GetReqBodyLen()
static inline off_t LSAPI_GetReqBodyLen(void)
{ return LSAPI_GetReqBodyLen_r( &g_req ); }
static inline off_t LSAPI_GetReqBodyRemain()
static inline off_t LSAPI_GetReqBodyRemain(void)
{ return LSAPI_GetReqBodyRemain_r( &g_req ); }
static inline ssize_t LSAPI_ReadReqBody( char * pBuf, size_t len )
{ return LSAPI_ReadReqBody_r( &g_req, pBuf, len ); }
static inline int LSAPI_ReqBodyGetChar()
static inline int LSAPI_ReqBodyGetChar(void)
{ return LSAPI_ReqBodyGetChar_r( &g_req ); }
static inline int LSAPI_ReqBodyGetLine( char * pBuf, int len, int *getLF )
@ -337,7 +336,7 @@ static inline ssize_t LSAPI_sendfile( int fdIn, off_t* off, size_t size )
static inline ssize_t LSAPI_Write_Stderr( const char * pBuf, ssize_t len )
{ return LSAPI_Write_Stderr_r( &g_req, pBuf, len ); }
static inline int LSAPI_Flush()
static inline int LSAPI_Flush(void)
{ return LSAPI_Flush_r( &g_req ); }
static inline int LSAPI_AppendRespHeader( char * pBuf, int len )
@ -379,9 +378,39 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp );
void LSAPI_Set_Slow_Req_Msecs( int msecs );
int LSAPI_Get_Slow_Req_Msecs( );
int LSAPI_Get_Slow_Req_Msecs(void);
int LSAPI_is_suEXEC_Daemon(void);
int LSAPI_Set_Restored_Parent_Pid(int pid);
typedef void (*LSAPI_On_Timer_pf)(void);
void LSAPI_Register_Pgrp_Timer_Callback(LSAPI_On_Timer_pf);
int LSAPI_Inc_Req_Processed(int cnt);
#define LSAPI_LOG_LEVEL_BITS 0xff
#define LSAPI_LOG_FLAG_NONE 0
#define LSAPI_LOG_FLAG_DEBUG 1
#define LSAPI_LOG_FLAG_INFO 2
#define LSAPI_LOG_FLAG_NOTICE 3
#define LSAPI_LOG_FLAG_WARN 4
#define LSAPI_LOG_FLAG_ERROR 5
#define LSAPI_LOG_FLAG_CRIT 6
#define LSAPI_LOG_FLAG_FATAL 7
#define LSAPI_LOG_TIMESTAMP_BITS (0xff00)
#define LSAPI_LOG_TIMESTAMP_FULL (0x100)
#define LSAPI_LOG_TIMESTAMP_HMS (0x200)
#define LSAPI_LOG_PID (0x10000)
void LSAPI_Log(int flag, const char * fmt, ...)
#if __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
;
int LSAPI_is_suEXEC_Daemon();
#if defined (c_plusplus) || defined (__cplusplus)
}

1264
sapi/litespeed/lscriu.c Normal file

File diff suppressed because it is too large Load Diff

67
sapi/litespeed/lscriu.h Normal file
View File

@ -0,0 +1,67 @@
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2018 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: George Wang <gwang@litespeedtech.com> |
+----------------------------------------------------------------------+
*/
/*
Copyright (c) 2002-2018, Lite Speed Technologies Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the Lite Speed Technologies Inc nor the
names of its contributors may be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LSCRIU_H_
#define _LSCRIU_H_
#if defined (c_plusplus) || defined (__cplusplus)
extern "C" {
#endif
// return 1 if CRIU is available, return 0 if CRIU is not available
int LSCRIU_Init(void);
void LSCRIU_inc_req_procssed(void);
#if defined (c_plusplus) || defined (__cplusplus)
}
#endif
#endif // LSCRIU_