Beispiel #1
0
Group::Group(const SuperGroupPtr &_superGroup, const Options &options, const ComponentInfo &info)
	: superGroup(_superGroup),
	  name(_superGroup->name + "#" + info.name),
	  secret(generateSecret(_superGroup)),
	  componentInfo(info)
{
	enabledCount   = 0;
	disablingCount = 0;
	disabledCount  = 0;
	spawner        = getPool()->spawnerFactory->create(options);
	restartsInitiated = 0;
	processesBeingSpawned = 0;
	m_spawning     = false;
	m_restarting   = false;
	lifeStatus     = ALIVE;
	if (options.restartDir.empty()) {
		restartFile = options.appRoot + "/tmp/restart.txt";
		alwaysRestartFile = options.appRoot + "/tmp/always_restart.txt";
	} else if (options.restartDir[0] == '/') {
		restartFile = options.restartDir + "/restart.txt";
		alwaysRestartFile = options.restartDir + "/always_restart.txt";
	} else {
		restartFile = options.appRoot + "/" + options.restartDir + "/restart.txt";
		alwaysRestartFile = options.appRoot + "/" + options.restartDir + "/always_restart.txt";
	}
	resetOptions(options);

	detachedProcessesCheckerActive = false;
}
Group::Group(Pool *_pool, const Options &_options)
	: pool(_pool),
	  uuid(generateUuid(_pool))
{
	info.context = _pool->getContext();
	info.group = this;
	info.name = _options.getAppGroupName().toString();
	generateSecret(_pool, info.secret);
	resetOptions(_options);
	enabledCount   = 0;
	disablingCount = 0;
	disabledCount  = 0;
	nEnabledProcessesTotallyBusy = 0;
	spawner        = getContext()->getSpawningKitFactory()->create(options);
	restartsInitiated = 0;
	processesBeingSpawned = 0;
	m_spawning     = false;
	m_restarting   = false;
	lifeStatus.store(ALIVE, boost::memory_order_relaxed);
	lastRestartFileMtime = 0;
	lastRestartFileCheckTime = 0;
	alwaysRestartFileExists = false;
	if (options.restartDir.empty()) {
		restartFile = options.appRoot + "/tmp/restart.txt";
		alwaysRestartFile = options.appRoot + "/tmp/always_restart.txt";
	} else if (options.restartDir[0] == '/') {
		restartFile = options.restartDir + "/restart.txt";
		alwaysRestartFile = options.restartDir + "/always_restart.txt";
	} else {
		restartFile = options.appRoot + "/" + options.restartDir + "/restart.txt";
		alwaysRestartFile = options.appRoot + "/" + options.restartDir + "/always_restart.txt";
	}

	detachedProcessesCheckerActive = false;
}
Beispiel #3
0
binary generateRandom(int size, const binary& n = binary()) // generates random binary number
{
    int nInt;
    if(n.size() == 0)
    {
        nInt = 1;
    }
    else
    {
        nInt = convertBinToDec(n);
    }

    binary result = initBinaryResult(size);
    int resultInt;

    do
    {
        for(int i=0; i<size; ++i)
        {
            result.setNumberAt(i, generateSecret());
			std::this_thread::sleep_for(std::chrono::milliseconds(1));
        }
        resultInt = convertBinToDec(result);
    } while(resultInt == 0 || gcd(resultInt, nInt) != 1);

    return result;
}
Beispiel #4
0
int CgidWorker::start( const char * pServerRoot, const char * pChroot,
                        uid_t uid, gid_t gid, int priority )
{
    char achSocket[1024];
    int fd;
    int ret;
    if ( m_pid != -1 )
        return 0;

    CgidConfig& config = getConfig();
    generateSecret( config.getSecretBuf());
    HttpGlobals::s_pCgid = this;
    config.addEnv( "PATH=/bin:/usr/bin:/usr/local/bin" );
    config.addEnv( NULL );
    
    char *p = achSocket;
    int i, n;
    memccpy( p, config.getSocket(), 0, 128 );
    setURL( p );
    fd = ExtWorker::startServerSock( &config, 200 );
    if ( fd == -1 )
    {
        LOG_ERR(("Cannot create a valid unix domain socket for CGI daemon." ));
        return -1;
    }
    m_fdCgid = fd;

    n = snprintf( p, 255, "uds:/%s", getConfig().getServerAddrUnixSock() );
    if ( getuid() == 0 )
    {
        chown( p + 5, 0, gid );
        chmod( p + 5, 0760 );
    }
    else
    {
        chmod( p + 5, 0700 );
    }

    if ( pChroot )
    {
        i = strlen( pChroot );
        memmove( p + 5, p + 5 + i, n - 5 - i + 1 );
    }
    setURL( p );

    ret = spawnCgid( m_fdCgid, p, config.getSecret() );

    if ( ret ==-1 )
    {
        return -1;
    }
    setState( ST_GOOD );
    return ret;
}