Exemplo n.º 1
0
void
maximize_priority(void)
{
	if (skip_rt) {
		cl_log(LOG_INFO, "Not elevating to realtime (-R specified).");
		return;
	}

	cl_make_realtime(-1, 100, 256, 256);

	if (ioprio_set(IOPRIO_WHO_PROCESS, getpid(),
			IOPRIO_PRIO_VALUE(IOPRIO_CLASS_RT, 1)) != 0) {
		cl_perror("ioprio_set() call failed.");
	}
}
Exemplo n.º 2
0
int
crmd_init(void)
{
    int exit_code = 0;
    enum crmd_fsa_state state;

    fsa_state = S_STARTING;
    fsa_input_register = 0;     /* zero out the regester */

    init_dotfile();
    crm_debug("Starting %s", crm_system_name);
    register_fsa_input(C_STARTUP, I_STARTUP, NULL);

    crm_peer_init();
    state = s_crmd_fsa(C_STARTUP);

    if (state == S_PENDING || state == S_STARTING) {
        /* Create the mainloop and run it... */
        crmd_mainloop = g_main_new(FALSE);
        crm_trace("Starting %s's mainloop", crm_system_name);

#ifdef REALTIME_SUPPORT
        static int crm_realtime = 1;

        if (crm_realtime == 1) {
            cl_enable_realtime();
        } else if (crm_realtime == 0) {
            cl_disable_realtime();
        }
        cl_make_realtime(SCHED_RR, 5, 64, 64);
#endif
        g_main_run(crmd_mainloop);
        if (is_set(fsa_input_register, R_STAYDOWN)) {
            crm_info("Inhibiting respawn by Heartbeat");
            exit_code = 100;
        }

    } else {
        crm_err("Startup of %s failed.  Current state: %s",
                crm_system_name, fsa_state2string(state));
        exit_code = 1;
    }

    crm_info("[%s] stopped (%d)", crm_system_name, exit_code);
    qb_log_fini();

    return exit_code;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{	

	int ret;

	progname = get_progname(argv[0]);
	nodename = get_nodename();

	cl_log_set_entity(progname);
	cl_log_set_facility(HA_LOG_FACILITY);
	cl_inherit_logging_environment(0);

	/* read command line option */
	opterr = 0;
	while (1) {
		int c = getopt(argc, argv, "hi:c:t:m:n:r:");
		if (c == -1)
			break;
		switch (c) {
			case 'h':           /* help*/
				usage(stdout);
				exit(EXIT_SUCCESS);
			case 'i':           /* -i <index> */
				{
					unsigned long l = strtoul(optarg, NULL, 10);
					if (l < SFEX_MIN_NUMLOCKS || l > SFEX_MAX_NUMLOCKS) {
						cl_log(LOG_ERR, 
								"index %s is out of range or invalid. it must be integer value between %lu and %lu.\n",
								optarg,
								(unsigned long)SFEX_MIN_NUMLOCKS,
								(unsigned long)SFEX_MAX_NUMLOCKS);
						exit(4);
					}
					lock_index = l;
				}
				break;
			case 'c':           /* -c <collision_timeout> */
				{
					unsigned long l = strtoul(optarg, NULL, 10);
					if (l < 1 || l > INT_MAX) {
						cl_log(LOG_ERR, 
								"collision_timeout %s is out of range or invalid. it must be integer value between %lu and %lu.\n",
								optarg,
								(unsigned long)1,
								(unsigned long)INT_MAX);
						exit(4);
					}
					collision_timeout = l;
				}
				break;
			case 'm':  			/* -m <monitor_interval> */
				{
					unsigned long l = strtoul(optarg, NULL, 10);
					if (l < 1 || l > INT_MAX) {
						cl_log(LOG_ERR, 
								"monitor_interval %s is out of range or invalid. it must be integer value between %lu and %lu.\n",
								optarg,
								(unsigned long)1,
								(unsigned long)INT_MAX);
						exit(4);
					}
					monitor_interval = l;
				}
				break;	
			case 't':           /* -t <lock_timeout> */
				{
					unsigned long l = strtoul(optarg, NULL, 10);
					if (l < 1 || l > INT_MAX) {
						cl_log(LOG_ERR, 
								"lock_timeout %s is out of range or invalid. it must be integer value between %lu and %lu.\n",
								optarg,
								(unsigned long)1,
								(unsigned long)INT_MAX);
						exit(4);
					}
					lock_timeout = l;
				}
				break;
			case 'n':
				{
					free(nodename);
					if (strlen(optarg) > SFEX_MAX_NODENAME) {
						cl_log(LOG_ERR, "nodename %s is too long. must be less than %d byte.\n",
								optarg,
								(unsigned int)SFEX_MAX_NODENAME);
						exit(EXIT_FAILURE);
					}
					nodename = strdup(optarg);
				}	
				break;
			case 'r':
				{
					rsc_id = strdup(optarg);
				}
				break;
			case '?':           /* error */
				usage(stderr);
				exit(4);
		}
	}
	/* check parameter except the option */
	if (optind >= argc) {
		cl_log(LOG_ERR, "no device specified.\n");
		usage(stderr);
		exit(EXIT_FAILURE);
	} else if (optind + 1 < argc) {
		cl_log(LOG_ERR, "too many arguments.\n");
		usage(stderr);
		exit(EXIT_FAILURE);
	}
	device = argv[optind];

	prepare_lock(device);
#if !SFEX_TESTING
	sysrq_fd = open("/proc/sysrq-trigger", O_WRONLY);
	if (sysrq_fd == -1) {
		cl_log(LOG_ERR, "failed to open /proc/sysrq-trigger due to %s\n", strerror(errno));
		exit(EXIT_FAILURE);
	}
#endif

	ret = lock_index_check(&cdata, lock_index);
	if (ret == -1)
		exit(EXIT_FAILURE);

	{
		struct sigaction sig_act;
		sigemptyset (&sig_act.sa_mask);
		sig_act.sa_flags = SA_SIGINFO;

		sig_act.sa_sigaction = quit_handler;
		ret = sigaction(SIGTERM, &sig_act, NULL);
		if (ret == -1) {
			cl_log(LOG_ERR, "sigaction failed\n");
			exit(EXIT_FAILURE);
		}
	}

	cl_log(LOG_INFO, "Starting SFeX Daemon...\n");
	
	/* acquire lock first.*/
	acquire_lock();

	if (daemon(0, 1) != 0) {
		cl_perror("%s::%d: daemon() failed.", __FUNCTION__, __LINE__);
		release_lock();
		exit(EXIT_FAILURE);
	}

	cl_make_realtime(-1, -1, 128, 128);
	
	cl_log(LOG_INFO, "SFeX Daemon started.\n");
	while (1) {
		sleep (monitor_interval);
		update_lock();
	}
}
Exemplo n.º 4
0
/*
  crmd起動初期処理


 C_で表現さえる原因は以下が用意されている
 
enum crmd_fsa_cause
{
	C_UNKNOWN = 0,
	C_STARTUP,
	C_IPC_MESSAGE,
	C_HA_MESSAGE,
	C_CCM_CALLBACK,
	C_CRMD_STATUS_CALLBACK,
	C_LRM_OP_CALLBACK,
	C_LRM_MONITOR_CALLBACK,
	C_TIMER_POPPED,
	C_SHUTDOWN,
	C_HEARTBEAT_FAILED,
	C_SUBSYSTEM_CONNECT,
	C_HA_DISCONNECT,
	C_FSA_INTERNAL,
	C_ILLEGAL
};
*/
int
crmd_init(void)
{
    int exit_code = 0;
    enum crmd_fsa_state state;

	/* 最初のfsa_stateをS_STARTINGにセット */
    fsa_state = S_STARTING;
    fsa_input_register = 0; /* zero out the regester */

    init_dotfile();
    crm_info("Starting %s", crm_system_name);
	/* Start時の自処理入力データを作成する */
	/*
	fsa_data->id        = last_data_id;
	fsa_data->fsa_input = I_STARTUP;
	fsa_data->fsa_cause = C_STARTUP;
	fsa_data->origin    = raised_from;
	fsa_data->data      = NULL;
	fsa_data->data_type = fsa_dt_none;
	fsa_data->actions   = with_actions;
	
	 #define register_fsa_input(cause, input, data) register_fsa_input_adv(cause, input, data, A_NOTHING, FALSE, __FUNCTION__)
	*/
    register_fsa_input(C_STARTUP, I_STARTUP, NULL);

    crm_peer_init();
    
    /* 最初のS_STARTING/C_STARTUP/I_STARTUP状態を処理する */
    state = s_crmd_fsa(C_STARTUP);
    
    if (state == S_PENDING || state == S_STARTING) {
	    /* Create the mainloop and run it... */
	    crmd_mainloop = g_main_new(FALSE);
	    crm_info("Starting %s's mainloop", crm_system_name);
	    
#ifdef REALTIME_SUPPORT
	    static int  crm_realtime = 1;
	    if (crm_realtime == 1){
		    cl_enable_realtime();
	    }else if (crm_realtime == 0){
		    cl_disable_realtime();
	    }
	    cl_make_realtime(SCHED_RR, 5, 64, 64);
#endif
		/* メインループ開始 */
	    g_main_run(crmd_mainloop);
	    if(is_set(fsa_input_register, R_STAYDOWN)) {
		    crm_info("Inhibiting respawn by Heartbeat");
		    exit_code = 100;
	    }

    } else {
	    crm_err("Startup of %s failed.  Current state: %s",
		    crm_system_name, fsa_state2string(state));
	    exit_code = 1;
    }
    
    crm_info("[%s] stopped (%d)", crm_system_name, exit_code);
    return exit_code;
}