static char *pmon_get_permanent_pname(int pid)
{
	int fd;
	char buf[PATH_MAX];
	struct stat st;
	char *cmdline = NULL;

	snprintf(buf, sizeof(buf), "%s/%d", PMON_PERMANENT_DIR, pid);
	fd = open(buf, O_RDONLY);
	if (fd == -1) {
		PRT_TRACE_ERR("file open error");
		return NULL;
	}

	if (fstat(fd, &st) < 0) {
		PRT_TRACE_ERR("fstat error");
		return NULL;
	}

	PRT_TRACE("size = %d", (int)st.st_size);

	cmdline = malloc(st.st_size + 1);
	if (cmdline == NULL) {
		PRT_TRACE_ERR("Not enough memory");
		return NULL;
	}
	memset(cmdline, 0, st.st_size + 1);

	read(fd, cmdline, st.st_size);
	/* TODO - must change more smarter */
	replace_char(st.st_size - 1, cmdline);
	close(fd);

	return cmdline;
}
int ss_pmon_init(struct ss_main_data *ad)
{
	char pmon_dev_node[PATH_MAX];

	if (0 > plugin_intf->OEM_sys_get_process_monitor_node(pmon_dev_node)) {
		PRT_TRACE_ERR("ss_pmon_init get dev node path failed");
		return -1;
	}

	pmon_fd = open(pmon_dev_node, O_RDONLY);
	if (pmon_fd < 0) {
		PRT_TRACE_ERR("ss_pmon_init fd open failed");
		return -1;
	}
	ecore_main_fd_handler_add(pmon_fd, ECORE_FD_READ, pmon_cb, ad, NULL,
				  NULL);
	return 0;
}
int launch_app_with_nice(const char *file, char *const argv[], pid_t *pid, int _nice)
{
	int ret;
	int _pid;

	if (file == NULL || access(file, X_OK) != 0) {
		PRT_TRACE_ERR("launch app error: Invalid input");
		errno = EINVAL;
		return -1;
	}

	if (pid && (*pid > 0 && kill(*pid, 0) != -1))
		return *pid;

	_pid = fork();

	if (_pid == -1) {
		PRT_TRACE_ERR("fork error: %s", strerror(errno));
		/* keep errno */
		return -1;
	}

	if (_pid > 0) {     /* parent */
		if (pid)
			*pid = _pid;
		return _pid;
	}

	/* child */
	prepare_exec();

	ret = nice(_nice);

	if (ret == -1 && errno != 0)
		PRT_TRACE_ERR("nice error: %s", strerror(errno));

	ret = execvp(file, argv);

	/* If failed... */
	PRT_TRACE_ERR("exec. error: %s", strerror(errno));
	return -2;
}
Пример #4
0
static int custom_cb(void *data, Ecore_Fd_Handler * fd_handler)
{
	int fd;
	struct message_data *msg; //-------

	PRT_ERR("[gandan] %s: socket data received\n", __FUNCTION__);

	struct sockaddr_un client_address;
	int client_sockfd;
	int client_len;


	if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) {
		PRT_TRACE_ERR
		    ("ecore_main_fd_handler_active_get error , return\n");
		return 1;
	}

	fd = ecore_main_fd_handler_fd_get(fd_handler);
	msg = malloc(sizeof(struct message_data)); //-------
	if (msg == NULL) {
		PRT_TRACE_ERR("%s : Not enough memory", __FUNCTION__);
		return 1;
	}

	client_len = sizeof(client_address);
	client_sockfd = accept(fd, (struct sockaddr *)&client_address, (socklen_t *)&client_len);

	if (client_sockfd == -1) {
		PRT_TRACE_ERR("socket accept error");
		free(msg);
		return -1;
	}

	read_message(client_sockfd, msg);
	PRT_ERR("[gandan] received data : %d\n", msg->val);

	PRT_ERR("[gandan] %s: socket data receive end\n", __FUNCTION__);
	free(msg);

	return 1;
}
static int pmon_cb(void *data, Ecore_Fd_Handler * fd_handler)
{
	int fd;
	struct ss_main_data *ad = (struct ss_main_data *)data;
	int dead_pid;

	if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) {
		PRT_TRACE_ERR
		    ("ecore_main_fd_handler_active_get error , return\n");
		return 1;
	}

	fd = ecore_main_fd_handler_fd_get(fd_handler);

	if ((read(fd, &dead_pid, sizeof(dead_pid))) < 0) {
		PRT_TRACE_ERR("Reading DEAD_PID failed, Return");
		return 1;
	}
		
	print_pmon_state(dead_pid);
	pmon_process(dead_pid, ad);

	return 1;
}
int ss_launch_after_kill_if_exist(const char *execpath, const char *arg, ...)
{
	char *buf;
	int pid;
	int nice_value = 0;
	int flag = 0;
	int buf_size = -1;
	int exist_pid;
	va_list argptr;

	if (execpath == NULL) {
		errno = EINVAL;
		return -1;
	}

	if ((exist_pid = sysman_get_pid(execpath)) > 0)
		kill(exist_pid, SIGTERM);

	va_start(argptr, arg);
	flag = va_arg(argptr, int);

	if (flag & SS_LAUNCH_NICE)
		nice_value = va_arg(argptr, int);

	va_end(argptr);

	ss_set_current_lang();

	arg = _S(arg);

	buf_size = strlen(execpath) + strlen(arg) + 10;
	buf = malloc(buf_size);
	if (buf == NULL) {
		/* Do something for not enought memory error */
		PRT_TRACE_ERR("Malloc Failed");
		return -1;
	}

	snprintf(buf, buf_size, "%s %s", execpath, arg);
	pid = launch_app_cmd_with_nice(buf, nice_value);
	if (pid == -2)
		exit(0);
	free(buf);

	return pid;

}
Пример #7
0
static int __custom_start(void){
	int fd;

	fd = custom_server_init();
	if ( fd < 0 )
		return -1;

	//ECORE_FD_READ , ECORE_FD_WRITE
	custom_efd = ecore_main_fd_handler_add(fd, ECORE_FD_READ, custom_cb, NULL, NULL, NULL);

	if (!custom_efd ) {
		PRT_TRACE_ERR("error ecore_main_fd_handler_add");
		return -1;
	}
	return fd;

}
int launch_app_cmd_with_nice(const char *cmdline, int _nice)
{
	int i;
	int nargs;
	int ret;
	char *argv[MAX_ARGS + 1];

	nargs = parse_cmd(cmdline, argv, MAX_ARGS + 1);
	if (nargs == -1) {
		PRT_TRACE_ERR("launch app error: Invalid input");
		errno = EINVAL;
		return -1;
	}

	ret = launch_app_with_nice(argv[0], argv, NULL, _nice);

	for (i = 0; i < nargs; i++)
		free(argv[i]);

	return ret;
}
static int pmon_process(unsigned int pid, void *ad)
{
	char *cmdline;
	int new_pid;
	char old_file[PATH_MAX];
	int fd;

	if (sysconf_is_vip(pid)) {
		PRT_TRACE_ERR("=======================================");
		PRT_TRACE_ERR("[Process MON] VIP process dead.");
		PRT_TRACE_ERR("=======================================");
	}
	/* If there is NOT a .hibernation_start file, run following codes 
	 * On hibernation processing, just ignore relaunching */
	else if (access("/tmp/.hibernation_start", R_OK) != 0) {
		cmdline = pmon_get_permanent_pname(pid);
		if (cmdline != NULL) {
			PRT_TRACE("[Process MON] %s relaunch", cmdline);
			new_pid = ss_launch_evenif_exist(cmdline, "");
			free(cmdline);
			if (new_pid > 0) {
				/* TODO - set oom */
				char buf[PATH_MAX];
				char filepath[PATH_MAX];
				size_t cnt;

				if (access(PMON_PERMANENT_DIR, R_OK) < 0) {
					PRT_TRACE("no predefined matrix dir = %s, so created", PMON_PERMANENT_DIR);
					mkdir(PMON_PERMANENT_DIR, 0777);
				}

				snprintf(filepath, sizeof(filepath), "%s/%d", PMON_PERMANENT_DIR, pid);
				fd = open(filepath, O_RDONLY);
				if (fd == -1) {
					PRT_TRACE("Failed to open");
					return -1;
				}

				cnt = read(fd, buf, PATH_MAX);
				close(fd);

				if (cnt <= 0) {
					PRT_TRACE("Failed to read");
					return -1;
				}

				snprintf(filepath, sizeof(filepath), "%s/%d", PMON_PERMANENT_DIR, new_pid);

				fd = open(filepath, O_CREAT | O_WRONLY, 0644);
				if (fd == -1) {
					PRT_TRACE("Failed to open");
					return -1;
				}

				if (write(fd, buf, cnt) == -1) {
					PRT_TRACE("Failed to write");
					close(fd);
					return -1;
				}
				close(fd);

				if (0 > plugin_intf->OEM_sys_set_process_monitor_mp_pnp(new_pid)) {
					PRT_TRACE_ERR("Write new pid failed");
				}
				PRT_TRACE("[Process MON] %d ", new_pid);

				FILE *fp;

				PRT_TRACE
				    ("[Process MON] OOMADJ_SET : pid %d, new_oomadj %d",
				     new_pid, (-17));
				snprintf(buf, sizeof(buf), "/proc/%d/oom_adj",
					 new_pid);
				fp = fopen(buf, "w");
				if (fp == NULL)
					return -1;
				fprintf(fp, "%d", (-17));
				fclose(fp);

				snprintf(old_file, sizeof(old_file), "%s/%d",
					 PMON_PERMANENT_DIR, pid);
				unlink(old_file);
			} else { 
				PRT_TRACE_ERR("[Process MON] failed relaunching");
			}
		}
	}
	return 0;
}