Exemple #1
0
int main(int argc, char **argv)
{
    /* Mainly only for safety */
    setupSignal();
    
    /* Initialize decoder's */
    DecoderSet(dInstr);
    
    banner(argc,argv);
    
    if( (u2AnonContext = parseCommandLine(argc,argv)) == NULL)
    {
	/* XXX */
	CleanExit(1);
    }
    
    if(u2AnonContext->verbose_flag)
    {
	printContext(u2AnonContext);
    }

    if( fileOperation(u2AnonContext))
    {
	/* XXX */
	CleanExit(1);
    }
    
    
    CleanExit(0); 
    /* Exit here but remove the compile warn ...*/
    return 0;
}
TimingSwitchDialog::TimingSwitchDialog(ChildWindowBase *parent) :
		ChildWindowBase(parent),
		ui(new Ui::TimingSwitchDialog)
{
	ui->setupUi(this);
	setupWidget();
	setupSignal();
}
Exemple #3
0
int SignalHandler::registerSignalHandler(int sig, SignalInterface *t)
{
	std::map<int, std::list<SignalInterface*> >::iterator it;
	it = signalList.find(sig);
	
	pthread_mutex_lock(&mutex);
	if (it == signalList.end()) {
		if (setupSignal(sig))
			THROWEXCEPTION("Couldn't set up signal handler for signal %d\n", sig);
	}
	signalList[sig].push_back(t);
	pthread_mutex_unlock(&mutex);
	return 0;
}
Exemple #4
0
int main(int argc, char **argv) {
    
    help(argc, argv);
    
    sprintf(pid_str, "%ld",(long)getpid());
    
    setupSignal();
    initProcessSM();
    initMsgSM();
    
    pthread_t rd_t;
    size_t len; /* Size of shared memory object */
    
    //read thread: task is read msg from shared memory
    if (0 != pthread_create(&rd_t, NULL, readMsg, NULL)) {
        errExit("pthread_create");
    }
    
    //in main thread wait for user's input
    while (1) {
        printf("please input:");
        char input[255];
        scanf("%s", input);
        if (strcmp("exit", input) == 0) {
            exitcomm();
        } else {
            //write to shared memory
            char str[SMSIZE];
            sprintf(str, "%s :", pid_str);
            strcat(str, input);
            len = strlen(str);
            
            memcpy(msgaddr, str, len);
            msgaddr[len] = '\0';
            sendSignal();
        }
    }
    return 0;
}
int main(int argc, char *argv[])
{
    char *pEnv;

    /*--------------------------------------------------------------------------
      중복 프로세스 체크
      ---------------------------------------------------------------------------*/
    if (dupcheckbyname(argv[0]) != 0) {
        fprintf(stderr, "oops!!! duplicated process(%s). So, exit\n", argv[0]);
        exit(0);
    }

    /*--------------------------------------------------------------------------
      시그널 등록
      ---------------------------------------------------------------------------*/
    setupSignal(vmct_signal_handler);

    /*--------------------------------------------------------------------------
      Init Environment
      ---------------------------------------------------------------------------*/
    /* get environment variable */
    if ((pEnv = getenv(BPAPP_ENV_NAME)) == NULL){
        fprintf(stderr, "'%s' environment variable not found(%s)\n", BPAPP_ENV_NAME, strerror(errno));
        exit(0);
    }

    /*--------------------------------------------------------------------------
      디버그 프린트 및 로그 초기화
      ---------------------------------------------------------------------------*/
#if 0
    InitDebug(pEnv, FMS_VMC | FMS_CLB, FMS_INFO1, DBG_TERMINAL | DBG_FILE | DBG_THIS);
#else
    InitDebug(pEnv, FMS_VMC | FMS_CLB, FMS_INFO1, DBG_FILE | DBG_THIS);
#endif

    xprint(FMS_VMC | FMS_LOOKS, "\n");
    xprint(FMS_VMC | FMS_LOOKS, "*********************************************************************\n");
    xprint(FMS_VMC | FMS_LOOKS, "     BPAPP-VMCT : START \n");
    xprint(FMS_VMC | FMS_LOOKS, "*********************************************************************\n");
    xprint(FMS_VMC | FMS_LOOKS, "\n");

    /* Init Global Variable */
    if (InitVariable() < 0) {
        xprint(FMS_VMC | FMS_FATAL, "Initialize failed, So exit\n");
        terminateLog();
        close_xprint();
        exit(0);
    }

    /* Init config from cfgFile */
    if (read_config(pEnv) < 0) {
        xprint(FMS_VMC | FMS_FATAL, "Global Configuration error, So exit\n");
        close_xprint();
        exit(0);
    }

    /* Init Mutex & MsgQCmdTmr */
    InitMutexCmdTmr();

#ifdef __DEBUG__
    DebugSizeofStruct();
    DebugVmctInfo();
    DebugVmProcessInfo();
#endif

    /*--------------------------------------------------------------------------
      pthread Create
     ---------------------------------------------------------------------------*/
    /* TCP Recv Control (HOST) */
    if (ThreadFlags[PTASK0] == FALSE) {
        pthread_attr_init(&Thread_Attr[PTASK0]);
        pthread_attr_setdetachstate(&Thread_Attr[PTASK0], PTHREAD_CREATE_DETACHED);
        pthread_create(&ThreadArray[PTASK0], &Thread_Attr[PTASK0], TcpRcvTask, NULL);
        pthread_attr_destroy(&Thread_Attr[PTASK0]);
        ThreadFlags[PTASK0] = TRUE;
    }

    /* System Info HOST Send */
    if (ThreadFlags[PTASK1] == FALSE) {
        pthread_attr_init(&Thread_Attr[PTASK1]);
        pthread_attr_setdetachstate(&Thread_Attr[PTASK1], PTHREAD_CREATE_DETACHED);
        pthread_create(&ThreadArray[PTASK1], &Thread_Attr[PTASK1], TcpSessionTask, NULL);
        pthread_attr_destroy(&Thread_Attr[PTASK1]);
        ThreadFlags[PTASK1] = TRUE;
    }

    /* Timer Cmd (TCP Reconnect) */
    if (ThreadFlags[PTASK2] == FALSE) {
        pthread_attr_init(&Thread_Attr[PTASK2]);
        pthread_attr_setdetachstate(&Thread_Attr[PTASK2], PTHREAD_CREATE_DETACHED);
        pthread_create(&ThreadArray[PTASK2], &Thread_Attr[PTASK2], TmrCmdTask, NULL);
        pthread_attr_destroy(&Thread_Attr[PTASK2]);
        ThreadFlags[PTASK2] = TRUE;
    }

    RunState = 1;

    while(RunState != 0) {
        nanoSleep(1000);
    }

    pthread_join(ThreadArray[PTASK0], NULL);
    pthread_join(ThreadArray[PTASK1], NULL);
    pthread_join(ThreadArray[PTASK2], NULL);

    return(0);
}
Exemple #6
0
void Master::start()
{
	//init script
	Config *pConfig = Config::getInstance();
	if(!pConfig->sScriptFile.empty()){
		pScript = new Script();
		if(!pScript->load(pConfig->sScriptFile)){
			printf("init script failed\n");
			return ;
		}
	}
	
	//session initialize
	Session::init();
	
	//create share memory
	if(!createGlobals()){
		return ;
	}
		
	//create server
	pServer = new Server(NULL);
	if(pServer->createTcpServer(pConfig->nPort) != 0){
		printf("create tcp server failed, port=%d, errno=%d, errstr=%s\n", 
			pConfig->nPort, errno, strerror(errno));
		return ;
	}
	
	//create worker
	pWorkers = (Worker**)zmalloc(pConfig->nWorkers * sizeof(Worker*));
	bUseAcceptMutex = pConfig->nWorkers > 1;
	for(int i = 0; i < pConfig->nWorkers; ++i){
		pWorkers[i] = new Worker(this, i);
		pWorkers[i]->start();
	}
	
	//set title
	char title[256];
	snprintf(title, 256, "fooking gateway master, %s", pConfig->sFile.c_str());
	utils::setProcTitle(title);
		
	//init signal
	setupSignal();
	
	//started log
	LOG_INFO("server started, listenfd=%d, port=%d", pServer->getSocket().getFd(), pConfig->nPort);

	//wait worker exit
	bRunning = true;
	while(bRunning)
	{
		int ret = 0;
		int pid = ::wait(&ret);
		if(pid <= 0){
			continue;
		}
		
		int found = -1;
		for(int i = 0; i < pConfig->nWorkers; ++i){
			Worker *pWorker = pWorkers[i];
			if(pWorker->getPid() == pid){
				found = pWorker->id();
				delete pWorker;
				break;
			}
		}
		
		if(found == -1){
			LOG_ERR("worker exited, not found workerid");
		}else{
			LOG_INFO("worker exited, id=%d, pid=%d", found, pid);
			atomic_fetch_sub(&pGlobals->clients, pGlobals->workerClients[found]);
			pGlobals->workerClients[found] = 0;
			
			//free lock
			if(bUseAcceptMutex){
				UnLockAcceptMutex(&pGlobals->lock, pid);
			}
			
			//restart
			pWorkers[found] = new Worker(this, found);
			pWorkers[found]->start();
		}
	}
}
Exemple #7
0
void startOneCache(void)
{
    CRedisProxyCfg* cfg = CRedisProxyCfg::instance();
    setupSignal();

    EventLoop listenerLoop;
    bool twemproxyMode = cfg->isTwemproxyMode();
    const int points_per_server = 160;
    const int pointer_per_hash = 4;
    int slot_index = 0;

    RedisProxy proxy;
    proxy.setEventLoop(&listenerLoop);
    loop = &listenerLoop;
    CProxyMonitor monitor;
    proxy.setMonitor(&monitor);

    const int defaultPort = 8221;
    int port = cfg->port();
    if (port <= 0) {
        LOG(Logger::Debug, "Port %d invalid, use default port %d", defaultPort);
        port = defaultPort;
    }

    if (!proxy.run(HostAddress(port))) {
        exit(APP_EXIT_KEY);
    }

    proxy.setTwemproxyModeEnabled(twemproxyMode);

    EventLoopThreadPool pool;
    pool.start(cfg->threadNum());
    proxy.setEventLoopThreadPool(&pool);

    const SVipInfo* vipInfo = cfg->vipInfo();
    proxy.setVipName(vipInfo->if_alias_name);
    proxy.setVipAddress(vipInfo->vip_address);
    proxy.setVipEnabled(vipInfo->enable);

    const SHashInfo* sHashInfo = cfg->hashInfo();

    if (!twemproxyMode) {
        proxy.setSlotCount(sHashInfo->hash_value_max);
    } else {
        proxy.setSlotCount(cfg->groupCnt() * points_per_server);
    }

    const GroupOption* groupOption = cfg->groupOption();
    proxy.setGroupRetryTime(groupOption->group_retry_time);
    proxy.setAutoEjectGroupEnabled(groupOption->auto_eject_group);
    proxy.setEjectAfterRestoreEnabled(groupOption->eject_after_restore);
    proxy.setPassword(cfg->password());

    for (int i = 0; i < cfg->groupCnt(); ++i) {
        const CGroupInfo* info = cfg->group(i);

        RedisServantGroup* group = new RedisServantGroup;
        RedisServantGroupPolicy* policy = RedisServantGroupPolicy::createPolicy(info->groupPolicy());
        group->setGroupName(info->groupName());
        group->setPolicy(policy);

        const HostInfoList& hostList = info->hosts();
        HostInfoList::const_iterator itHost = hostList.begin();
        for (; itHost != hostList.end(); ++itHost) {
            const CHostInfo& hostInfo = (*itHost);
            RedisServant* servant = new RedisServant;
            RedisServant::Option opt;
            strcpy(opt.name, hostInfo.get_hostName().c_str());
            opt.poolSize = hostInfo.get_connectionNum();
            opt.reconnInterval = groupOption->backend_retry_interval;
            opt.maxReconnCount = groupOption->backend_retry_limit;
            servant->setOption(opt);
            servant->setRedisAddress(HostAddress(hostInfo.get_ip().c_str(), hostInfo.get_port()));
            servant->setEventLoop(proxy.eventLoop());
            if (hostInfo.get_master()) {
                group->addMasterRedisServant(servant);
            } else {
                group->addSlaveRedisServant(servant);
            }
            servant->connectionPool()->setPassword(itHost->passWord());
        }
        group->setEnabled(true);
        proxy.addRedisGroup(group);

        if (!twemproxyMode) {
            for (int i = info->hashMin(); i <= info->hashMax(); ++i) {
                proxy.setSlot(i, group);
            }

            for (int i = 0; i < cfg->hashMapCnt(); ++i) {
                const CHashMapping* mapping = cfg->hashMapping(i);
                RedisServantGroup* group = proxy.group(mapping->group_name);
                proxy.setSlot(mapping->hash_value, group);
            }
        } else {
            Slot* slot = proxy.slotData();
            for (int pointer_index = 1;
                    pointer_index <= points_per_server / pointer_per_hash;
                    pointer_index++) {

                char host[86];
                int hostlen = sprintf(host, "%s-%u", group->groupName(), pointer_index - 1);
                for (int x = 0; x < pointer_per_hash; x++) {
                    slot[slot_index].group = group;
                    slot[slot_index++].value = ketama_hash(host, hostlen, x);
                }
            }
        }
    }

    if (twemproxyMode) {
        LOG(Logger::Debug, "Twemproxy mode. dist=ketama slotcount=%d", proxy.slotCount());
        Slot* slot = proxy.slotData();
        int slotCount = proxy.slotCount();
        qsort(slot, slotCount, sizeof(Slot), slot_item_cmp);
    }

    HashFunc func = hashfuncFromName(cfg->hashFunctin().c_str());
    proxy.setHashFunction(func);

    for (int i = 0; i < cfg->keyMapCnt(); ++i) {
        const CKeyMapping* mapping = cfg->keyMapping(i);
        RedisServantGroup* group = proxy.group(mapping->group_name);
        if (group != NULL) {
            proxy.addGroupKeyMapping(mapping->key, strlen(mapping->key), group);
        }
    }

    LOG(Logger::Message, "Start the %s on port %d. PID: %d", APP_NAME, port, getpid());
    listenerLoop.exec();
}