예제 #1
0
int sys_getpath(int f, char *b, int len)
{
	if(!b) return -EINVAL;
	struct file *file = get_file_pointer((task_t *) current_task, f);
	if(!file)
		return -EBADF;
	int ret = get_path_string(file->inode, b, len);
	fput((task_t *)current_task, f, 0);
	return ret;
}
예제 #2
0
int main(int argc, char *argv[], char *envp[])
{
	int write_bytes;
	char exec_file_name[STRING_MAX];
	char path_str[STRING_MAX];
	int flag_exit;
	int exec_status;
	int index;
	int fd;
	pid_t pid;
	signal(SIGINT, SIG_IGN);
	signal(SIGINT, handle_signal);
	read_bytes = STRING_MAX;
	fflush(stdout);
	get_path_string(envp, path_str);
	insert_path_str_to_search(path_str);
	do {
		memset(exec_file_name, 0, read_bytes);
		write_bytes = write(1, MESS_BASH_WAIT_COMMAND,
				sizeof(MESS_BASH_WAIT_COMMAND));
		read_bytes = 1;
		read_bytes = read(0, exec_file_name, STRING_MAX);
		if (read_bytes != 1) {
			exec_file_name[read_bytes-1] = 0;
			flag_exit = strcmp(exec_file_name, COMMAND_BASH_CLOSE);
			if (flag_exit)
				switch (pid = fork()) {
				case -1:
					perror("fork");
					exit(1);
				case 0:
					fill_argv(exec_file_name);
					if (argv_child[0][0] != '/') {
						fd = open(argv_child[0], O_RDONLY);
						if (fd > 0) {
							close(fd);
						} else if (attach_path() != 0) {
							printf("0 %s: %s\n",
								argv_child[0],
								MESS_BASH_COMMAND_MISS);
							exit(1);
						}
					} else {
						fd = open(argv_child[0], O_RDONLY);
						if (fd > 0) {
							close(fd);
						} else {
							printf("1 %s: %s\n",
								argv_child[0],
								MESS_BASH_COMMAND_MISS);
							exit(1);
						}
					}
					exec_status = execve(argv_child[0],
						argv_child, envp);
					if (exec_status < 0) {
						printf("2 %s: %s\n",
							argv_child[0],
							MESS_BASH_COMMAND_MISS);
						exit(1);
					}
					exit(0);
				default:
					wait(NULL);
				}
		}
	} while (flag_exit);
	for (index = 0; argv_child[index] != NULL; index++)
		free(argv_child[index]);
	for (index = 0; search_path[index] != NULL; index++)
		free(search_path[index]);
	write_bytes = write(1, MESS_BASH_NL, sizeof(MESS_BASH_NL));
	return 0;
}