/* putting daemon back to idle state */ int htxd_idle_daemon(void) { int return_code; char trace_string[256]; pid_t htx_stats_pid; pid_t htx_msg_pid; pid_t htx_equaliser_pid; htxd *htxd_instance; #ifdef __HTXD_DR__ pid_t htx_dr_child_pid; #endif if(htxd_is_hang_monitor_initialized() == TRUE) { htxd_instance = htxd_get_instance(); htxd_stop_hang_monitor(&(htxd_instance->p_hang_monitor_thread)); htxd_remove_hang_monitor(); sprintf(trace_string, "stopping hang monitor thread"); HTXD_TRACE(LOG_OFF, trace_string); } if(htxd_is_time_driven_run_monitor_initialized() == TRUE) { htxd_instance = htxd_get_instance(); htxd_stop_time_driven_run_monitor(&(htxd_instance->p_time_driven_run_monitor_thread)); htxd_remove_time_driven_run_monitor(); sprintf(trace_string, "stopping time_driven_run monitor thread"); HTXD_TRACE(LOG_OFF, trace_string); } if(htxd_is_stop_watch_monitor_initialized() == TRUE) { htxd_instance = htxd_get_instance(); htxd_stop_stop_watch_monitor(&(htxd_instance->stop_watch_monitor_thread)); htxd_remove_stop_watch_monitor(); sprintf(trace_string, "stopping stop watch monitor thread"); HTXD_TRACE(LOG_OFF, trace_string); } htx_stats_pid = htxd_get_htx_stats_pid(); if (htx_stats_pid != 0) { htxd_send_SIGTERM(htx_stats_pid); sprintf(trace_string, "sent SIGTERM to hxstats process, pid <%d>", htx_stats_pid); HTXD_TRACE(LOG_OFF, trace_string); } #ifdef __HTX_LINUX__ if(htxd_is_hotplug_monitor_initialized() == TRUE) { htxd_instance = htxd_get_instance(); htxd_stop_hotplug_monitor(&(htxd_instance->p_hotplug_monitor_thread)); htxd_remove_hotplug_monitor(); sprintf(trace_string, "stopping hotplug monitor thread"); HTXD_TRACE(LOG_OFF, trace_string); } #endif #ifdef __HTXD_DR__ htx_dr_child_pid = htxd_get_dr_child_pid(); if (htx_dr_child_pid != 0) { htxd_send_SIGTERM(htx_dr_child_pid); sprintf(trace_string, "sent SIGTERM to DR child process, pid <%d>", htx_dr_child_pid); HTXD_TRACE(LOG_OFF, trace_string); } #endif htx_equaliser_pid = htxd_get_equaliser_pid(); if(htx_equaliser_pid != 0) { htxd_send_SIGTERM(htx_equaliser_pid); sprintf(trace_string, "sent SIGTERM to equaliser process, pid <%d>", htx_equaliser_pid); HTXD_TRACE(LOG_OFF, trace_string); } htxd_send_message ("Final message from test: System into idle state", 0, HTX_SYS_INFO, HTX_SYS_FINAL_MSG); sprintf(trace_string, "sent test final message to hxsmsg process"); HTXD_TRACE(LOG_OFF, trace_string); while(1) { #ifdef __HTXD_DR__ if( (htx_stats_pid == 0) && (htx_dr_child_pid == 0) ) { break; } htx_stats_pid = htxd_get_htx_stats_pid(); htx_dr_child_pid = htxd_get_dr_child_pid(); sleep(1); #else if(htx_stats_pid == 0) { break; } htx_stats_pid = htxd_get_htx_stats_pid(); sleep(1); #endif } while(1) { htx_msg_pid = htxd_get_htx_msg_pid(); if(htx_msg_pid == 0) { sprintf(trace_string, "hxsmsg is stopped"); HTXD_TRACE(LOG_OFF, trace_string); break; } sleep(1); sprintf(trace_string, "wating for exiting hxsmsg process, pid <%d>", htx_msg_pid); HTXD_TRACE(LOG_ON, trace_string); } while(1) { htx_equaliser_pid = htxd_get_equaliser_pid(); if(htx_equaliser_pid == 0) { sprintf(trace_string, "equaliser is stopped"); HTXD_TRACE(LOG_OFF, trace_string); break; } sleep(1); sprintf(trace_string, "wating for exiting equaliser process, pid <%d>", htx_equaliser_pid); HTXD_TRACE(LOG_ON, trace_string); } if (htxd_is_init_syscfg() == TRUE) { return_code = detach_syscfg(); if(return_code != 0) { sprintf(trace_string, "Internal error: failed to detach syscfg with error code <%d>", return_code); HTXD_TRACE(LOG_ON, trace_string); } htxd_set_init_syscfg_flag(FALSE); } htxd_cleanup_system_shm(); htxd_set_daemon_state(HTXD_DAEMON_STATE_IDLE); htxd_set_test_running_state(HTXD_TEST_HALTED); sprintf(trace_string, "daemon is in idle state now"); HTXD_TRACE(LOG_OFF, trace_string); 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; }
/* putting daemon back to idle state */ int htxd_idle_daemon(void) { int return_code; char trace_string[256]; pid_t htx_stats_pid; htxd *htxd_instance; #ifdef __HTXD_DR__ pid_t htx_dr_child_pid; #endif if(htxd_is_hang_monitor_initialized() == TRUE) { htxd_instance = htxd_get_instance(); htxd_stop_hang_monitor(&(htxd_instance->p_hang_monitor_thread)); htxd_remove_hang_monitor(); } htx_stats_pid = htxd_get_htx_stats_pid(); if (htx_stats_pid != 0) { htxd_send_SIGTERM(htx_stats_pid); } #ifdef __HTX_LINUX__ if(htxd_is_hotplug_monitor_initialized() == TRUE) { htxd_instance = htxd_get_instance(); htxd_stop_hotplug_monitor(&(htxd_instance->p_hotplug_monitor_thread)); htxd_remove_hotplug_monitor(); } #endif #ifdef __HTXD_DR__ htx_dr_child_pid = htxd_get_dr_child_pid(); if (htx_dr_child_pid != 0) { htxd_send_SIGTERM(htx_dr_child_pid); } #endif htxd_send_message ("System into idle state", 0, HTX_SYS_INFO, HTX_SYS_FINAL_MSG); while(1) { #ifdef __HTXD_DR__ if( (htx_stats_pid == 0) && (htx_dr_child_pid == 0) ) { break; } htx_stats_pid = htxd_get_htx_stats_pid(); htx_dr_child_pid = htxd_get_dr_child_pid(); sleep(1); #else if(htx_stats_pid == 0) { break; } htx_stats_pid = htxd_get_htx_stats_pid(); sleep(1); #endif } if (htxd_is_init_syscfg() == TRUE) { return_code = detach_syscfg(); if(return_code != 0) { sprintf(trace_string, "Internal error: failed to detach syscfg with error code <%d>", return_code); HTXD_TRACE(LOG_ON, trace_string); } htxd_set_init_syscfg_flag(FALSE); } htxd_cleanup_system_shm(); return 0; }