Example #1
0
File: nc.c Project: dzch/twemproxy
int
main(int argc, char **argv)
{
    rstatus_t status;
    struct instance nci;

    nc_set_default_options(&nci);

    status = nc_get_options(argc, argv, &nci);
    if (status != NC_OK) {
        nc_show_usage();
        exit(1);
    }

    if (show_version) {
        nc_show_version();
        exit(0);
    }

    if (show_help) {
        nc_show_usage();
        exit(0);
    }

    if (describe_stats) {
        stats_describe();
        exit(0);
    }

    if (test_conf) {
        if (!nc_test_conf(&nci)) {
            exit(1);
        }
        exit(0);
    }

    status = nc_pre_run(&nci);
    if (status != NC_OK) {
        nc_post_run(&nci);
        exit(1);
    }

    nc_run(&nci);

    nc_post_run(&nci);

    exit(1);
}
Example #2
0
int
main(int argc, char **argv)
{
    rstatus_t status;
    struct instance nci;

    nc_set_default_options(&nci);

    status = nc_get_options(argc, argv, &nci);
    if (status != NC_OK) {
        nc_show_usage();
        exit(1);
    }

    if (show_version) {
        log_stderr("This is nutcracker-%s" CRLF, NC_VERSION_STRING);
        if (show_help) {
            nc_show_usage();
        }

        if (describe_stats) {
            stats_describe();
        }

        exit(0);
    }

    if (test_conf) {
        if (!nc_test_conf(&nci)) {
            exit(1);
        }
        exit(0);
    }

    status = nc_pre_run(&nci);
    if (status != NC_OK) {
        nc_post_run(&nci);
        exit(1);
    }

    nc_run(&nci);

    nc_post_run(&nci);

    exit(1);
}
Example #3
0
void
tw_worker_cycle(void *data)
{
    rstatus_t status;
	pid_t pid;
	char tmp_name[100];
	int i;
	sigset_t		  set;

	
	nc_process_role = NC_PROCESS_WORKER;
	sprintf(tmp_name, "worker %d", nc_worker_index);
	nc_setproctitle(tmp_name);
	
	// done by slave to replace master signal !important
	sigemptyset(&set);
	if (sigprocmask(SIG_SETMASK, &set, NULL) == -1) {
		log_error("sigprocmask() children %d failed", nc_worker_index);
	}

    //nc_set_default_options(&env_global);
    //status = nc_get_options(nc_argc, nc_argv, &env_global);
    //if (status != NC_OK) {
    //    exit(1);
    //}
	//memcpy(&nci_global, &env_global, sizeof(struct instance));
 
	if (conf_filename_global==NULL){
		nci_global.conf_filename = NC_CONF_PATH;	
	} else {
		nci_global.conf_filename = conf_filename_global;
	}
	if (log_filename_global == NULL) {
		nci_global.log_filename = NC_LOG_PATH;
	} else {
		nci_global.log_filename = log_filename_global;
	}
	log_error("%s", nci_global.conf_filename);

	pid = getpid();
	//CPU_ZERO(&cpu_mask);
    //CPU_SET(nc_worker_index, &cpu_mask);
	for (i = 0; i < sysconf(_SC_NPROCESSORS_ONLN); i++ ) {
	  if (CPU_ISSET(i, &cpu_mask)){
	    break;
	  }
	}
    if(sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_mask) == -1) {
      log_error("warning: worker %d bind process pid %d on cpu%d fail\n", nc_worker_index, pid, i);
    }else{
      log_error("worker %d bind current process pid %d to core %d\n", nc_worker_index, pid, i);
    }
	log_error("process pid %d socketpair channel %d", pid, nc_worker_channel);
	  
    status = nc_worker_pre_run(&nci_global);
    if (status != NC_OK) {
        nc_worker_post_run(&nci_global);
        exit(1);
    }

    nc_run(&nci_global);

    nc_worker_post_run(&nci_global);

    exit(1);
}