Skip to content

Commit

Permalink
Merge pull request #58 from mingxoxo/bug/#46/sigint-handling
Browse files Browse the repository at this point in the history
Bug : #46/부모 프로세스 시그널 핸들링
  • Loading branch information
mingxoxo authored Jan 15, 2023
2 parents 7e9faea + a7014d1 commit 5580bbe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion execute/child.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
/* By: wonyang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/11 23:33:05 by wonyang #+# #+# */
/* Updated: 2023/01/14 22:34:33 by wonyang ### ########seoul.kr */
/* Updated: 2023/01/15 11:46:51 by wonyang ### ########seoul.kr */
/* */
/* ************************************************************************** */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include "minishell.h"
#include "ds_envp.h"
#include "execute.h"
Expand Down Expand Up @@ -123,6 +124,7 @@ t_error create_childs(t_tnode **cmd_list, pid_t *pid_list)

before_fd = STDIN_FILENO;
i = 0;
signal(SIGINT, SIG_IGN);
while (cmd_list[i + 1])
{
pid_list[i] = fork_child(cmd_list[i], &before_fd);
Expand Down
3 changes: 2 additions & 1 deletion includes/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: wonyang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/10 19:35:48 by wonyang #+# #+# */
/* Updated: 2023/01/13 17:17:47 by wonyang ### ########seoul.kr */
/* Updated: 2023/01/15 11:45:51 by wonyang ### ########seoul.kr */
/* */
/* ************************************************************************** */

Expand All @@ -25,6 +25,7 @@ typedef struct s_global
int status;
} t_global;

void set_signal_handling(void);
void set_minishell_setting(void);

#endif
3 changes: 2 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: wonyang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/08 22:30:32 by wonyang #+# #+# */
/* Updated: 2023/01/14 22:47:58 by wonyang ### ########seoul.kr */
/* Updated: 2023/01/15 11:46:01 by wonyang ### ########seoul.kr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -92,6 +92,7 @@ int main(int argc, char **argv, char **env)
else
execute_cmds(node);
tcsetattr(STDIN_FILENO, TCSANOW, &(g_var.new_term));
set_signal_handling();
ft_lstclear(&lst, del_t_paren);
clear_node(node, del_t_token);
free(str);
Expand Down
5 changes: 3 additions & 2 deletions terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: wonyang <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/10 15:47:32 by wonyang #+# #+# */
/* Updated: 2023/01/13 17:17:56 by wonyang ### ########seoul.kr */
/* Updated: 2023/01/15 11:49:27 by wonyang ### ########seoul.kr */
/* */
/* ************************************************************************** */

Expand All @@ -32,13 +32,14 @@ static void get_terminal_setting(void)
static void sigint_handler_prompt(int signo)
{
(void)signo;
g_var.status = 1;
ft_putchar_fd('\n', STDOUT_FILENO);
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}

static void set_signal_handling(void)
void set_signal_handling(void)
{
signal(SIGINT, sigint_handler_prompt);
}
Expand Down

0 comments on commit 5580bbe

Please sign in to comment.