Ejemplo n.º 1
0
int ConnPool::regConn(IConnection *pConn)
{
    assert(pConn);
    if (m_freeList.full())
    {
        if (setMaxConns(m_connList.size() + 10))
            return -1;
    }
    m_connList.safe_push_back(pConn);
    return 0;
}
Ejemplo n.º 2
0
void ExtWorkerConfig::config(const XmlNode *pNode)
{
    const char *pValue;
    int iMaxConns = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                    "maxConns", 1, 2000, 1);
    int iRetryTimeout = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                        "retryTimeout", 0, LONG_MAX, 10);
    int iInitTimeout = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                       "initTimeout", 1, LONG_MAX, 3);
    int iBuffer = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                  "respBuffer", 0, 2, 1);
    int iKeepAlive = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                     "persistConn", 0, 1, 1);
    int iKeepAliveTimeout = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                            "pcKeepAliveTimeout", -1, INT_MAX, INT_MAX);

    if (iKeepAliveTimeout == -1)
        iKeepAliveTimeout = INT_MAX;

    if (iBuffer == 1)
        iBuffer = 0;
    else if (iBuffer == 0)
        iBuffer = HEC_RESP_NOBUFFER;
    else if (iBuffer == 2)
        iBuffer = HEC_RESP_NPH;

    setPersistConn(iKeepAlive);
    setKeepAliveTimeout(iKeepAliveTimeout);
    setMaxConns(iMaxConns);
    setTimeout(iInitTimeout);
    setRetryTimeout(iRetryTimeout);
    setBuffering(iBuffer);
    clearEnv();
    const XmlNodeList *pList = pNode->getChildren("env");

    if (pList)
    {
        XmlNodeList::const_iterator iter;

        for (iter = pList->begin(); iter != pList->end(); ++iter)
        {
            pValue = (*iter)->getValue();

            if (pValue)
                addEnv((*iter)->getValue());
        }
    }

}
Ejemplo n.º 3
0
int LocalWorkerConfig::checkExtAppSelfManagedAndFixEnv()
{
    static const char *instanceEnv[] =
    {
        "PHP_FCGI_CHILDREN",  "PHP_LSAPI_CHILDREN",
        "LSAPI_CHILDREN"
    };
    int selfManaged = 0;
    size_t i;
    Env *pEnv = getEnv();
    const char *pEnvValue = NULL;

    for (i = 0; i < sizeof(instanceEnv) / sizeof(char *); ++i)
    {
        pEnvValue = pEnv->find(instanceEnv[i]);

        if (pEnvValue != NULL)
            break;
    }


    if (pEnvValue)
    {
        int children = atol(pEnvValue);


        if ((children > 0) && (children * getInstances() < getMaxConns()))
        {
            LS_WARN(ConfigCtx::getCurConfigCtx(),
                    "Improper configuration: the value of "
                    "%s should not be less than 'Max "
                    "connections', 'Max connections' is reduced to %d."
                    , instanceEnv[i], children * getInstances());
            setMaxConns(children * getInstances());
        }

        selfManaged = 1;
    }

    pEnv->add(0, 0, 0, 0);
    return selfManaged;
}
Ejemplo n.º 4
0
int LocalWorkerConfig::config(const XmlNode *pNode)
{
    ServerProcessConfig &procConfig = ServerProcessConfig::getInstance();
    int selfManaged;
    int instances;
    int backlog = ConfigCtx::getCurConfigCtx()->getLongValue(pNode, "backlog",
                  1, 100, 10);
    int priority = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                   "priority", -20, 20, procConfig.getPriority() + 1);

    if (priority > 20)
        priority = 20;

    if (priority < procConfig.getPriority())
        priority = procConfig.getPriority();

    long l = ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
             "extMaxIdleTime", -1, INT_MAX, INT_MAX);

    if (l == -1)
        l = INT_MAX;

    setPriority(priority);
    setBackLog(backlog);
    setMaxIdleTime(l);


    int umakeVal = ConfigCtx::getCurConfigCtx()->getLongValue(pNode, "umask",
                   000, 0777, procConfig.getUMask(), 8);
    setUmask(umakeVal);

    setRunOnStartUp(ConfigCtx::getCurConfigCtx()->getLongValue(pNode,
                    "runOnStartUp", 0, 2, 0));

    RLimits limits;
    if (ExtAppRegistry::getRLimits() != NULL)
        limits = *(ExtAppRegistry::getRLimits());
    limits.setCPULimit(RLIM_INFINITY, RLIM_INFINITY);
    LocalWorker::configRlimit(&limits, pNode);
    setRLimits(&limits);
    Env *pEnv = getEnv();

    if (pEnv->find("PATH") == NULL)
        pEnv->add("PATH=/bin:/usr/bin");
    instances = ConfigCtx::getCurConfigCtx()->getLongValue(pNode, "instances",
                1, INT_MAX, 1);

    if (instances > 2000)
        instances = 2000;

    if (instances >
        HttpServerConfig::getInstance().getMaxFcgiInstances())
    {
        instances = HttpServerConfig::getInstance().getMaxFcgiInstances();
        LS_WARN(ConfigCtx::getCurConfigCtx(),
                "<instances> is too large, use default max:%d",
                instances);
    }
    setInstances(instances);
    selfManaged = checkExtAppSelfManagedAndFixEnv();
    setSelfManaged(selfManaged);
    if ((instances != 1) &&
        (getMaxConns() > instances))
    {
        LS_NOTICE(ConfigCtx::getCurConfigCtx(),
                  "Possible mis-configuration: 'Instances'=%d, "
                  "'Max connections'=%d, unless one Fast CGI process is "
                  "capable of handling multiple connections, "
                  "you should set 'Instances' greater or equal to "
                  "'Max connections'.", instances, getMaxConns());
        setMaxConns(instances);
    }

    RLimits *pLimits = getRLimits();
#if defined(RLIMIT_NPROC)
    int mini_nproc = (3 * getMaxConns() + 50)
                     * HttpServerConfig::getInstance().getChildren();
    struct rlimit   *pNProc = pLimits->getProcLimit();

    if (((pNProc->rlim_cur > 0) && ((int) pNProc->rlim_cur < mini_nproc))
        || ((pNProc->rlim_max > 0) && ((int) pNProc->rlim_max < mini_nproc)))
    {
        LS_NOTICE(ConfigCtx::getCurConfigCtx(),
                  "'Process Limit' probably is too low, "
                  "adjust the limit to: %d.", mini_nproc);
        pLimits->setProcLimit(mini_nproc, mini_nproc);
    }

#endif

    return 0;
}
Ejemplo n.º 5
0
int CgidWorker::config( const XmlNode *pNode1 )
{
    int iChrootlen = 0;
    const char *psChroot = NULL;

    
    if ( HttpGlobals::s_psChroot )
    {
        iChrootlen = HttpGlobals::s_psChroot->len();
        psChroot = HttpGlobals::s_psChroot->c_str();
    }
    int instances = ConfigCtx::getCurConfigCtx()->getLongValue( pNode1,
                    "maxCGIInstances", 1, 2000, 100 );
    setMaxConns( instances );
    ExtAppRegistry::setRLimits( getConfig().getRLimits());
    ExtAppRegistry::getRLimits()->reset();
    LocalWorker::configRlimit( ExtAppRegistry::getRLimits(), pNode1 );
    int priority = ConfigCtx::getCurConfigCtx()->getLongValue( pNode1, "priority", -20, 20, HttpGlobals::s_priority + 1 );

    if ( priority > 20 )
        priority = 20;

    if ( priority < HttpGlobals::s_priority )
        priority = HttpGlobals::s_priority;

    char achSocket[128];
    const char *pValue = pNode1->getChildValue( "cgidSock" );

    if ( !pValue )
    {
        snprintf( achSocket, 128, "uds:/%s%sadmin/cgid/cgid.sock",
                  ( iChrootlen ) ? psChroot : "",
                  HttpGlobals::s_pServerRoot );
    }
    else
    {
        strcpy( achSocket, "uds:/" );

        if ( strncasecmp( "uds:/", pValue, 5 ) == 0 )
            pValue += 5;

        if ( ( iChrootlen ) &&
                ( strncmp( pValue, psChroot, iChrootlen ) == 0 ) )
        {
            pValue += iChrootlen;
        }

        snprintf( achSocket, 128, "uds:/%s%s",
                  ( iChrootlen) ? psChroot : "",
                  pValue );
    }

    getConfig().setSocket( achSocket );
    getConfig().setPriority( priority );
    getConfig().setMaxConns( instances );
    getConfig().setRetryTimeout( 0 );
    getConfig().setBuffering( HEC_RESP_NOBUFFER );
    getConfig().setTimeout( HttpServerConfig::getInstance().getConnTimeout() );
    HttpGlobals::s_uidMin = ConfigCtx::getCurConfigCtx()->getLongValue( pNode1, "minUID", 10, INT_MAX, 10 );
    HttpGlobals::s_gidMin = ConfigCtx::getCurConfigCtx()->getLongValue( pNode1, "minGID", 5, INT_MAX, 5 );
    uid_t forcedGid = ConfigCtx::getCurConfigCtx()->getLongValue( pNode1, "forceGID", 0, INT_MAX, 0 );

    if ( ( forcedGid > 0 ) && ( forcedGid < HttpGlobals::s_gidMin ) )
    {
        ConfigCtx::getCurConfigCtx()->log_warn( "\"Force GID\" is smaller than \"Minimum GID\", turn it off." );
    }
    else
        HttpGlobals::s_ForceGid = forcedGid;

    char achMIME[] = "application/x-httpd-cgi";
    HttpGlobals::getMime()->addMimeHandler( "", achMIME,
                                            HandlerFactory::getInstance( HandlerType::HT_CGI, NULL ), NULL,  LogIdTracker::getLogId() );


//    char achMIME_SSI[] = "application/x-httpd-shtml";
//    HttpGlobals::getMime()->addMimeHandler( "", achMIME_SSI,
//                                            HandlerFactory::getInstance( HandlerType::HT_SSI, NULL ), NULL,  LogIdTracker::getLogId() );

    HttpGlobals::s_pidCgid = start( HttpGlobals::s_pServerRoot , psChroot,
                             HttpGlobals::s_uid, HttpGlobals::s_gid, HttpGlobals::s_priority );
    return HttpGlobals::s_pidCgid;
}
Ejemplo n.º 6
0
int CgidWorker::config(const XmlNode *pNode1)
{
    int iChrootlen = 0;
    const char *psChroot = NULL;
    ServerProcessConfig &procConfig = ServerProcessConfig::getInstance();

    if (procConfig.getChroot() != NULL)
    {
        iChrootlen = procConfig.getChroot()->len();
        psChroot = procConfig.getChroot()->c_str();
    }
    int instances = ConfigCtx::getCurConfigCtx()->getLongValue(pNode1,
                    "maxCGIInstances", 1, 2000, 100);
    setMaxConns(instances);
    ExtAppRegistry::setRLimits(getConfig().getRLimits());
    ExtAppRegistry::getRLimits()->reset();
    LocalWorker::configRlimit(ExtAppRegistry::getRLimits(), pNode1);
    int priority = ConfigCtx::getCurConfigCtx()->getLongValue(pNode1,
                   "priority", -20, 20, procConfig.getPriority() + 1);

    if (priority > 20)
        priority = 20;

    if (priority < procConfig.getPriority())
        priority = procConfig.getPriority();

    char achSocket[128];
    const char *pValue = pNode1->getChildValue("cgidSock");

    if (!pValue)
    {
        snprintf(achSocket, 128, "uds:/%s%sadmin/cgid/cgid.sock",
                 (iChrootlen) ? psChroot : "",
                 MainServerConfig::getInstance().getServerRoot());
    }
    else
    {
        strcpy(achSocket, "uds:/");

        if (strncasecmp("uds:/", pValue, 5) == 0)
            pValue += 5;

        if ((iChrootlen) &&
            (strncmp(pValue, psChroot, iChrootlen) == 0))
            pValue += iChrootlen;

        snprintf(achSocket, 128, "uds:/%s%s",
                 (iChrootlen) ? psChroot : "",
                 pValue);
    }

    getConfig().setSocket(achSocket);
    getConfig().setPriority(priority);
    getConfig().setMaxConns(instances);
    getConfig().setRetryTimeout(0);
    getConfig().setBuffering(HEC_RESP_NOBUFFER);
    getConfig().setTimeout(HttpServerConfig::getInstance().getConnTimeout());
    procConfig.setUidMin(ConfigCtx::getCurConfigCtx()->getLongValue(pNode1,
                         "minUID", 10, INT_MAX, 10));
    procConfig.setGidMin(ConfigCtx::getCurConfigCtx()->getLongValue(pNode1,
                         "minGID", 5, INT_MAX, 5));
    uid_t forcedGid = ConfigCtx::getCurConfigCtx()->getLongValue(pNode1,
                      "forceGID", 0, INT_MAX, 0);

    if ((forcedGid > 0) && (forcedGid < procConfig.getGidMin()))
        LS_WARN(ConfigCtx::getCurConfigCtx(),
                "\"Force GID\" is smaller than \"Minimum GID\", turn it off.");
    else
        procConfig.setForceGid(forcedGid);

    char achMIME[] = "application/x-httpd-cgi";
    HttpMime::getMime()->addMimeHandler("", achMIME,
                                        HandlerFactory::getInstance(HandlerType::HT_CGI, NULL), NULL,
                                        TmpLogId::getLogId());


//    char achMIME_SSI[] = "application/x-httpd-shtml";
//    HttpMime::getMime()->addMimeHandler( "", achMIME_SSI,
//                                            HandlerFactory::getInstance( HandlerType::HT_SSI, NULL ), NULL,  LogIdTracker::getLogId() );

    CgidWorker::setCgidWorkerPid(
        start(MainServerConfig::getInstance().getServerRoot(), psChroot,
              procConfig.getUid(), procConfig.getGid(),
              procConfig.getPriority()));
    return CgidWorker::getCgidWorkerPid();
}