Code Monkey home page Code Monkey logo

42_minishell's Introduction

pm_shell

42_minishell's People

Contributors

yymin1022 avatar falconlee236 avatar

Watchers

 avatar

42_minishell's Issues

[FIX] unset 함수도 환경변수 없으면 터짐

t_env	*make_envlist(char **env)
{
	int		i;
	t_env	*env_list;

	i = -1;
	env_list = NULL;
	while (env[++i])
	{
		if (ft_strncmp(env[i], "OLDPWD", 6) == 0)
			continue ;
		// env_pushback(&env_list, env_createnew(env[i])); << 환경변수 날린거임
	}
	return (env_list);
}
pmshell> :$ unset a
[1]    36796 segmentation fault  ./minishell

이것도 터져요 by 장민석

pmshell> :$ env
pmshell> :$ export a=b
pmshell> :$ env
pmshell> :$ 

이건 왜 안들어가요 by 고지흔

pmshell> :$ export
[1]    38544 segmentation fault  ./minishell

ㅋㅋ 이것도 터지는데? by 고지흔

[FIX] g_status_code 전역 변수를 지역 변수로 옮김

minishell에서 전역 변수는 signal handle을 위해서 사용해야 하기 때문에 exit code를 위해서 사용되는 g_status_code는 전역 변수로 사용할 수 없습니다. 따라서 이 변수를 지역 변수로 옮깁니다.

전역 변수는 signal handler 함수에서 g_signo 를 signo로 덮어씌워서 사용하는게 좋을것 같습니다.

[FIX] cd 관련 오류 다수 발견

pmshell> :$ mkdir testf
mkdir: testf: File exists
pmshell> :$ cd testf
/Users/sangyleepmshell> :$ rm -rf ../testf
pmshell> :$ cd
/Users/sangyleeAddressSanitizer:DEADLYSIGNAL
int	cmd_cd(char **argv, t_env *env_list)
{
	char	*home_path;
	char	*new_path;
	char	*prev_path;

	home_path = get_home_path(env_list);
	fprintf(stderr, "%s", home_path);
	if (argv[1] == NULL || argv[1][0] == '~')
	{
		if (argv[1] == NULL)
			new_path = ft_strdup(home_path);
		else
			new_path = ft_strjoin(home_path, &argv[1][1]);
	}
	else if (ft_strcmp(argv[1], "-") == 0)
		new_path = get_oldpwd(env_list);
	else
		new_path = ft_strdup(argv[1]);
	if (new_path == NULL)
		return (0);
	prev_path = getcwd(NULL, 0); 
	if (chdir(new_path) != 0
		|| !update_pwd(env_list) <<<<<<<<<< 여기 문제임 with 고지흔
		|| !update_oldpwd(ft_strjoin("OLDPWD=", prev_path), env_list))
	{
		four_times_free(prev_path, new_path, home_path, 0);
		ft_putstr_fd("pmshell: ", 2);
		perror("cd");
		return (0);
	}
	four_times_free(prev_path, new_path, home_path, 0);
	return (1);
}

폴더 만들고 폴더 안에 들어가서 폴더를 삭제하고 cd하니까 세그폴트 나요

2

t_env	*make_envlist(char **env)
{
	int		i;
	t_env	*env_list;

	i = -1;
	env_list = NULL;
	while (env[++i])
	{
		if (ft_strncmp(env[i], "OLDPWD", 6) == 0)
			continue ;
		// env_pushback(&env_list, env_createnew(env[i]));
	}
	return (env_list);
}

envlist를 안만들면 (모두 unset 한거임 by 고지흔)

pmshell> :$ pwd
/Users/sangylee/Desktop/pm_shell
pmshell> :$ ls
pmshell: ls: No such file or directory
pmshell> :$ ls
pmshell: ls: No such file or directory
pmshell> :$ PWD
pmshell: PWD: No such file or directory
pmshell> :$ cd
[1]    35755 segmentation fault  ./minishell

명령어가 터져요

[DEV} HERE_DOC 처리 기능 구현

cmd_list에 heredoc이 들어오면 임시 파일을 생성해서 사용자가 입력한 값이 그곳에 들어갈 수 있는 기능을 구현합니다.

[FIX] heredoc이 들어올 때 redirection io가 읽지 못하는 문제

static int	redirect_input(t_redirect *redir, t_info *info)
{
	int	fd;

	fd = open(redir->file, O_RDONLY);
	if (fd == -1)
		exit_err(redir->file, 1, info);
	if (dup2(fd, STDIN_FILENO) == -1)
		perror("dup2(stdin)");
	close(fd);
	return (1);
}

이 함수에서 redir->file이 redirection인 경우에는 deilmeter가 들어오기 때문에 현재 코드에서는 에러가 납니다
redirection인 경우에는 0.tmp, 1.tmp 등등으로 읽어야 합니다.

[DEV] env 구조체 구조 변경

env 구조체의 구조를 key-value가 아닌 단순 문자열로 변경합니다

거기에 해당 구조체에 맞는 구조를 변경합니다

[DEV] exit build command의 여러 경우의 수 고려 필요

현재 exit는 빌트인이 들어오면 exit(0)하고 마는데,
exit 1234 이렇게 들어오면 exit(1234)로 status code를 반환해야 합니다.
추가로 문자열은 어떻게 처리할지 알아서 하시면 됩니다.

결국 exit의 옵션을 추가해야 합니다.

[DEV] waitpid를 할때 예외처리

void	cmd_wait_child(pid_t pid_parent, int cmd_cnt)
{
	int		i;
	int		status;
	int		is_print_err;
	pid_t	pid_child;

	i = 0;
	is_print_err = 0;
	while (i < cmd_cnt)
	{
		pid_child = waitpid(-1, &status, 0);
		if (WIFSIGNALED(status) && ++is_print_err)
		{
			if (WTERMSIG(status) == SIGINT && is_print_err)
				ft_putstr_fd("^C\n", STDERR_FILENO);
			else if (WTERMSIG(status) == SIGQUIT && is_print_err)
				ft_putstr_fd("^\\Quit: 3\n", STDERR_FILENO);
			if (pid_child == pid_parent)
				g_status_code = 128 + WTERMSIG(status);
		}
		else if (pid_child == pid_parent)
			g_status_code = WEXITSTATUS(status);
		i++;
	}
}

이 함수에서 pid_child로 받는데, 파이프의 경우 맨 마지막에 실행이 종료되는 코드의 status code가 아닌, 파이프의 마지막에 위치한 pid의 status code를 받아와야 하기 때문에 맨 마지막 파이프의 pid를 가져야 합니다. 그것을 저장하는 로직을 구현해야 합니다.

[FIX] cd $HOME이 사라질때 에러 미시지 추가하기

cd ~의 원리가
$HOME을 찾고 그것의 값으로 이동하는데, unset으로 $HOME을 지우면 원래는 에러 메시지가 나와야 합니다.
그런데 현재는 그냥 아무것도 안나와서 그것을 수정해야합니다.

에러 메시지 고려 잘해주세요

[FIX] exit code 맞추세요

exit code 귀찮다고 안맞추지 말고 고치세요

bash-3.2$ |
bash: syntax error near unexpected token `|'
bash-3.2$ $?
bash: 258: command not found

내것도 해줘

부탁임

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.