Ejemplo n.º 1
0
/* calculate next possible offset value for shm and sem key values */
int htxd_get_next_key_offset(htxd_ecg_manager *this_ecg_manager)
{

	static int next_key_offset = 0;
	htxd_ecg_info * p_ecg_info_list;

	p_ecg_info_list = htxd_get_ecg_info_list(this_ecg_manager);
	if(p_ecg_info_list == NULL) {
		return next_key_offset;
	}

	while(next_key_offset < KYE_OFF_SET_LIMIT) {
		while(p_ecg_info_list != NULL) {
			if(p_ecg_info_list->ecg_shm_key == ECG_SHMKEY_START + next_key_offset) {
				next_key_offset++;
				break;
			}
			p_ecg_info_list = p_ecg_info_list->ecg_info_next;
		}
		if(p_ecg_info_list == NULL) {
			break;
		}
	}

	if(next_key_offset > KYE_OFF_SET_LIMIT) {
		next_key_offset = -1;
	}

	return next_key_offset;
}
Ejemplo n.º 2
0
int htxd_get_running_ecg_list(char * ecg_name_list)
{

	htxd_ecg_manager *p_ecg_manager;
	htxd_ecg_info * p_ecg_info_list;
	int ecg_name_list_length;


	ecg_name_list[0] = '\0';
	p_ecg_manager = htxd_get_ecg_manager();

	p_ecg_info_list = htxd_get_ecg_info_list(p_ecg_manager);

	while(p_ecg_info_list != NULL) {
		strcat(ecg_name_list, p_ecg_info_list->ecg_name);
		strcat(ecg_name_list, ", ");
		p_ecg_info_list = p_ecg_info_list->ecg_info_next;
	}

	ecg_name_list_length = strlen(ecg_name_list);
	if(ecg_name_list_length > 0) {
		ecg_name_list[ecg_name_list_length - 2] = '\0';
	}

	return 0;
}
Ejemplo n.º 3
0
/* search in the ecg info list with ecg name for an ecg node in the list */
htxd_ecg_info * htxd_get_ecg_info_node(htxd_ecg_manager *this_ecg_manager, char *ecg_name)
{
	htxd_ecg_info *p_ecg_info_node = NULL;;

	p_ecg_info_node = htxd_get_ecg_info_list(this_ecg_manager);
	while(p_ecg_info_node != NULL) {
		if( strcmp(ecg_name, p_ecg_info_node->ecg_name) == 0) {
			break;
		}
		p_ecg_info_node = p_ecg_info_node->ecg_info_next;
	}

	return p_ecg_info_node;
}
Ejemplo n.º 4
0
/* a generic function to process a command for all devices in an  ecg */
int htxd_process_all_active_ecg(ecg_process_function process_action, char *command_result)
{
	htxd *htxd_instance;
	htxd_ecg_info * p_ecg_info_list;
	int return_code = 0;


	htxd_instance = htxd_get_instance();

	p_ecg_info_list = htxd_get_ecg_info_list(htxd_instance->p_ecg_manager);

	while(p_ecg_info_list != NULL) {
		return_code = process_action(p_ecg_info_list, command_result);
		p_ecg_info_list = p_ecg_info_list->ecg_info_next;
	}

	return return_code;
}
/* select mdt command main function */
int htxd_option_method_select_mdt(char **result, htxd_command *p_command)
{
	htxd *htxd_instance;
	htxd_ecg_info * p_ecg_info_list;
	htxd_ecg_info * p_ecg_info_to_select;
	char command_ecg_name[MAX_ECG_NAME_LENGTH];
	htxd_ecg_manager *ecg_manager;
	char trace_str[512], cmd[128];
	char temp_str[512];


	HTXD_FUNCTION_TRACE(FUN_ENTRY, "htxd_option_method_select_mdt");
	/* htxd instance will be created only first time */
	htxd_instance = htxd_get_instance();

	*result = malloc(1024);
	ecg_manager = htxd_get_ecg_manager();
	strcpy(command_ecg_name, p_command->ecg_name);

	if(htxd_instance->is_mdt_created == 0) {
		htxd_execute_shell_profile();	
		htxd_instance->is_mdt_created = 1;
	}

	if(htxd_instance->run_state == HTXD_DAEMON_STATE_SELECTED_MDT) {
		if(strcmp(command_ecg_name, ecg_manager->selected_ecg_name) == 0) {
			sprintf(*result, "Failed to select specified ecg/mdt(%s), same ecg/mdt is already selected", command_ecg_name);
		} else {
			sprintf(*result, "Failed to select specified ecg/mdt(%s), another ecg/mdt(%s) is already selected", command_ecg_name, ecg_manager->selected_ecg_name);
		}
		return 1;
	}

	if(htxd_instance->run_state == HTXD_DAEMON_STATE_RUNNING_MDT) {
		if(strcmp(command_ecg_name, ecg_manager->running_ecg_name) == 0) {
			sprintf(*result, "Failed to select specified ecg/mdt(%s), same ecg/mdt is being run", command_ecg_name);
		} else {
			sprintf(*result, "Failed to select specified ecg/mdt(%s), another ecg/mdt(%s) is being run", command_ecg_name, ecg_manager->running_ecg_name);
		}
		return 1;
	}

	sprintf(trace_str, "ECG name from command = <%s>", command_ecg_name);
	HTXD_TRACE(LOG_OFF, trace_str);


	if(command_ecg_name[0] == '\0') {
		sprintf(command_ecg_name, "%s/mdt/%s", global_htx_home_dir, DEFAULT_ECG_NAME);
	}

	if(htxd_is_file_exist(command_ecg_name) == FALSE) {
		sprintf(*result, "specified mdt(%s) is invalid", command_ecg_name);
		HTXD_TRACE(LOG_OFF, "htxd_is_file_exist() could not find the ECG file");
		return 1;
	}

	if(ecg_manager == NULL) {
		HTXD_TRACE(LOG_OFF, "ecg manager is creating");
		ecg_manager = create_ecg_manager();
		if(ecg_manager == NULL) {
			HTXD_TRACE(LOG_OFF, "e_ecg_manager() failed to create ecg manager");
			return 1;
		}
		htxd_instance->p_ecg_manager = ecg_manager;
		htxd_send_message ("HTX Daemon wakeup for responding", 0, HTX_SYS_INFO, HTX_SYS_MSG);
	}

	p_ecg_info_list = htxd_get_ecg_info_list(htxd_instance->p_ecg_manager);
	while(p_ecg_info_list != NULL) {
		if( strcmp(command_ecg_name, p_ecg_info_list->ecg_name) == 0) {
			sprintf(*result, "specified ECG (%s) is already running", command_ecg_name);
			HTXD_TRACE(LOG_OFF, "specified ECG is already running");
			return 1;
		}
		p_ecg_info_list = p_ecg_info_list->ecg_info_next;
	}

	htxd_set_daemon_state(HTXD_DAEMON_STATE_SELECTING_MDT);

	/* copy run mdt to current mdt */
	sprintf(temp_str, "cp %s %s/mdt/mdt ; sync", command_ecg_name, global_htx_home_dir);
	system(temp_str);

	/* update for camss mdt */
	if( strstr(command_ecg_name, "camss") != NULL) {
		sprintf(trace_str, "updating camss mdt <%s>", command_ecg_name);
		HTXD_TRACE(LOG_OFF, trace_str);
		sprintf(cmd, "%s/etc/scripts/%s %s", global_htx_home_dir, CAMSS_MDT_UPDATE_SCRIPT, command_ecg_name);
		system(cmd);
	}

	/* execute run setup script for this MDT */
	htxd_execute_run_setup_script(command_ecg_name);

	/* allocating required IPCs  and initialize the value at shared memory*/
	HTXD_TRACE(LOG_OFF, "run initializing ecg_info");
	htxd_init_ecg_info(ecg_manager, command_ecg_name);

	/* start hxsmsg process if it is not already started */
	if(htxd_get_htx_msg_pid() == 0) {
		sprintf(temp_str, "%s/%s", global_htx_home_dir, HTXD_AUTOSTART_FILE);
		if(htxd_is_file_exist(temp_str) == FALSE) { /* incase of bootme do not truncate error file */
			htxd_truncate_error_file();
		}
		htxd_truncate_message_file();
		htxd_load_hxsmsg(htxd_instance->p_profile);
		HTXD_TRACE(LOG_ON, "run started htxsmsg process");
	}

	strcpy(ecg_manager->selected_ecg_name, command_ecg_name);

	/* to DEBUG */
/*	htxd_display_ecg_info_list();
	htxd_display_exer_table();
*/
	p_ecg_info_to_select = ecg_manager->current_loading_ecg_info;
	if(p_ecg_info_to_select->ecg_exerciser_entries == 0){
		sprintf(*result, "No device is present in ECG <%s>, could not start any device", command_ecg_name);
	} else if(p_ecg_info_to_select->ecg_shm_exerciser_entries == 0){
		sprintf(*result, "No device is started under ECG <%s>, since all the devices are already loaded under another ECG(s)", command_ecg_name);
	} else if (p_ecg_info_to_select->ecg_exerciser_entries != p_ecg_info_to_select->ecg_shm_exerciser_entries) {
		sprintf(*result, "ECG (%s) is slected\nWARNING: few devices are unable to start since they may be already loaded under another ECG(s)", command_ecg_name);
	} else {
		sprintf(*result, "ECG (%s) is selected", command_ecg_name);
		sprintf(trace_str, "date +\"ECG (%s) was selected on %%x at %%X %%Z\" >>%s/%s", command_ecg_name, global_htxd_log_dir, HTXD_START_STOP_LOG);
		system(trace_str);
	}

	htxd_send_message (*result, 0, HTX_SYS_INFO, HTX_SYS_MSG);
	HTXD_TRACE(LOG_ON, *result);
	htxd_set_daemon_state(HTXD_DAEMON_STATE_SELECTED_MDT);
	HTXD_FUNCTION_TRACE(FUN_EXIT, "htxd_option_method_select_mdt");
	return 0;

}
/* run command main function */
int htxd_option_method_run_mdt(char **result, htxd_command *p_command)
{
	htxd *htxd_instance;
	htxd_ecg_info * p_ecg_info_list;
	htxd_ecg_info * p_ecg_info_to_run;
	char command_ecg_name[MAX_ECG_NAME_LENGTH];
	htxd_ecg_manager *ecg_manager;
	char trace_str[512], cmd[128];
	int return_code;
	char temp_str[512];


	HTXD_FUNCTION_TRACE(FUN_ENTRY, "htxd_option_method_run_mdt");
	/* htxd instance will be created only first time */
	htxd_instance = htxd_get_instance();
	strcpy(command_ecg_name, p_command->ecg_name);

	sprintf(trace_str, "ECG name from command = <%s>", command_ecg_name);
	HTXD_TRACE(LOG_OFF, trace_str);

	htxd_ecg_shutdown_flag = FALSE;

	ecg_manager = htxd_get_ecg_manager();

	if(command_ecg_name[0] == '\0') {
		sprintf(command_ecg_name, "%s/mdt/%s", global_htx_home_dir, DEFAULT_ECG_NAME);
	}

	if(htxd_instance->is_mdt_created == 0) {
		htxd_execute_shell_profile();	
		htxd_instance->is_mdt_created = 1;
	}

	*result = malloc(1024);

	if(htxd_is_file_exist(command_ecg_name) == FALSE) {
		sprintf(*result, "specified mdt(%s) is invalid", command_ecg_name);
		HTXD_TRACE(LOG_OFF, "htxd_is_file_exist() could not find the ECG file");
		return 1;
	}

	if(ecg_manager == NULL) {
		HTXD_TRACE(LOG_OFF, "ecg manager is creating");
		ecg_manager = create_ecg_manager();
		if(ecg_manager == NULL) {
			HTXD_TRACE(LOG_OFF, "e_ecg_manager() failed to create ecg manager");
			return 1;
		}
		htxd_instance->p_ecg_manager = ecg_manager;
	}


	/* start hxsmsg process if it is not already started */
	if(htxd_get_htx_msg_pid() == 0) {
		sprintf(temp_str, "%s/%s", global_htx_home_dir, HTXD_AUTOSTART_FILE);
		if(htxd_is_file_exist(temp_str) == FALSE) { /* incase of bootme do not truncate error file */
			htxd_truncate_error_file();
		}
		htxd_truncate_message_file();
		htxd_load_hxsmsg(htxd_instance->p_profile);
		HTXD_TRACE(LOG_ON, "run started htxsmsg process");
		htxd_send_message ("HTX Daemon wakeup for responding", 0, HTX_SYS_INFO, HTX_SYS_MSG);
	}

	if(htxd_is_daemon_selected()  != TRUE) {
		p_ecg_info_list = htxd_get_ecg_info_list(htxd_instance->p_ecg_manager);
		while(p_ecg_info_list != NULL) {
			if( strcmp(command_ecg_name, p_ecg_info_list->ecg_name) == 0) {
				sprintf(*result, "specified ECG (%s) is already running", command_ecg_name);
				HTXD_TRACE(LOG_OFF, "specified ECG is already running");
				return 1;
			}
			p_ecg_info_list = p_ecg_info_list->ecg_info_next;
		}
		sprintf(trace_str, "start activating  MDT <%s>", command_ecg_name);
		htxd_send_message (trace_str, 0, HTX_SYS_INFO, HTX_SYS_MSG);
		HTXD_TRACE(LOG_ON, trace_str);

		/* copy run mdt to current mdt */
		sprintf(temp_str, "cp %s %s/mdt/mdt ; sync", command_ecg_name, global_htx_home_dir);
		system(temp_str);

		/* update for camss mdt */
		if( strstr(command_ecg_name, "camss") != NULL) {
			sprintf(trace_str, "updating camss mdt <%s>", command_ecg_name);
			HTXD_TRACE(LOG_OFF, trace_str);
			sprintf(cmd, "%s/etc/scripts/%s %s", global_htx_home_dir, CAMSS_MDT_UPDATE_SCRIPT, command_ecg_name);
			system(cmd);
		}

		/* execute run setup script for this MDT */
		htxd_execute_run_setup_script(command_ecg_name);

		/* allocating required IPCs  and initialize the value at shared memory*/
		HTXD_TRACE(LOG_OFF, "run initializing ecg_info");
		htxd_init_ecg_info(ecg_manager, command_ecg_name);
	} else {
		if(strcmp(command_ecg_name, ecg_manager->selected_ecg_name) != 0) {
			sprintf(*result, "Failed to run specified ecg/mdt (%s), another ecg/mdt (%s) is already selected", command_ecg_name, ecg_manager->selected_ecg_name);
			return 1;
		}
		ecg_manager->selected_ecg_name[0] = '\0';
	}

	htxd_set_daemon_state(HTXD_DAEMON_STATE_STARTING_MDT);
	ecg_manager->current_loading_ecg_info->ecg_run_start_time = (int) time((time_t *) 0);

	/* initializing syscfg */
	if(htxd_is_init_syscfg() != TRUE) {
		return_code = init_syscfg();
		if (return_code != 0) {
			sprintf(*result, "Internal error: failed to initialize syscfg with error code <%d>", return_code);
			HTXD_TRACE(LOG_ON, *result);
			return return_code;
		}
		htxd_set_init_syscfg_flag(TRUE);
	}

	/* start all devices in the ecg */
	HTXD_TRACE(LOG_OFF, "run activating all devices under the ECG");
	htxd_activate_all_ecg_devices(ecg_manager);

	/* start hxstats process if it is not already started */
	if(htxd_get_htx_stats_pid() == 0) {
		htxd_load_hxstats();
		HTXD_TRACE(LOG_ON, "run started htxstats process");
	}

#ifdef __HTXD_DR__
	/* start DR child process */
	if(htxd_get_dr_child_pid() == 0) {
		htxd_start_DR_child();
		HTXD_TRACE(LOG_ON, "run started DR child process");
	}
#endif

#ifdef __HTX_LINUX__
	/* start hotplug monitor */
	if( htxd_is_hotplug_monitor_initialized() != TRUE && htxd_get_equaliser_offline_cpu_flag() != 1) {
		htxd_start_hotplug_monitor(&(htxd_instance->p_hotplug_monitor_thread));
		HTXD_TRACE(LOG_ON, "run started hotplug monitor");
	}
#endif

	/* start equaliser process */
	if( htxd_check_for_equaliser_start(ecg_manager) == TRUE) {
		htxd_start_equaliser();
		HTXD_TRACE(LOG_ON, "run started equaliser process");
	}

	/* start hang monitor thread */
	if(htxd_is_hang_monitor_initialized() != TRUE) {
		htxd_start_hang_monitor(&(htxd_instance->p_hang_monitor_thread));
		HTXD_TRACE(LOG_ON, "run started hang monitor thread");
	}

	/* start stop_watch monitor thread */
	if(htxd_is_stop_watch_monitor_initialized() != TRUE) {
		htxd_start_stop_watch_monitor(&(htxd_instance->stop_watch_monitor_thread));
		HTXD_TRACE(LOG_ON, "run started stop watch monitor thread");
	}

	htxd_set_test_running_state(HTXD_TEST_ACTIVATED);
	strcpy(ecg_manager->running_ecg_name, command_ecg_name);


	/* to DEBUG */
/*	htxd_display_ecg_info_list();
	htxd_display_exer_table();
*/
	p_ecg_info_to_run = ecg_manager->current_loading_ecg_info;
	if(p_ecg_info_to_run->ecg_exerciser_entries == 0){
		sprintf(*result, "No device is present in ECG <%s>, could not start any device", command_ecg_name);
	} else if(p_ecg_info_to_run->ecg_shm_exerciser_entries == 0){
		sprintf(*result, "No device is started under ECG <%s>, since all the devices are already loaded under another ECG(s)", command_ecg_name);
	} else if (p_ecg_info_to_run->ecg_exerciser_entries != p_ecg_info_to_run->ecg_shm_exerciser_entries) {
		sprintf(*result, "ECG (%s) Activated\nWARNING: few devices are unable to start since they may be already loaded under another ECG(s)", command_ecg_name);
	} else {
		sprintf(*result, "ECG (%s) Activated.", command_ecg_name);
		sprintf(trace_str, "date +\"ECG (%s) was activated on %%x at %%X %%Z\" >>%s/%s", command_ecg_name, global_htxd_log_dir, HTXD_START_STOP_LOG);
		system(trace_str);
	}

	/* have to set shm key to system header shared memory so that htx stats is able to connect */
	htxd_set_system_header_info_shm_with_current_shm_key(p_ecg_info_to_run->ecg_shm_key);

	htxd_send_message (*result, 0, HTX_SYS_INFO, HTX_SYS_MSG);
	htxd_set_daemon_state(HTXD_DAEMON_STATE_RUNNING_MDT);
	HTXD_TRACE(LOG_ON, *result);
	HTXD_FUNCTION_TRACE(FUN_EXIT, "htxd_option_method_run_mdt");
	return 0;
}