diff options
Diffstat (limited to 'sapi/litespeed/lsapilib.c')
| -rw-r--r-- | sapi/litespeed/lsapilib.c | 240 |
1 files changed, 120 insertions, 120 deletions
diff --git a/sapi/litespeed/lsapilib.c b/sapi/litespeed/lsapilib.c index daf0f37f14..53d9def952 100644 --- a/sapi/litespeed/lsapilib.c +++ b/sapi/litespeed/lsapilib.c @@ -22,18 +22,18 @@ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are -met: +met: * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + 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. + 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. + written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -45,7 +45,7 @@ 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. +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -153,7 +153,7 @@ static const char *CGI_HEADERS[H_TRANSFER_ENCODING+1] = "HTTP_VIA", "HTTP_TRANSFER_ENCODING" }; - + static int CGI_HEADER_LEN[H_TRANSFER_ENCODING+1] = { 11, 19, 20, 20, 18, 15, 12, 14, 11, 12, 9, 11, 12, 15, 18, 22, 13, 18, 13, 24, 15, 10, 20, 8, 22 }; @@ -184,7 +184,7 @@ static int HTTP_HEADER_LEN[H_TRANSFER_ENCODING+1] = { 6, 14, 15, 15, 13, 10, 12, 14, 6, 7, 4, 6, 7, 10, //user-agent 13,17, 8, 13, 8, 19, 10, 5, 15, 3, 17 }; - + static void lsapi_sigpipe( int sig ) { } @@ -196,7 +196,7 @@ static void lsapi_siguser1( int sig ) #ifndef sighandler_t typedef void (*sighandler_t)(int); #endif - + static void lsapi_signal(int signo, sighandler_t handler) { struct sigaction sa; @@ -219,7 +219,7 @@ static void lsapi_enable_core_dump() #if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__) \ || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) int mib[2]; - size_t len; + size_t len; len = 2; if ( sysctlnametomib("kern.sugid_coredump", mib, &len) == 0 ) @@ -230,7 +230,7 @@ static void lsapi_enable_core_dump() "core dump may not be available!"); } - + #endif #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) @@ -511,7 +511,7 @@ static inline void swapIntEndian( int * pInteger ) b = p[1]; p[1] = p[2]; p[2] = b; - + } static inline void fixEndian( LSAPI_Request * pReq ) @@ -586,7 +586,7 @@ static int lsapi_load_lve_lib() if (s_liblve) { fp_lve_is_available = dlsym(s_liblve, "lve_is_available"); - if (dlerror() == NULL) + if (dlerror() == NULL) { if ( !(*fp_lve_is_available)() ) { @@ -612,7 +612,7 @@ static int init_lve_ex() { int rc; if ( !s_liblve ) - return -1; + return -1; fp_lve_instance_init = dlsym(s_liblve, "lve_instance_init"); fp_lve_destroy = dlsym(s_liblve, "lve_destroy"); fp_lve_enter = dlsym(s_liblve, "lve_enter"); @@ -620,13 +620,13 @@ static int init_lve_ex() if ( s_enable_lve >= LSAPI_CAGEFS_ENABLED ) fp_lve_jail = dlsym(s_liblve, "jail" ); - if ( s_lve == NULL ) + if ( s_lve == NULL ) { rc = (*fp_lve_instance_init)(NULL); s_lve = malloc(rc); } rc = (*fp_lve_instance_init)(s_lve); - if (rc != 0) + if (rc != 0) { perror( "LSAPI: Unable to initialize LVE" ); free( s_lve ); @@ -634,7 +634,7 @@ static int init_lve_ex() return -1; } return 0; - + } #endif @@ -701,7 +701,7 @@ static int LSAPI_perror_r( LSAPI_Request * pReq, const char * pErr1, const char static int lsapi_lve_error( LSAPI_Request * pReq ) { - static const char * headers[] = + static const char * headers[] = { "Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0", "Pragma: no-cache", @@ -717,7 +717,7 @@ static int lsapi_lve_error( LSAPI_Request * pReq ) "Please try again later.\n" "<HR>\n" "</BODY></HTML>\n"; - + LSAPI_ErrResponse_r( pReq, 508, headers, achBody, sizeof( achBody ) - 1 ); return 0; } @@ -751,7 +751,7 @@ static int lsapi_jailLVE( LSAPI_Request * pReq, uid_t uid, struct passwd * pw ) ret = (*fp_lve_jail)( pw, error_msg ); if ( ret < 0 ) { - fprintf( stderr, "LSAPI (%d): LVE jail(%d) ressult: %d, error: %s !\n", + fprintf( stderr, "LSAPI (%d): LVE jail(%d) ressult: %d, error: %s !\n", getpid(), uid, ret, error_msg ); LSAPI_perror_r( pReq, "LSAPI: jail() failure.", NULL ); return -1; @@ -796,7 +796,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p pw = getpwuid( uid ); #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) if ( s_lve ) - { + { if( lsapi_enterLVE( pReq, uid ) == -1 ) return -1; if ( pw && fp_lve_jail) @@ -813,7 +813,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p } } #endif - //if ( !uid || !gid ) //do not allow root + //if ( !uid || !gid ) //do not allow root //{ // return -1; //} @@ -869,7 +869,7 @@ static int setUID_LVE(LSAPI_Request * pReq, uid_t uid, gid_t gid, const char * p return 0; } -static int lsapi_suexec_auth( LSAPI_Request *pReq, +static int lsapi_suexec_auth( LSAPI_Request *pReq, char * pAuth, int len, char * pUgid, int ugidLen ) { lsapi_MD5_CTX md5ctx; @@ -901,7 +901,7 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) //with special ID 0x00 //authenticate the suEXEC request; //first one should be MD5( nonce + lscgid secret ) - //remember to clear the secret after verification + //remember to clear the secret after verification //it should be set at the end of special env i = pReq->m_pHeader->m_cntSpecialEnv - 1; if ( i >= 0 ) @@ -917,7 +917,7 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) { --pReq->m_pHeader->m_cntSpecialEnv; uid = *(uint32_t *)pEnv->pValue; - gid = *(((uint32_t *)pEnv->pValue) + 1 ); + gid = *(((uint32_t *)pEnv->pValue) + 1 ); //fprintf( stderr, "LSAPI: SUEXEC_UGID set UID: %d, GID: %d\n", uid, gid ); } else @@ -927,8 +927,8 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) } if ( pEnv&& lsapi_suexec_auth( pReq, pAuth->pValue, pAuth->valLen, pEnv->pValue, pEnv->valLen ) == 0 ) { - //read UID, GID from specialEnv - + //read UID, GID from specialEnv + } else { @@ -956,10 +956,10 @@ static int lsapi_changeUGid( LSAPI_Request * pReq ) return -1; } - s_uid = uid; + s_uid = uid; return 0; - + } static int parseContentLenFromHeader(LSAPI_Request * pReq) @@ -1004,7 +1004,7 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen ) pReq->m_pScriptName = pReq->m_pReqBuf + pReq->m_pHeader->m_scriptNameOff; pReq->m_pQueryString = pReq->m_pReqBuf + pReq->m_pHeader->m_queryStringOff; pReq->m_pRequestMethod = pReq->m_pReqBuf + pReq->m_pHeader->m_requestMethodOff; - + pBegin = pReq->m_pReqBuf + (( pBegin - pReq->m_pReqBuf + 7 ) & (~0x7)); pReq->m_pHeaderIndex = ( struct lsapi_http_header_index * )pBegin; pBegin += sizeof( struct lsapi_http_header_index ); @@ -1030,7 +1030,7 @@ static int parseRequest( LSAPI_Request * pReq, int totalLen ) { parseContentLenFromHeader(pReq); } - + return 0; } @@ -1088,7 +1088,7 @@ static inline int lsapi_notify_pid( int fd ) 8 + LSAPI_PACKET_HEADER_LEN ); memmove( &achBuf[8], "\0PID", 4 ); *((int *)&achBuf[12]) = getpid(); - + if ( write( fd, achBuf, 16 ) < 16 ) return -1; return 0; @@ -1112,7 +1112,7 @@ static inline int init_conn_key( int fd ) < LSAPI_PACKET_HEADER_LEN+8 ) return -1; return 0; - + } @@ -1198,9 +1198,9 @@ int LSAPI_Init(void) #if defined(SIGXFSZ) && defined(SIG_IGN) signal(SIGXFSZ, SIG_IGN); #endif - /* let STDOUT function as STDERR, + /* let STDOUT function as STDERR, just in case writing to STDOUT directly */ - dup2( 2, 1 ); + dup2( 2, 1 ); if ( LSAPI_InitRequest( &g_req, LSAPI_SOCK_FILENO ) == -1 ) return -1; g_inited = 1; @@ -1240,8 +1240,8 @@ int LSAPI_InitRequest( LSAPI_Request * pReq, int fd ) { fd = dup( fd ); newfd = open( "/dev/null", O_RDWR ); - dup2( newfd, STDIN_FILENO ); - } + dup2( newfd, STDIN_FILENO ); + } if ( isPipe( fd ) ) { @@ -1274,7 +1274,7 @@ int LSAPI_Accept_r( LSAPI_Request * pReq ) char achPeer[128]; socklen_t len; int nodelay = 1; - + if ( !pReq ) return -1; if ( LSAPI_Finish_r( pReq ) == -1 ) @@ -1300,7 +1300,7 @@ int LSAPI_Accept_r( LSAPI_Request * pReq ) { lsapi_set_nblock( pReq->m_fd , 0 ); if (((struct sockaddr *)&achPeer)->sa_family == AF_INET ) - { + { setsockopt(pReq->m_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay)); } @@ -1344,7 +1344,7 @@ int LSAPI_Finish_r( LSAPI_Request * pReq ) { Flush_RespBuf_r( pReq ); } - + pReq->m_pIovecCur->iov_base = (void *)&finish; pReq->m_pIovecCur->iov_len = LSAPI_PACKET_HEADER_LEN; pReq->m_totalLen += LSAPI_PACKET_HEADER_LEN; @@ -1362,7 +1362,7 @@ void LSAPI_Reset_r( LSAPI_Request * pReq ) pReq->m_pRespBufPos = pReq->m_pRespBuf; pReq->m_pIovecCur = pReq->m_pIovecToWrite = pReq->m_pIovec + 1; pReq->m_pRespHeaderBufPos = pReq->m_pRespHeaderBuf; - + memset( &pReq->m_pHeaderIndex, 0, (char *)(pReq->m_respHeaderLen) - (char *)&pReq->m_pHeaderIndex ); } @@ -1377,7 +1377,7 @@ int LSAPI_Release_r( LSAPI_Request * pReq ) if ( pReq->m_pEnvList ) free( pReq->m_pEnvList ); if ( pReq->m_pRespHeaderBuf ) - free( pReq->m_pRespHeaderBuf ); + free( pReq->m_pRespHeaderBuf ); return 0; } @@ -1390,9 +1390,9 @@ char * LSAPI_GetHeader_r( LSAPI_Request * pReq, int headerIndex ) off = pReq->m_pHeaderIndex->m_headerOff[ headerIndex ]; if ( !off ) return NULL; - if ( *(pReq->m_pHttpHeader + off + + if ( *(pReq->m_pHttpHeader + off + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) ) - *( pReq->m_pHttpHeader + off + + *( pReq->m_pHttpHeader + off + pReq->m_pHeaderIndex->m_headerLen[ headerIndex ]) = 0; return pReq->m_pHttpHeader + off; } @@ -1411,7 +1411,7 @@ static int readBodyToReqBuf( LSAPI_Request * pReq ) return -1; if ( len > bodyLeft ) len = bodyLeft; - + len = lsapi_read( pReq->m_fd, pReq->m_pReqBuf + pReq->m_bufRead, len ); if ( len > 0 ) pReq->m_bufRead += len; @@ -1447,7 +1447,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in *getLF = 0; while( (left = pBufEnd - pBufCur ) > 0 ) { - + len = pReq->m_bufRead - pReq->m_bufProcessed; if ( len <= 0 ) { @@ -1468,7 +1468,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in pReq->m_bufProcessed += len; pReq->m_reqBodyRead += len; - + if ( p ) { *getLF = 1; @@ -1476,7 +1476,7 @@ int LSAPI_ReqBodyGetLine_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen, in } } *pBufCur = 0; - + return pBufCur - pBuf; } @@ -1490,7 +1490,7 @@ ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen ) return -1; total = pReq->m_reqBodyLen - pReq->m_reqBodyRead; - + if ( total <= 0 ) return 0; if ( total < bufLen ) @@ -1526,7 +1526,7 @@ ssize_t LSAPI_ReadReqBody_r( LSAPI_Request * pReq, char * pBuf, size_t bufLen ) } pReq->m_reqBodyRead += total; return total; - + } @@ -1539,7 +1539,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) ssize_t toWrite; ssize_t packetLen; int skip = 0; - + if ( !pReq || !pBuf || (pReq->m_fd == -1) ) return -1; if ( pReq->m_reqState & LSAPI_ST_RESP_HEADER ) @@ -1564,13 +1564,13 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) pReq->m_pRespBufPos += len - skip; return len; } - - + + pHeader = pReq->m_respPktHeader; p = pBuf + skip; pEnd = pBuf + len; bufLen = pReq->m_pRespBufPos - pReq->m_pRespBuf; - + while( ( toWrite = pEnd - p ) > 0 ) { packetLen = toWrite + bufLen; @@ -1579,7 +1579,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) packetLen = LSAPI_MAX_DATA_PACKET_LEN; toWrite = packetLen - bufLen; } - + lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM, packetLen + LSAPI_PACKET_HEADER_LEN ); pReq->m_totalLen += packetLen + LSAPI_PACKET_HEADER_LEN; @@ -1593,7 +1593,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; pReq->m_pIovecCur->iov_len = bufLen; pReq->m_pRespBufPos = pReq->m_pRespBuf; - ++pReq->m_pIovecCur; + ++pReq->m_pIovecCur; bufLen = 0; } @@ -1615,7 +1615,7 @@ ssize_t LSAPI_Write_r( LSAPI_Request * pReq, const char * pBuf, size_t len ) return p - pBuf; } -#if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__ ) || defined(__NetBSD__) || defined(__OpenBSD__) ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size ) { ssize_t ret; @@ -1644,7 +1644,7 @@ ssize_t gsendfile( int fdOut, int fdIn, off_t* off, size_t size ) return ret; } #endif - + #if defined(sun) || defined(__sun) #include <sys/sendfile.h> ssize_t gsendfile( int fdOut, int fdIn, off_t *off, size_t size ) @@ -1690,16 +1690,16 @@ ssize_t LSAPI_sendfile_r( LSAPI_Request * pReq, int fdIn, off_t* off, size_t siz LSAPI_FinalizeRespHeaders_r( pReq ); } pReq->m_reqState |= LSAPI_ST_RESP_BODY; - + LSAPI_Flush_r(pReq); - + lsapi_buildPacketHeader( pHeader, LSAPI_RESP_STREAM, size + LSAPI_PACKET_HEADER_LEN ); - + if (write(pReq->m_fd, (const char *) pHeader, LSAPI_PACKET_HEADER_LEN ) != LSAPI_PACKET_HEADER_LEN) return -1; - + return gsendfile( pReq->m_fd, fdIn, off, size ); } @@ -1722,7 +1722,7 @@ void Flush_RespBuf_r( LSAPI_Request * pReq ) pReq->m_pIovecCur->iov_base = (void *)pReq->m_pRespBuf; pReq->m_pIovecCur->iov_len = bufLen; pReq->m_pRespBufPos = pReq->m_pRespBuf; - ++pReq->m_pIovecCur; + ++pReq->m_pIovecCur; bufLen = 0; } } @@ -1754,11 +1754,11 @@ int LSAPI_Flush_r( LSAPI_Request * pReq ) { Flush_RespBuf_r( pReq ); } - + n = pReq->m_pIovecCur - pReq->m_pIovecToWrite; if ( n > 0 ) { - + ret = lsapi_writev( pReq->m_fd, &pReq->m_pIovecToWrite, n, pReq->m_totalLen ); if ( ret < pReq->m_totalLen ) @@ -1784,7 +1784,7 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le int ret; struct iovec iov[2]; struct iovec *pIov; - + if ( !pReq ) return -1; if (( pReq->m_fd == -1 )||(pReq->m_fd == pReq->m_fdListen )) @@ -1793,7 +1793,7 @@ ssize_t LSAPI_Write_Stderr_r( LSAPI_Request * pReq, const char * pBuf, size_t le { LSAPI_Flush_r( pReq ); } - + p = pBuf; pEnd = pBuf + len; @@ -1900,7 +1900,7 @@ struct _headerInfo int compareValueLocation(const void * v1, const void *v2 ) { return ((const struct _headerInfo *)v1)->_value - - ((const struct _headerInfo *)v2)->_value; + ((const struct _headerInfo *)v2)->_value; } int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, @@ -1931,7 +1931,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, headers[count]._value = pValue; headers[count]._valueLen = len; ++count; - + //ret = (*fn)( HTTP_HEADERS[i], HTTP_HEADER_LEN[i], // pValue, len, arg ); //if ( ret <= 0 ) @@ -1960,7 +1960,7 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, ++count; if ( count == 512 ) break; - //ret = (*fn)( pKey, keyLen, + //ret = (*fn)( pKey, keyLen, // pValue, pCur->valueLen, arg ); //if ( ret <= 0 ) // return ret; @@ -1970,13 +1970,13 @@ int LSAPI_ForeachOrgHeader_r( LSAPI_Request * pReq, qsort( headers, count, sizeof( struct _headerInfo ), compareValueLocation ); for( i = 0; i < count; ++i ) { - ret = (*fn)( headers[i]._name, headers[i]._nameLen, + ret = (*fn)( headers[i]._name, headers[i]._nameLen, headers[i]._value, headers[i]._valueLen, arg ); if ( ret <= 0 ) return ret; } return count; - + } @@ -2037,7 +2037,7 @@ int LSAPI_ForeachHeader_r( LSAPI_Request * pReq, pValue = pReq->m_pHttpHeader + pCur->valueOff; *(pValue + pCur->valueLen ) = 0; - ret = (*fn)( achHeaderName, keyLen, + ret = (*fn)( achHeaderName, keyLen, pValue, pCur->valueLen, arg ); if ( ret <= 0 ) return ret; @@ -2045,7 +2045,7 @@ int LSAPI_ForeachHeader_r( LSAPI_Request * pReq, } } return count + pReq->m_pHeader->m_cntUnknownHeaders; - + } static int EnvForeach( struct LSAPI_key_value_pair * pEnv, @@ -2114,7 +2114,7 @@ int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq ) pReq->m_totalLen += pReq->m_pIovecCur->iov_len; ++pReq->m_pIovecCur; } - + pReq->m_pIovec->iov_len = sizeof( struct lsapi_resp_header) + pReq->m_respHeader.m_respInfo.m_cntHeaders * sizeof( short ); pReq->m_totalLen += pReq->m_pIovec->iov_len; @@ -2127,11 +2127,11 @@ int LSAPI_FinalizeRespHeaders_r( LSAPI_Request * pReq ) } -int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName, +int LSAPI_AppendRespHeader2_r( LSAPI_Request * pReq, const char * pHeaderName, const char * pHeaderValue ) { int nameLen, valLen, len; - if ( !pReq || !pHeaderName || !pHeaderValue ) + if ( !pReq || !pHeaderName || !pHeaderValue ) return -1; if ( pReq->m_reqState & LSAPI_ST_RESP_BODY ) return -1; @@ -2275,7 +2275,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) struct addrinfo *res, hints; int doAddrInfo = 0; int port; - + if ( !pBind ) return -1; @@ -2299,7 +2299,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) if ( !pEnd ) return -1; *pEnd++ = 0; - + if ( *p == '*' ) { strcpy( achAddr, "::" ); @@ -2314,7 +2314,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) if ( !pEnd ) return -1; *pEnd++ = 0; - + doAddrInfo = 0; if ( *p == '*' ) { @@ -2334,7 +2334,7 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) } if ( *pEnd == ':' ) ++pEnd; - + port = atoi( pEnd ); if (( port <= 0 )||( port > 65535 )) return -1; @@ -2355,13 +2355,13 @@ int LSAPI_ParseSockAddr( const char * pBind, struct sockaddr * pAddr ) memcpy(pAddr, res->ai_addr, res->ai_addrlen); freeaddrinfo(res); } - + if ( pAddr->sa_family == AF_INET ) ((struct sockaddr_in *)pAddr)->sin_port = htons( port ); else ((struct sockaddr_in6 *)pAddr)->sin6_port = htons( port ); return 0; - + } int LSAPI_CreateListenSock( const char * pBind, int backlog ) @@ -2407,11 +2407,11 @@ typedef struct _lsapi_prefork_server int m_iChildrenMaxIdleTime; int m_iMaxReqProcessTime; int m_iAvoidFork; - + lsapi_child_status * m_pChildrenStatus; lsapi_child_status * m_pChildrenStatusCur; lsapi_child_status * m_pChildrenStatusEnd; - + }lsapi_prefork_server; static lsapi_prefork_server * g_prefork_server = NULL; @@ -2426,7 +2426,7 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork ) if ( max_children >= 10000) max_children = 10000; - + g_prefork_server = (lsapi_prefork_server *)malloc( sizeof( lsapi_prefork_server ) ); if ( !g_prefork_server ) return -1; @@ -2440,14 +2440,14 @@ int LSAPI_Init_Prefork_Server( int max_children, fn_select_t fp, int avoidFork ) setpgid( pid, pid ); g_prefork_server->m_iAvoidFork = avoidFork; g_prefork_server->m_iMaxChildren = max_children; - + g_prefork_server->m_iExtraChildren = ( avoidFork ) ? 0 : (max_children / 3) ; g_prefork_server->m_iMaxIdleChildren = ( avoidFork ) ? (max_children + 1) : (max_children / 3); if ( g_prefork_server->m_iMaxIdleChildren == 0 ) g_prefork_server->m_iMaxIdleChildren = 1; g_prefork_server->m_iChildrenMaxIdleTime = 300; g_prefork_server->m_iMaxReqProcessTime = 3600; - return 0; + return 0; } void LSAPI_Set_Server_fd( int fd ) @@ -2554,7 +2554,7 @@ static void lsapi_sigchild( int signal ) static int lsapi_init_children_status() { int size = 4096; - + char * pBuf; size = (g_prefork_server->m_iMaxChildren + g_prefork_server->m_iExtraChildren ) * sizeof( lsapi_child_status ) * 2; size = (size + 4095 ) / 4096 * 4096; @@ -2582,9 +2582,9 @@ static void dump_debug_info( lsapi_child_status * pStatus, long tmCur ) } s_pid_dump_debug_info = fork(); - fprintf( stderr, "[%s] Possible runaway process, PPID: %d, PID: %d, reqCount: %d, process time: %ld, checkpoint time: %ld, start time: %ld\n", - ctime(&tmCur), getpid(), pStatus->m_pid, pStatus->m_iReqCounter, - tmCur - pStatus->m_tmReqBegin, tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart ); + fprintf( stderr, "[%s] Possible runaway process, PPID: %d, PID: %d, reqCount: %d, process time: %ld, checkpoint time: %ld, start time: %ld\n", + ctime(&tmCur), getpid(), pStatus->m_pid, pStatus->m_iReqCounter, + tmCur - pStatus->m_tmReqBegin, tmCur - pStatus->m_tmLastCheckPoint, tmCur - pStatus->m_tmStart ); snprintf( achCmd, 1024, "gdb --batch -ex \"attach %d\" -ex \"set height 0\" -ex \"bt\" >&2;PATH=$PATH:/usr/sbin lsof -p %d >&2", pStatus->m_pid, pStatus->m_pid ); if ( system( achCmd ) == -1 ) perror( "system()" ); @@ -2607,7 +2607,7 @@ static void lsapi_check_child_status( long tmCur ) ++count; if ( !pStatus->m_inProcess ) { - + if (( g_prefork_server->m_iCurChildren - dying > g_prefork_server->m_iMaxChildren)|| ( idle > g_prefork_server->m_iMaxIdleChildren )) { @@ -2627,7 +2627,7 @@ static void lsapi_check_child_status( long tmCur ) } else { - if ( tmCur - pStatus->m_tmReqBegin > + if ( tmCur - pStatus->m_tmReqBegin > g_prefork_server->m_iMaxReqProcessTime ) { if (( ( pStatus->m_iKillSent % 5 ) == 0 )&&( s_dump_debug_info )) @@ -2662,7 +2662,7 @@ static void lsapi_check_child_status( long tmCur ) } if ( abs( g_prefork_server->m_iCurChildren - count ) > 1 ) { - fprintf( stderr, "Children tracking is wrong: PID: %d, Cur Children: %d, count: %d, idle: %d, dying: %d\n", getpid(), + fprintf( stderr, "Children tracking is wrong: PID: %d, Cur Children: %d, count: %d, idle: %d, dying: %d\n", getpid(), g_prefork_server->m_iCurChildren, count, idle, dying ); } @@ -2706,7 +2706,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re sigset_t orig_mask; lsapi_init_children_status(); - + setsid(); act.sa_flags = 0; @@ -2796,17 +2796,17 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re sigemptyset( &mask ); sigaddset( &mask, SIGCHLD ); - - if ( sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0 ) + + if ( sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0 ) { perror( "sigprocmask(SIG_BLOCK) to block SIGCHLD" ); } pid = fork(); - + if ( !pid ) { - if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) + if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK in child" ); g_prefork_server = NULL; s_ppid = getppid(); @@ -2848,7 +2848,7 @@ static int lsapi_prefork_server_accept( lsapi_prefork_server * pServer, LSAPI_Re close( pReq->m_fd ); pReq->m_fd = -1; - if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) + if (sigprocmask(SIG_SETMASK, &orig_mask, NULL) < 0) perror( "sigprocmask( SIG_SETMASK ) to restore SIGMASK" ); } @@ -2897,7 +2897,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) s_pChildStatus->m_tmWaitBegin = time( NULL ); } - + while( g_running ) { if ( pReq->m_fd != -1 ) @@ -2916,7 +2916,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) if ( !g_running ) return -1; if ((s_req_processed)&&( s_pChildStatus )&&( s_pChildStatus->m_iKillSent )) - return -1; + return -1; FD_ZERO( &readfds ); FD_SET( fd, &readfds ); timeout.tv_sec = 1; @@ -2944,7 +2944,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) else if ( ret >= 1 ) { if (s_req_processed && ( s_pChildStatus )&&( s_pChildStatus->m_iKillSent )) - return -1; + return -1; if ( fd == pReq->m_fdListen ) { pReq->m_fd = lsapi_accept( pReq->m_fdListen ); @@ -2992,7 +2992,7 @@ int LSAPI_Prefork_Accept_r( LSAPI_Request * pReq ) LSAPI_Reset_r( pReq ); } return -1; - + } void LSAPI_Set_Max_Reqs( int reqs ) @@ -3061,19 +3061,19 @@ static void unset_lsapi_envs() #else env = environ; #endif - while( env != NULL && *env != NULL ) + while( env != NULL && *env != NULL ) { - if (!strncmp(*env, "LSAPI_", 6) || !strncmp( *env, "PHP_LSAPI_", 10 ) - || (!strncmp( *env, "PHPRC=", 6 )&&(!s_uid))) - { + if (!strncmp(*env, "LSAPI_", 6) || !strncmp( *env, "PHP_LSAPI_", 10 ) + || (!strncmp( *env, "PHPRC=", 6 )&&(!s_uid))) + { char ** del = env; - do + do *del = del[1]; while( *del++ ); } else ++env; - } + } } static int lsapi_initSuEXEC() @@ -3100,7 +3100,7 @@ static int lsapi_initSuEXEC() } p = getenv( "LSAPI_SECRET" ); if (( !p )||( readSecret(p) == -1 )) - return -1; + return -1; if ( g_prefork_server ) { if ( g_prefork_server->m_iMaxChildren < 100 ) @@ -3140,7 +3140,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) if ( p ) { avoidFork = atoi( p ); - } + } p = getenv( "LSAPI_ACCEPT_NOTIFY" ); if ( p ) @@ -3149,7 +3149,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) } p = getenv( "LSAPI_SLOW_REQ_MSECS" ); - if ( p ) + if ( p ) { n = atoi( p ); LSAPI_Set_Slow_Req_Msecs( n ); @@ -3199,26 +3199,26 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) p = getenv( "LSAPI_EXTRA_CHILDREN" ); if ( p ) LSAPI_Set_Extra_Children( atoi( p ) ); - + p = getenv( "LSAPI_MAX_IDLE_CHILDREN" ); if ( p ) LSAPI_Set_Max_Idle_Children( atoi( p ) ); - + p = getenv( "LSAPI_PGRP_MAX_IDLE" ); if ( p ) { LSAPI_Set_Server_Max_Idle_Secs( atoi( p ) ); } - + p = getenv( "LSAPI_MAX_PROCESS_TIME" ); - if ( p ) + if ( p ) LSAPI_Set_Max_Process_Time( atoi( p ) ); - + if ( getenv( "LSAPI_PPID_NO_CHECK" ) ) { LSAPI_No_Check_ppid(); } - + p = getenv( "LSAPI_DUMP_DEBUG_INFO" ); if ( p ) s_dump_debug_info = atoi( p ); @@ -3234,7 +3234,7 @@ int LSAPI_Init_Env_Parameters( fn_select_t fp ) } -int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders, +int LSAPI_ErrResponse_r( LSAPI_Request * pReq, int code, const char ** pRespHeaders, const char * pBody, int bodyLen ) { LSAPI_SetRespStatus_r( pReq, code ); |
