Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion includes/msh.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: haekang <haekang@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/26 12:29:19 by jho #+# #+# */
/* Updated: 2023/11/29 15:51:54 by jho ### ########.fr */
/* Updated: 2023/11/30 17:13:44 by haekang ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -36,4 +36,12 @@

int g_exit_status;



void do_sigint(int signum);
void set_terminal_print_off(void);
void set_terminal_print_on(void);
void set_default_signal(void);
void set_signal(void);
void handle_signal_2(int signo);
#endif
4 changes: 2 additions & 2 deletions sources/msh_builtin/msh_builtin_cd_chdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: haekang <haekang@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/29 16:14:44 by haekang #+# #+# */
/* Updated: 2023/11/29 16:15:50 by haekang ### ########.fr */
/* Updated: 2023/11/29 20:53:30 by haekang ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -20,7 +20,7 @@ int msh_builtin_cd_chdir(char *path, char *old_pwd, int pipe)
printf("minishell: cd: %s: No such file or directory\n", path);
g_exit_status = 1;
if (pipe == 1)
exit (g_exit_status);
exit(g_exit_status);
return (0);
}
return (1);
Expand Down
4 changes: 2 additions & 2 deletions sources/msh_builtin/msh_builtin_env.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: haekang <haekang@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/10 20:07:51 by haekang #+# #+# */
/* Updated: 2023/11/29 16:19:04 by haekang ### ########.fr */
/* Updated: 2023/11/29 20:53:51 by haekang ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -31,6 +31,6 @@ int msh_builtin_env(int *fd, int pipe, char **cmd, t_env *env)
}
g_exit_status = 0;
if (pipe == 1)
exit (g_exit_status);
exit(g_exit_status);
return (0);
}
6 changes: 3 additions & 3 deletions sources/msh_executor/msh_execute_first.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* msh_execute_first.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jho <jho@student.42seoul.kr> +#+ +:+ +#+ */
/* By: haekang <haekang@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/23 14:24:03 by jho #+# #+# */
/* Updated: 2023/11/30 16:30:51 by jho ### ########.fr */
/* Updated: 2023/11/30 17:47:50 by haekang ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -60,7 +60,7 @@ int msh_execute_first(t_pipeline *pl, int *fd, t_env *env, int forked)
return (-1);
if (pid == 0)
{
if (fd[0] != 0 && close(fd[0]) == -1)
if (fd[0] != 0 && close(fd[0]) == -1)
return (-1);
msh_execute_first_child(pl, local_fd, env, forked);
}
Expand Down
4 changes: 3 additions & 1 deletion sources/msh_expander/msh_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: haekang <haekang@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/26 09:58:12 by jho #+# #+# */
/* Updated: 2023/11/14 14:39:42 by haekang ### ########.fr */
/* Updated: 2023/11/30 15:45:52 by haekang ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -39,6 +39,8 @@ char *msh_expand(char *s, t_env *env)
t_token *tokens;
char *expanded;

if (s == NULL)
return (NULL);
tokens = msh_vqoutes(s);
if (tokens == NULL)
return (NULL);
Expand Down
7 changes: 6 additions & 1 deletion sources/msh_main/msh_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: haekang <haekang@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/12 12:03:25 by jho #+# #+# */
/* Updated: 2023/11/30 16:15:28 by jho ### ########.fr */
/* Updated: 2023/11/30 17:49:03 by haekang ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -33,6 +33,11 @@ int main(int argc, char *argv[], char *envp[])
while (1)
{
input = readline("msh$> ");
if (input == NULL)
{
set_terminal_print_on();
exit (g_exit_status);//여기서 ctrl + d 처리
}
expanded = msh_expand(input, env);
pipelines = msh_lex(expanded);
if (pipelines == NULL)
Expand Down
83 changes: 83 additions & 0 deletions sources/msh_signal/msh_signal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <signal.h>

void handle_signal_2(int signo)
{
(void)signo;
g_exit_status = 1;
}

void handle_signal(int signo)
{
pid_t pid;
int status;

pid = waitpid(-1, &status, WNOHANG);
if (signo == SIGINT)
{
if (pid == -1)
{
printf("\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
g_exit_status = 1;
}
else//자식 프로세스가 존재함
{
printf("부모 시그널\n");
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
g_exit_status = 1;
}
}
// else if (signo == SIGQUIT)
// {
// if (pid == -1)
// ft_putstr_fd("\b\b \b\b", STDOUT);
// else
// ft_putstr_fd("Quit: 3\n", STDOUT);
// }
}

// void do_sigint(int signum)
// {
// (void)signum;
// printf("\n");
// rl_on_new_line();
// rl_replace_line("", 0);
// rl_redisplay();
// g_exit_status = 1;
// }

void set_terminal_print_off(void)
{
struct termios term;

tcgetattr(1, &term);
term.c_lflag &= ~(ECHOCTL);
tcsetattr(1, 0, &term);
}

void set_terminal_print_on(void)
{
struct termios term;

tcgetattr(1, &term);
term.c_lflag |= (ECHOCTL);
tcsetattr(1, 0, &term);
}

void set_default_signal(void)
{
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}


void set_signal(void)
{
set_terminal_print_off();
signal(SIGINT, handle_signal);
signal(SIGQUIT, SIG_IGN);
}