Пример #1
0
pid_t htxd_create_child_process(void)
{
	pid_t new_pid;
	char trace_string[256];
	int return_code;


	htxd_set_FD_close_on_exec_flag();
	new_pid = fork();
	if(new_pid == -1) {
		sprintf(trace_string, "fork failed with errno <%d>", errno);
		HTXD_TRACE(LOG_ON, trace_string);
	}

	if(new_pid == 0) {
		/* unblock all the signals for new process */
		return_code = htxd_thread_unblock_all_signals();
		if(return_code != 0) {
			sprintf(trace_string, "htxd_thread_unblock_all_signals returned with erro code <%d>", return_code);
			HTXD_TRACE(LOG_ON, trace_string);
		}
	}

	return new_pid;
}
Пример #2
0
/* read bytes from filename and create a read_buffer and store the bytes */
int htxd_read_file(char *filename, char **read_buffer)
{
	int read_file_fd;
	int return_code;
	struct stat read_file_stat;
	int size_of_read_buffer;
	int number_of_byes_read;
	char trace_string[256];


	*read_buffer = 0;

	return_code = stat(filename, &read_file_stat);
	if(return_code == -1 ) {
		sprintf(trace_string, "Error : htxd_read_file() open() return  = <%d>,  errno  = <%d>, filename = <%s>\n", return_code, errno, filename);
		HTXD_TRACE(LOG_ON, trace_string);
		return -1;
	}

	read_file_fd = open(filename, O_RDONLY);
	if(read_file_fd == -1) {
		sprintf(trace_string, "Error : htxd_read_file() open() return  = <%d>,  errno  = <%d>, filename = <%s>\n", return_code, errno, filename);
		HTXD_TRACE(LOG_ON, trace_string);
		return -1;
	}

	size_of_read_buffer = read_file_stat.st_size + 1024;

	*read_buffer = malloc(size_of_read_buffer);
	if(*read_buffer == NULL) {
		sprintf(trace_string, "Error : htxd_read_file() malloc(%d) return NULL, errno  = <%d>, filename = <%s>\n", size_of_read_buffer, errno, filename);
		HTXD_TRACE(LOG_ON, trace_string);
		close(read_file_fd);
		return -1;
	}

	memset(*read_buffer, 0, size_of_read_buffer);

	number_of_byes_read = read(read_file_fd, *read_buffer, size_of_read_buffer - 1024);
	if(number_of_byes_read == -1) {
		sprintf(trace_string, "Error : htxd_read_file() read() return <%d>, errno <%d>, filename = <%s>\n", number_of_byes_read, errno, filename);
		HTXD_TRACE(LOG_ON, trace_string);
	}
	if(number_of_byes_read == 0) {
		sprintf(*read_buffer, "file <%s> is empty", filename);
	}

	close(read_file_fd);

	return 0;
}
Пример #3
0
/* receive bytes */
int htxd_receive_bytes(int new_fd, char * receive_buffer, int receive_length)
{
	int	received_bytes;
	int	remaining_bytes;
	char	trace_string[256];


	remaining_bytes = receive_length;
	while(remaining_bytes > 0) {
		received_bytes = recv(new_fd, receive_buffer, remaining_bytes, 0);
		if(received_bytes == -1) {
			sprintf(trace_string, "htxd_receive_bytes: recv() returned with <%d>. errno <%d>", received_bytes, errno); 
			HTXD_TRACE(LOG_ON, trace_string);
			return -1;
		}

		if(received_bytes == 0) {
			break;
		}

		remaining_bytes -= received_bytes;
		receive_buffer += received_bytes;
	}	
	return 	(receive_length - remaining_bytes);
}
Пример #4
0
/* incomming command string receives here */
char * htxd_receive_command(int new_fd)  /* note: have to change for error handling */
{
	int	result;
	char	*command_details_buffer = NULL;
	char	temp_buffer[20];
	int	command_length;
	char	trace_string[256];


	memset(temp_buffer, 0, sizeof(temp_buffer) );
	/* receiving command  length from incomming commend */
	result = htxd_receive_bytes(new_fd, temp_buffer, 10);
	if(result == -1)
	{
		sprintf(trace_string, "htxd_receive_bytes returned -1"); 
		HTXD_TRACE(LOG_ON, trace_string);
		return NULL;
	}

	temp_buffer[COMMAND_STRING_LENGTH] = '\0';

	command_length = atoi(temp_buffer);

	/* now we are ready to receive the command string */
	command_details_buffer = malloc(command_length + 10);
	if(command_details_buffer == NULL)
	{
		sprintf(trace_string, "malloc() failed while allocating command_details_buffer"); 
		HTXD_TRACE(LOG_ON, trace_string)
		return NULL;
	} 
Пример #5
0
int htxd_verify_is_ready_to_start(void)
{
	char *command_string = "ps -aef | grep -E 'hxssup|hxe|eservd|hxsmsg|hxstats' | grep -v grep | awk '{print $8}' | grep -E 'hxssup|hxe|eservd|hxsmsg|hxstats' | wc -l";
	FILE *command_fp;
	char trace_string[512];
	int process_count;
	

	command_fp = popen(command_string, "r");
	if(command_fp == NULL) {
		sprintf(trace_string, "htxd_verify_is_ready_to_start: popen failed with errno <%d>", errno);
		HTXD_TRACE(LOG_ON, trace_string);
		return -1;
	}

	fscanf(command_fp, "%d", &process_count);
	
	pclose(command_fp);
	
	if(process_count == 0) {
		return 0;
	} else {
		sprintf(trace_string, "ps -aef | grep -E 'hxssup|hxe|eservd|hxsmsg|hxstats' | grep -v grep > %s/%s", global_htxd_log_dir, HTXD_PROCESS_CHECK_LOG);
		system(trace_string);
		return -1;
	}	
}
Пример #6
0
int htxd_verify_command_buffer_format(char *command_buffer)
{

	if(command_buffer == NULL) {
		HTXD_TRACE(LOG_ON, "htxd_verify_command_buffer_format: command_buffer is NULL");
		return -1;
	}

	if(strlen(command_buffer) == 0) {
		HTXD_TRACE(LOG_ON, "htxd_verify_command_buffer_format: commnad buffer length is 0");
		return -2;
	}

	if(command_buffer[0] != ':') {
		return -3;
	}

	return 0;
}
/* hxsstas : read exerciser info from shared memory and store it /tmp/htxstats file */
int htxd_load_hxstats(void)
{
	int hxstats_pid, rc = 0;
	char hxsstats_path[512], temp_str[300];


	hxstats_pid = htxd_create_child_process();
	switch(hxstats_pid)
	{
	case 0:
		strcpy(hxsstats_path, global_htx_home_dir);
		strcat(hxsstats_path, "/bin/hxstats");

		sprintf(temp_str, "%s/htxstats", global_htx_log_dir);
		execl(hxsstats_path, "hxstats", temp_str, "30", (char *) 0 );

		sprintf(temp_str, "htxd_load_hxstats: hxstats load failed, execl failed with errno <%d>", errno); 
		HTXD_TRACE(LOG_ON, temp_str);
		exit(errno);

	case -1:
		sprintf(temp_str, "htxd_load_hxstats: htxd_create_child_process returned -1 with errno <%d>", errno);
		HTXD_TRACE(LOG_ON, temp_str);
		exit(-1);

	default:
		htxd_set_htx_stats_pid(hxstats_pid);
	}

	htxd_reset_FD_close_on_exec_flag();
#ifdef __HTX_LINUX__
	if ((htxd_get_equaliser_offline_cpu_flag()) == 1) {
		rc = do_the_bind_proc(hxstats_pid);
		if (rc < 0) {
			sprintf(temp_str, "binding hxstats process to core 0 failed.");
			htxd_send_message(temp_str, 0, HTX_SYS_INFO, HTX_SYS_MSG);
		}

	}
#endif

	return 0;
}
Пример #8
0
/* creating a socket */
int htxd_create_socket(void)
{
	int	socket_fd;
	char	trace_string[256];


	socket_fd = socket (AF_INET, SOCK_STREAM, 0);
	if(socket_fd == -1)
	{
		sprintf(trace_string, "ERROR: while creating socket. Exiting... errno = %d, return_code = %d", errno, socket_fd); 
		HTXD_TRACE(LOG_ON, trace_string);
		perror(trace_string);
		exit(1);
	}

	if (fcntl(socket_fd, F_SETFD, FD_CLOEXEC) == -1) {
		sprintf(trace_string, "ERROR: while setting FD_CLOEXEC on socket. Exiting... errno = %d, return_code = %d", errno, socket_fd);
		HTXD_TRACE(LOG_ON, trace_string);
		perror(trace_string);
		exit(1);
	}

	return socket_fd;
}
Пример #9
0
int htxd_is_file_exist(char *filename)
{
	struct stat file_status;
	char trace_string[256];
	int return_code;


	return_code = stat(filename, &file_status);
	if( return_code == 0) {
		return TRUE;
	}

	sprintf(trace_string, "stat() failed at htxd_is_file_exist with return value = <%d>, errno = <%d>, filename <%s>, return", return_code, errno, filename);
	HTXD_TRACE(LOG_OFF, trace_string);
	return FALSE;
}
Пример #10
0
/* listening connection */
int htxd_listen_socket(int socket_fd)
{
	int	result;
	char	trace_string[256];


	result = listen (socket_fd, BACKLOG);
	if(result == -1)
	{
		sprintf(trace_string, "ERROR: while listening connection. Exiting... errno = %d, return_code = %d", errno, socket_fd); 
		HTXD_TRACE(LOG_ON, trace_string);
		perror(trace_string);
		exit(1);
	}

	return result;
}
Пример #11
0
/* update exer table with exer pid, usually after new exer is forked */
int htxd_update_exer_pid_in_exer_list(texer_list *p_exer_table, char *exer_name, pid_t new_exer_pid)
{

	int exer_position_in_exer_table;
	char trace_str[256];

	exer_position_in_exer_table = htxd_get_exer_position_in_exer_table_by_exer_name(p_exer_table, exer_name);
	if(exer_position_in_exer_table == -1) {
		sprintf(trace_str, "could not find exer_name <%s> in exer_table", exer_name);
		HTXD_TRACE(LOG_OFF, trace_str);
	} else {
		p_exer_table[exer_position_in_exer_table].exer_pid = new_exer_pid;
		/* printf("[DEBUG] : pid <%d> is updated for exer_name<%s> in exer_table at exer_position_in_exer_table <%d>\n", new_exer_pid, exer_name, exer_position_in_exer_table); fflush(stdout); */
	}

	return 0;
}
Пример #12
0
/* length received ack */
int htxd_send_ack_command_length(int new_fd)
{
	int result;
	char ack_string[] = ":length received:";
	char	trace_string[256];

	
	result = send (new_fd, ack_string, strlen (ack_string), 0);
	if(result == -1)
	{
		sprintf(trace_string, "htxd_receive_bytes: send() returned with <%d>. errno <%d>", result, errno); 
		HTXD_TRACE(LOG_ON, trace_string);
		return result;
	}

	return result;
}
Пример #13
0
/* bind socket */
int htxd_bind_socket(int socket_fd, struct sockaddr_in *local_address, int port_number)
{
	int	result;
	char	trace_string[256];


	result = bind (socket_fd, (struct sockaddr *) local_address, sizeof (struct sockaddr));
	if(result == -1)
	{
		sprintf(trace_string, "ERROR: while binding connection. Exiting... errno = %d, return_code = %d", errno, socket_fd); 
		HTXD_TRACE(LOG_ON, trace_string);
		perror(trace_string);
		exit(1);
	}

	return result;
}
Пример #14
0
/* setting socket option */
int htxd_set_socket_option(int socket_fd)
{
	int	result;
	int	option_value = 1;
	char	trace_string[256];


	result = setsockopt (socket_fd, SOL_SOCKET, SO_REUSEADDR, (void *) &option_value, sizeof (option_value) );
	if(result == -1)
	{
		sprintf(trace_string, "ERROR: while setting socket options. Exiting... errno = %d, return_code = %d", errno, socket_fd); 
		HTXD_TRACE(LOG_ON, trace_string);
		perror(trace_string);
		exit(1);
	}

	return result;
}
Пример #15
0
/* accept a connection */
int htxd_accept_connection(int socket_fd, struct sockaddr_in *p_client_address, socklen_t *p_address_length)
{
	int	new_fd;
	char	trace_string[256];


	memset((void*)p_client_address, 0, sizeof(struct sockaddr));
	*p_address_length = sizeof (struct sockaddr);
	new_fd = accept (socket_fd, (struct sockaddr *)p_client_address, p_address_length);
	if( (new_fd == -1) && (errno != EINTR) ) {
		sprintf(trace_string, "ERROR: while accepting connection. Exiting... errno = %d, return_code = %d", errno, socket_fd); 
		HTXD_TRACE(LOG_ON, trace_string)
		perror(trace_string);
		exit(1);
	}

	return new_fd; 
}
Пример #16
0
int htxd_init_start_halted_exerciser_mode( htxd_ecg_info *p_ecg_info)
{
	struct htxshm_HE	*p_HE;
	int			i;
	int			return_code = 0;
	char			temp_string[256];


	p_HE = (struct htxshm_HE *)(p_ecg_info->ecg_shm_addr.hdr_addr + 1);
	for(i = 0; i < p_ecg_info->ecg_shm_exerciser_entries ; i++) {
		if(p_HE->start_halted == 1 ) {
			return_code = htxd_set_device_run_sem_status(p_ecg_info->ecg_sem_id, i, 1);
			if(return_code != 0) {
				sprintf(temp_string, "htxd_set_device_run_sem_status: returns error code <%d>\n", return_code);
				HTXD_TRACE(LOG_OFF, temp_string);
			}
		}
	}

	return 0;
}
/* start equaliser process */
int htxd_start_equaliser(void)
{

	int rc = 0;
	pid_t equaliser_pid;
	char	temp_str[128];

	equaliser_pid = htxd_create_child_process();
	switch(equaliser_pid)
	{
	case 0:
		htxd_equaliser();
		sprintf(temp_str, "htxd_start_equaliser: returned from htxd_equaliser, exiting...");
		HTXD_TRACE(LOG_ON, temp_str);
		exit(0);
		break;

	case -1:
		sprintf(temp_str, "Unable to fork for equaliser process.  errno = %d", errno);
		htxd_send_message(temp_str, errno, HTX_SYS_HARD_ERROR, HTX_SYS_MSG);
		break;

	default:
		printf("DEBUG: equaliser process started with pid <%d>\n", equaliser_pid);
		htxd_set_equaliser_pid(equaliser_pid);
	#ifdef __HTX_LINUX__
		if ((htxd_get_equaliser_offline_cpu_flag()) == 1) {
			rc = do_the_bind_proc(equaliser_pid);
			if (rc < 0) {
				sprintf(temp_str, "binding equaliser process to core 0 failed.\n");
				htxd_send_message(temp_str, 0, HTX_SYS_INFO, HTX_SYS_MSG);
			}
		}
	#endif
		break;

	}

	return 0;
}
Пример #18
0
int htxd_execute_shell_profile(void)
{
	int return_status;
	int return_code;
	char trace_string[300];


#ifdef  __HTX_LINUX__
	sprintf(trace_string, "/bin/bash %s/etc/scripts/htx_setup.sh > %s/%s 2>&1", global_htx_home_dir, global_htxd_log_dir, HTXD_CREATE_MDT_LOG);
	return_status = system(trace_string);
#else
	sprintf(trace_string, "%s/etc/scripts/htx_setup > %s/%s 2>&1", global_htx_home_dir, global_htxd_log_dir, HTXD_CREATE_MDT_LOG);
	return_status = system(trace_string);
#endif

	return_code = WEXITSTATUS(return_status);
	if(return_code != 0) {
		sprintf(trace_string, "shell profile execute returned with code <%d>, ignoring the return code", return_code);
		HTXD_TRACE(LOG_ON, trace_string);
		return_code = 0;
	}
	return return_code;
}
Пример #19
0
/* select with timeout for reading */
int htxd_select_timeout(int socket_fd, int timeout_seconds)
{
	int		result;
	fd_set		read_fd_set;
	struct timeval	timeout;
	char		trace_string[256];

	FD_ZERO (&read_fd_set);

	timeout.tv_sec	= timeout_seconds;
	timeout.tv_usec	= SELECT_TIMEOUT_MICRO_SECONDS;

	FD_SET (socket_fd, &read_fd_set);

	result = select (socket_fd + 1, &read_fd_set, NULL, NULL, &timeout);
	if( (result == -1) && (errno != EINTR) ) {
		sprintf(trace_string, "ERROR: while selecting connection. Exiting... errno = %d, return_code = %d", errno, socket_fd); 
		HTXD_TRACE(LOG_ON, trace_string)
		perror(trace_string);
		exit(1);
	}

	return result;
}
/* hxsmsg : picks messages from HTX message queue and stores the messages in files */
int htxd_load_hxsmsg(htxd_profile *p_profile)
{
	int hxsmsg_pid, rc = 0;
	char hxsmsg_path[512], temp_str[256];
	char auto_start_flag_string[8];


	hxsmsg_pid = htxd_create_child_process();
	switch(hxsmsg_pid)
	{
	case 0:
		strcpy(hxsmsg_path, global_htx_home_dir);
		strcat(hxsmsg_path, "/bin/hxsmsg");

		sprintf(temp_str, "%s/%s", global_htx_home_dir, HTXD_AUTOSTART_FILE);
		if(htxd_is_file_exist(temp_str) == FALSE) {
			strcpy(auto_start_flag_string, "no");
		} else {
			strcpy(auto_start_flag_string, "yes");
		}

		execl(	hxsmsg_path,
				"hxsmsg",
				p_profile->max_htxerr_size,
				p_profile->max_htxmsg_size,
				p_profile->max_htxerr_save_size,
				p_profile->max_htxmsg_save_size,
				p_profile->htxerr_wrap,
				p_profile->htxmsg_wrap,
				p_profile->htxmsg_archive,
				auto_start_flag_string,
				p_profile->stress_device,
				p_profile->stress_cycle,
				(char *) 0);
		sprintf(temp_str, "htxd_load_hxsmsg: hxsmsg load failedi, execl returned with errno  <errno : %d> !!!", errno); 
		HTXD_TRACE(LOG_ON, temp_str);
		exit(errno);

	case -1:
		return -1;
		break;

	default:
		htxd_set_htx_msg_pid(hxsmsg_pid);
	#ifdef __HTX_LINUX__
		if ((htxd_get_equaliser_offline_cpu_flag()) == 1) {
			rc = do_the_bind_proc(hxsmsg_pid);
			if (rc < 0) {
				sprintf(temp_str, "binding hxsmsg process to core 0 failed.");
				htxd_send_message(temp_str, 0, HTX_SYS_INFO, HTX_SYS_MSG);
				HTXD_TRACE(LOG_ON, temp_str);
			}

		}
	#endif
		break;
	}

	htxd_reset_FD_close_on_exec_flag();

	return 0;
}
Пример #21
0
short htxd_send_message(char *msg_text, int errno_val, int  severity, mtyp_t msg_type)
{
	int msgqid;
	time_t  system_time;
	char str_time_temp[50];
	char *program_name;
	char char_time[50];
	short exit_code = 0;
	int errno_save;
	char error_msg[512];
	struct htx_msg_buf msg_buffer;
	size_t str_length;
	struct tm new_time;


	msgqid = htxd_get_msg_queue_id();
/* 	printf("DEBUG: htxd_send_message()enter :  msgqid=<%d>\n", msgqid); */

	memset(&msg_buffer, 0, sizeof(msg_buffer) );

	if (msgqid != -1) {
		if (strlen(msg_text) > MAX_TEXT_MSG) {
			msg_text[MAX_TEXT_MSG] = '\0';
			exit_code |= MSG_TOO_LONG;
		}

		errno = 0;

		program_name = htxd_get_program_name();

#ifdef __HTX_LINUX__
		system_time = time((time_t *) NULL);
		localtime_r(&system_time, &new_time);
		asctime_r(&new_time, str_time_temp);
		memset(char_time, '\0', sizeof(char_time));
		strncpy(char_time, (str_time_temp + 4), 20);
#else
		system_time = time((time_t *) NULL);
		if(system_time ==0) {
			errno_save = errno;
			(void) sprintf(error_msg,"\n%s -- Error in the time() system call of the send_message() function.\nerrno: %d (%s).\n",program_name, errno_save, strerror(errno_save));
			fprintf(stderr, "%s", error_msg);
			fflush(stderr);
			HTXD_TRACE(LOG_ON, error_msg);
			exit_code |= BAD_GETTIMER;
			strcpy(char_time, "time() error");
		} else {
			localtime_r(&system_time, &new_time);
			asctime_r(&new_time, str_time_temp);
			memset(char_time, '\0', sizeof(char_time));
			strncpy(char_time, (str_time_temp + 4), 20);
		}
#endif


/*		strcpy(msg_buffer.htx_data.sdev_id, "htx_messages");
		msg_buffer.htx_data.error_code = errno_val;
		msg_buffer.htx_data.severity_code = severity;
		strcpy(msg_buffer.htx_data.HE_name, program_name);

*/


		strncpy(msg_buffer.htx_data.sdev_id, "", sizeof(msg_buffer.htx_data.sdev_id));
		strncpy(msg_buffer.htx_data.sdev_id, "htx_messages", (sizeof(msg_buffer.htx_data.sdev_id) - 1));
		msg_buffer.htx_data.error_code = errno_val;
		msg_buffer.htx_data.severity_code = severity;
		strncpy(msg_buffer.htx_data.HE_name, "", sizeof(msg_buffer.htx_data.HE_name));
		strncpy(msg_buffer.htx_data.HE_name, program_name, (sizeof(msg_buffer.htx_data.HE_name) - 1));

		sprintf(msg_buffer.htx_data.msg_text,"---------------------------------------------------------------------\nDevice id      : %-18s\nTimestamp      : %-20s\nerr            : %-8.8x\nsev            : %d\nExerciser Name : %-14s\nError Text     : %s\n---------------------------------------------------------------------\n",
			msg_buffer.htx_data.sdev_id,
			char_time,
			msg_buffer.htx_data.error_code,
			msg_buffer.htx_data.severity_code,
			msg_buffer.htx_data.HE_name,
			msg_text);

		str_length = strlen(msg_buffer.htx_data.msg_text);
		if (msg_buffer.htx_data.msg_text[str_length - 2] != '\n') {
			strcat(msg_buffer.htx_data.msg_text, "\n");
		}

		msg_buffer.mtype = msg_type;

		errno = 0;

		if (msgsnd(msgqid, &msg_buffer, (sizeof(msg_buffer) - sizeof(mtyp_t)), IPC_NOWAIT) != GOOD) {
			errno_save = errno;
			sprintf(error_msg, "\n%s -- Error in msgsnd() system call of the send_message() function.\nerrno: %d (%s).\n",
				program_name,
				errno_save,
				strerror(errno_save));

			fprintf(stderr, "%s", error_msg);
			fflush(stderr);
			HTXD_TRACE(LOG_ON, error_msg);
			exit_code |= BAD_MSGSND;
		}
	} else {
		fprintf(stderr, "%s", msg_text);
		fflush(stderr);
		HTXD_TRACE(LOG_ON, error_msg);
		exit_code |= NO_MSG_QUEUE;
	}

	return(exit_code);
}
Пример #22
0
int htxd_set_shm_with_exercisers_values_for_dr_restart(char *dr_ecg_name)
{
	CFG__SFT *ecg_fd;
	int return_code = 0;
	htxd_ecg_info *p_running_ecg_info;
	char *running_ecg_name;
	htxd_ecg_manager *p_ecg_manager;
	char default_ecg_stanza[4096];
	char ecg_stanza[4096];
	union shm_pointers shm_point;
	int dup_flag = 0;
	char temp_device_name[80];
	int device_position;
	char trace_string[256];



	ecg_fd = cfgcopsf (dr_ecg_name);
	if(ecg_fd == (CFG__SFT *) NULL) {
		HTXD_TRACE(LOG_ON, "htxd_set_shm_exercisers_values_for_dr_restart() return: ecg_fd == (CFG__SFT *) NULL");
		return -1;
	}

	return_code = cfgcrdsz (ecg_fd, default_ecg_stanza, sizeof (default_ecg_stanza), "default");
	if(return_code != CFG_SUCC) {
		HTXD_TRACE(LOG_ON, "htxd_set_shm_exercisers_values_for_dr_restart() return: return_code != CFG_SUCC");
		return -1;
	}

	p_ecg_manager = htxd_get_ecg_manager();
	running_ecg_name = htxd_get_running_ecg_name();

	p_running_ecg_info = htxd_get_ecg_info_node(p_ecg_manager, running_ecg_name);

	shm_point.hdr_addr = p_running_ecg_info->ecg_shm_addr.hdr_addr + 1;
	shm_point.HE_addr += p_running_ecg_info->ecg_shm_exerciser_entries;
	while( (return_code =  htxd_extract_ecg_to_shm_HE(p_ecg_manager, ecg_stanza, sizeof (ecg_stanza), shm_point,(char **) NULL, ecg_fd, &dup_flag, temp_device_name)) == CFG_SUCC){
		if(dup_flag == FALSE) {
			htxd_update_exer_table(p_ecg_manager, shm_point, 8);
			(shm_point.HE_addr)++;
			(p_running_ecg_info->ecg_shm_exerciser_entries)++;
			p_running_ecg_info->ecg_shm_addr.hdr_addr->num_entries = p_running_ecg_info->ecg_shm_exerciser_entries;
			(p_running_ecg_info->ecg_shm_addr.hdr_addr->max_entries)++;
		} else {
			if(htxd_is_device_need_dr_restart(p_running_ecg_info, temp_device_name) == FALSE) {
				continue;
			}
		}

		device_position = htxd_get_device_position_in_shm_HE(p_running_ecg_info, temp_device_name);
		if(device_position == -1) {
			HTXD_TRACE(LOG_ON, "Inavlid device position in HE shared memory");
			continue;
		}
	/*	htxd_display_ecg_info_list();
		htxd_display_exer_table(); */
		htxd_set_device_restart_status(p_running_ecg_info, device_position);

	}
	if(return_code != CFG_EOF) {
		sprintf(trace_string, "htxd_extract_ecg_to_shm_HE returned with %d", return_code);
		HTXD_TRACE(LOG_ON, trace_string);
		return -1;
	}

	return_code = cfgcclsf (ecg_fd);
	if(return_code != CFG_SUCC) {
		sprintf(trace_string, "cfgcclsf returned with <%d>", return_code);
		HTXD_TRACE(LOG_ON, trace_string);
		return -1;
	}

	return 0;
}
Пример #23
0
/* allocating IPC resources required for the new ECG */
int htxd_init_ecg_info(htxd_ecg_manager *this_ecg_manager, char *new_ecg_name)
{
	int number_of_devices;
	int max_number_of_devices;
	char error_msg[1024];
	htxd_ecg_info *p_current_ecg_info;
	int next_key_offset;
	char temp_string[256];


	HTXD_FUNCTION_TRACE(FUN_ENTRY, "htxd_init_ecg_info");

	sprintf(temp_string, "start processing ECG <%s>", new_ecg_name);
	HTXD_TRACE(LOG_OFF, temp_string);
	/* htxd_send_message (temp_string, 0, HTX_SYS_INFO, HTX_SYS_MSG); */

	htxd_allocate_ecg_info(this_ecg_manager);

	number_of_devices = htxd_get_number_of_device(new_ecg_name, error_msg);
	max_number_of_devices = number_of_devices + EXTRA_DEVICE_ENTRIES;

	p_current_ecg_info = this_ecg_manager->current_loading_ecg_info;
	p_current_ecg_info->ecg_info_next = NULL;

	p_current_ecg_info->ecg_exerciser_entries = number_of_devices;
	p_current_ecg_info->ecg_max_exerciser_entries = max_number_of_devices;
	p_current_ecg_info->ecg_shm_exerciser_entries = 0;
	strcpy( p_current_ecg_info->ecg_name, new_ecg_name);
	p_current_ecg_info->ecg_status = ECG_UNLOADED;

	next_key_offset = htxd_get_next_key_offset(this_ecg_manager);

	p_current_ecg_info->ecg_shm_key = ECG_SHMKEY_START + next_key_offset;
	p_current_ecg_info->ecg_sem_key = ECG_SEMKEY_START + next_key_offset;


	HTXD_TRACE(LOG_OFF, "allocationg semaphore for ecg_info");
	/* allocating semaphore */
	if( (p_current_ecg_info->ecg_sem_id = htxd_init_sem(p_current_ecg_info->ecg_sem_key, max_number_of_devices) ) == -1 ) {
		return -1;
	}

	HTXD_TRACE(LOG_OFF, "allocationg shared memory for ecg_info");
	/* allocating shared memory */
	if( ( p_current_ecg_info->ecg_shm_addr.hdr_addr = htxd_init_shm(p_current_ecg_info->ecg_shm_key, max_number_of_devices,&(p_current_ecg_info->ecg_shm_id) ) ) == NULL ) {
		return -1;
	}

	/* setting shared memory with header values */
	HTXD_TRACE(LOG_OFF, "setting shm header values");
	htxd_set_shm_header_values(this_ecg_manager);

	/* setting shared memory with HE values */
	HTXD_TRACE(LOG_OFF, "setting shm HE values");
	htxd_set_shm_exercisers_values(this_ecg_manager, new_ecg_name);

	/* initialize equaliser info */
	HTXD_TRACE(LOG_OFF, "initialize equaliser_info");
	htxd_init_equaliser_info(p_current_ecg_info);

	/* initialize start-halted mode */
	htxd_init_start_halted_exerciser_mode(p_current_ecg_info);

	p_current_ecg_info->ecg_status = ECG_INACTIVE;

	p_current_ecg_info->ecg_shm_addr.hdr_addr->num_entries = p_current_ecg_info->ecg_shm_exerciser_entries;
	(this_ecg_manager->ecg_list_length)++;

	HTXD_FUNCTION_TRACE(FUN_EXIT, "htxd_init_ecg_info");
	return 0;
}
/* load exerciser : start exerciser process */
int htxd_load_exerciser(struct htxshm_HE *p_HE)
{

	int exerciser_pid;
	int temp_int;
	char exerciser_path[512];
	char exerciser_name[64];
	char device_name[64];
	char run_mode[64];
	char rule_path[64];
	int emc_mode;
	char trace_str[256];


	HTXD_FUNCTION_TRACE(FUN_ENTRY, "htxd_load_exerciser");
	sprintf(trace_str, "loading exerciser <%s>", p_HE->sdev_id);
	HTXD_TRACE(LOG_OFF, trace_str);
	exerciser_pid = htxd_create_child_process();
	switch(exerciser_pid)
	{
	case 0:
		setsid();

		temp_int = p_HE->priority;
		nice(temp_int);

		sleep(5);   /* let daemon update shared memory */

		strcpy(exerciser_name, p_HE->HE_name);

		if (strcmp(p_HE->HE_name, "hxemem64") == 0) {
			putenv("CORE_NOSHM=true");
		}

		if (strcmp(p_HE->HE_name, "hxepowermixer") == 0) {
			putenv("MEMORY_AFFINITY=MCM");
		}

		strcpy(exerciser_path, global_htx_home_dir);
		strcat(exerciser_path, "/bin/");
		strcat(exerciser_path, exerciser_name);

		strcpy(device_name, "/dev/");
		strcat(device_name, p_HE->sdev_id);

		emc_mode = htxd_get_emc_mode();
		if(emc_mode == 1) {
			strcpy(run_mode, "EMC");
		} else {
			strcpy(run_mode, "REG");
		}

		if(emc_mode == 1) {
			if(p_HE->emc_rules[0] != '/') {
				sprintf(rule_path, "%s/rules/emc/%s", global_htx_home_dir, p_HE->emc_rules);
			} else {
				strcpy(rule_path, p_HE->emc_rules);
			}
		} else {
			if(p_HE->reg_rules[0] != '/') {
				sprintf(rule_path, "%s/rules/reg/%s", global_htx_home_dir, p_HE->reg_rules);
			} else {
				strcpy(rule_path, p_HE->reg_rules);
			}
		}

		/* system("export EXTSHM=OFF"); */
		unsetenv("EXTSHM");

		if ( (execl(exerciser_path, exerciser_name, device_name, run_mode, rule_path, (char *) 0) ) == -1) {
			sprintf(trace_str, "execl() failed  exerciser_path <%s> exerciser_name <%s> errno = <%d>\n", exerciser_path, exerciser_name, errno);
			htxd_send_message (trace_str, 0, HTX_SYS_SOFT_ERROR, HTX_SYS_MSG);
			HTXD_TRACE(LOG_ON, trace_str);
			exit(-1);
		}

	case -1:
		sprintf(trace_str, "exerciser <%s> fork failed with error <%d>", p_HE->sdev_id, errno);
		HTXD_TRACE(LOG_ON, trace_str);
		return -1;

	default:
		p_HE->PID = exerciser_pid;
		htxd_update_exer_pid_in_exer_list(htxd_get_exer_table(), p_HE->sdev_id, exerciser_pid);
		sprintf(trace_str, "exerciser <%s> forked with PID <%d>", p_HE->sdev_id, p_HE->PID);
		HTXD_TRACE(LOG_OFF, trace_str);
		break;
	}
	htxd_reset_FD_close_on_exec_flag();

	HTXD_FUNCTION_TRACE(FUN_EXIT, "htxd_load_exerciser");
	return 0;
}
Пример #25
0
/* 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;
}
Пример #26
0
/* daemon live here, receives command, process it, send back result */
int htxd_start_daemon(htxd *htxd_instance)
{

	int			result				= 0;
	int			socket_fd;
	struct sockaddr_in	local_address;
	struct sockaddr_in	client_address;
	socklen_t		address_length;
	int			client_socket_fd;
	htxd_thread		command_thread;



	HTXD_FUNCTION_TRACE(FUN_ENTRY, "htxd_start_daemon");

	init_option_list();
	htxd_launch_autostart();

	if(htxd_is_profile_initialized(htxd_instance) != TRUE) {
		HTXD_TRACE(LOG_ON, "initialize HTX profile details");
		htxd_init_profile(&(htxd_instance->p_profile));
		/* htxd_display_profile(htxd_instance->p_profile);  */ /* To DEBUG */
	}

	socket_fd = htxd_create_socket();

	result = htxd_set_socket_option(socket_fd);

	local_address.sin_family = AF_INET;
	local_address.sin_port = htons (htxd_instance->port_number);
	local_address.sin_addr.s_addr = INADDR_ANY;
	memset (&(local_address.sin_zero), '\0', 8);


	result = htxd_bind_socket(socket_fd, &local_address, htxd_instance->port_number);

	result = htxd_listen_socket(socket_fd);

	HTXD_TRACE(LOG_ON, "starting daemon main loop");
	do  /* this loop make the daemon live */
	{
		if(htxd_shutdown_flag == TRUE) {
			break;
		}

		client_socket_fd = htxd_accept_connection(socket_fd, &client_address, &address_length);
		if(client_socket_fd == -1)
		{
			if(htxd_shutdown_flag == TRUE) {
				break;
			}
			HTXD_TRACE(LOG_ON, "htxd_accept_connection returned -1, ignoring and continue...");
			continue;
		}

		HTXD_TRACE(LOG_OFF, "found a command for receiving");
	
		memset(&command_thread, 0, sizeof(htxd_thread));
		command_thread.thread_function = htxd_command_thraead_handler;
		command_thread.thread_data = malloc(sizeof(int));
		(*((int *)command_thread.thread_data)) = client_socket_fd;
		command_thread.thread_stack_size = 10000000;
	
		htxd_create_command_thread(&command_thread);	


	} while(htxd_shutdown_flag == FALSE);

	htxd_shutdown_all_mdt();

	HTXD_FUNCTION_TRACE(FUN_EXIT, "htxd_start_daemon");

	return result;
}
/* 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;
}
Пример #28
0
void *htxd_command_thraead_handler(void *ptr_socket)
{

	char *		command_buffer		= NULL;
	htxd_command	command_object;
	int		command_return_code	= 0;
	int		client_socket;
	char *		command_result		= NULL;
	char		trace_string[256];
	int		result			= 0;


	client_socket = *( (int *)ptr_socket);	
	free(ptr_socket);
	/* receive the incoming command */
	HTXD_TRACE(LOG_OFF, "daemon receiving command");
	command_buffer = htxd_receive_command(client_socket);
	if(command_buffer == NULL)
	{
		sprintf(trace_string, "Error : htxd_receive_command: returned NULL");
		HTXD_TRACE(LOG_ON, trace_string);
		return NULL;
	}

	HTXD_TRACE(LOG_OFF, "command received start<<");
	HTXD_TRACE(LOG_OFF, command_buffer);
	HTXD_TRACE(LOG_OFF, ">> command received end");

	if(htxd_verify_command_buffer_format(command_buffer) != 0) {
		HTXD_TRACE(LOG_ON, "htxd_start_daemon: htxd_verify_command_buffer_format failed for the command buffer");
		HTXD_TRACE(LOG_ON, "further processing of the command will be ignored");

		sprintf(trace_string, "Error while receiving command, errno <%d>", errno);
		result = htxd_send_response(client_socket, trace_string, 1, -1);
		if(result == -1) {
			HTXD_TRACE(LOG_ON, "1. htxd_send_response() is returned -1, ignoring further processing of the command");
		}
		HTXD_TRACE(LOG_ON, trace_string);
		close(client_socket);
		if(command_buffer != NULL) {
			free(command_buffer);
			command_buffer = NULL;
		} 
		
		return NULL;
	} 

	htxd_update_command_object(command_buffer, &command_object);

	if(command_buffer != NULL) {
		free(command_buffer);
		command_buffer = NULL;
	} 

	/* process the received command */
	HTXD_TRACE(LOG_OFF, "daemon start processing command");
	command_return_code = htxd_process_command(&command_result, &command_object);

	/* handling if command did not generate result buffer */		
	if(command_result == NULL) {
		command_result = malloc(HTX_ERR_MESSAGE_LENGTH);
		if(command_result == NULL) {
			sprintf(trace_string, "Error : malloc(%d) failed with errno = <%d> while allocating error message", HTX_ERR_MESSAGE_LENGTH, errno);
			HTXD_TRACE(LOG_ON, trace_string); 
			exit(1);
		}
		strcpy(command_result, "No result is generated by the command");
	}

	HTXD_TRACE(LOG_OFF, "command result start<<");
	HTXD_TRACE(LOG_OFF, command_result);
	HTXD_TRACE(LOG_OFF, ">> command result end");

	/* send back command result to client */
	HTXD_TRACE(LOG_OFF, "daemon sending the result to client");
	result = htxd_send_response(client_socket, command_result, command_object.command_type, command_return_code);
	if(result == -1)
	{
		sprintf(trace_string, "Error : htxd_send_response returned with -1");
		HTXD_TRACE(LOG_ON, trace_string); 
		return NULL;
	}
	
	if(command_result != 0) {
		free(command_result);
	}

	close(client_socket);

	htxd_exit_command_thread();	

	return NULL;
}
/* 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;

}
Пример #30
0
/* daemon live here, receives command, process it, send back result */
int htxd_start_daemon(htxd *htxd_instance)
{

	int					result				= 0;
	int					socket_fd;
	struct sockaddr_in	local_address;
	struct sockaddr_in	client_address;
	socklen_t			address_length;
	int					new_fd;
	char *				command_buffer		= NULL;
	char *				command_result		= NULL;
	int					command_return_code	= 0;
	char			trace_string[256];


	HTXD_FUNCTION_TRACE(FUN_ENTRY, "htxd_start_daemon");

	init_option_list();
	htxd_autostart(htxd_instance);  /* try autostart if find the autostart flag file */

	socket_fd = htxd_create_socket();

	result = htxd_set_socket_option(socket_fd);

	local_address.sin_family = AF_INET;
	local_address.sin_port = htons (htxd_instance->port_number);
	local_address.sin_addr.s_addr = INADDR_ANY;
	memset (&(local_address.sin_zero), '\0', 8);

	result = htxd_bind_socket(socket_fd, &local_address, htxd_instance->port_number);

	result = htxd_listen_socket(socket_fd);

	HTXD_TRACE(LOG_ON, "starting daemon main loop");
	do  /* this loop make the daemon live */
	{
		do  /* this loop listens for incomming messages */
		{
			HTXD_TRACE(LOG_OFF, "daemon wating for command");
			result = htxd_select(socket_fd);
			if(htxd_shutdown_flag == TRUE) {
				break;
			}
		}while( (result == -1) && (errno == EINTR) );
		if(htxd_shutdown_flag == TRUE) {
			break;
		}

		new_fd = htxd_accept_connection(socket_fd, &client_address, &address_length);
		if(new_fd == -1)
		{
			if(htxd_shutdown_flag == TRUE) {
				break;
			}
			HTXD_TRACE(LOG_OFF, "select time out");
			continue;
		}

		HTXD_TRACE(LOG_OFF, "found a command for receiving");
	
		if(htxd_is_profile_initialized(htxd_instance) != TRUE) {
			HTXD_TRACE(LOG_ON, "initialize HTX profile details");
			htxd_init_profile(&(htxd_instance->p_profile));
			/* htxd_display_profile(htxd_instance->p_profile);  */ /* To DEBUG */
			register_signal_handlers();	
		}

		/* receive the incomming command */
		HTXD_TRACE(LOG_OFF, "daemon receiving command");
		command_buffer = htxd_receive_command(new_fd);
		if(command_buffer == NULL)
		{
			return -1;
		}

		HTXD_TRACE(LOG_OFF, "command received start<<");
		HTXD_TRACE(LOG_OFF, command_buffer);
		HTXD_TRACE(LOG_OFF, ">> command received end");

		htxd_update_command_object(command_buffer);

		if(command_buffer != NULL) {
			free(command_buffer);
			command_buffer = NULL;
		} 

		/* process the received command */
		HTXD_TRACE(LOG_OFF, "daemon start processing command");
		command_return_code = htxd_process_command(&command_result);

		/* handling if command did not generate result buffer */		
		if(command_result == NULL) {
			command_result = malloc(HTX_ERR_MESSAGE_LENGTH);
			if(command_result == NULL) {
				sprintf(trace_string, "Error : malloc(%d) failed with errno = <%d> while allocating error message", HTX_ERR_MESSAGE_LENGTH, errno);
				HTXD_TRACE(LOG_ON, trace_string); 
				exit(1);
			}
			strcpy(command_result, "No result is generated by the command");
		}

		HTXD_TRACE(LOG_OFF, "command result start<<");
		HTXD_TRACE(LOG_OFF, command_result);
		HTXD_TRACE(LOG_OFF, ">> command result end");

		/* send back command result to client */
		HTXD_TRACE(LOG_OFF, "daemon sending the result to client");
		result = htxd_send_response(new_fd, command_result, command_return_code);
		if(result == -1)
		{
			return result;
		}
		
		if(command_result != 0) {
			free(command_result);
		}
		close(new_fd);

	} while(htxd_shutdown_flag == FALSE);

	if(htxd_get_ecg_list_length(htxd_instance->p_ecg_manager) > 0)
	{
		/* shutdown all running ecgs and return */	
		// htxd_shutdown_all_running_ecgs();
	}

	htxd_shutdown_all_mdt();

	HTXD_FUNCTION_TRACE(FUN_EXIT, "htxd_start_daemon");

	return result;
}