ft_cleanup called at exit, reset termios to ISIG,ICANON,ECHO

This commit is contained in:
Jack Halford 2016-12-01 14:47:28 +01:00
parent 007b4c6a3f
commit 1f36fc1501
7 changed files with 41 additions and 20 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2016/12/01 12:13:46 by jhalford ### ########.fr */
/* Updated: 2016/12/01 14:46:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,8 +48,6 @@ struct s_data
t_list *qstack;
int fdin;
int fdout;
int save_in;
int save_out;
};
extern t_stof g_builtins[];
@ -57,6 +55,7 @@ extern pid_t g_pid;
void sig_handler(int signo);
int data_init(t_data *data);
void ft_cleanup(void);
int ft_builtin(char **av, t_data *data);
int builtin_echo(char **av, t_data *data);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */
/* Updated: 2016/11/28 14:30:07 by jhalford ### ########.fr */
/* Updated: 2016/12/01 14:35:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:18 by jhalford #+# #+# */
/* Updated: 2016/12/01 13:47:33 by jhalford ### ########.fr */
/* Updated: 2016/12/01 14:46:48 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,7 +57,7 @@ int ft_cmd_exec(char *execpath, char **argv, t_data *data)
g_pid = pid;
if (data->fdout == STDOUT)
{
ft_printf("[waiting for PID = %i]\n", pid);
ft_dprintf(2, "[waiting for PID = %i]\n", pid);
waitpid(pid, &status, 0);
builtin_setenv((char*[3]){"?", ft_itoa(status)}, data);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */
/* Updated: 2016/12/01 14:26:56 by jhalford ### ########.fr */
/* Updated: 2016/12/01 14:46:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,7 @@ int ft_set_termios(t_data *data, int input_mode)
if (input_mode)
term.c_lflag &= ~(ICANON) & ~(ISIG) & ~(ECHO);
else
term.c_lflag |= ICANON | ECHO;
term.c_lflag |= ICANON | ISIG | ECHO;
term.c_cc[VMIN] = 1;
term.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSADRAIN, &term) == -1)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2016/12/01 12:12:59 by jhalford ### ########.fr */
/* Updated: 2016/12/01 14:46:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,12 +16,11 @@ extern char **environ;
int data_init(t_data *data)
{
atexit(&ft_cleanup);
data->env = ft_sstrdup(environ);
data->history = NULL;
data->fdin = STDIN;
data->fdout = STDOUT;
data->save_in = dup(STDIN);
data->save_out = dup(STDOUT);
if (!(data->history = ft_dlstnew(NULL, 0)))
return (-1);
return (0);

View file

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cleanup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 14:42:42 by jhalford #+# #+# */
/* Updated: 2016/12/01 14:46:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_cleanup(void)
{
struct termios term;
if (tcgetattr(0, &term) == -1)
return ;
term.c_lflag |= ICANON | ISIG | ECHO;
if (tcsetattr(0, TCSANOW, &term) == -1)
return ;
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:43:22 by jhalford #+# #+# */
/* Updated: 2016/12/01 14:27:00 by jhalford ### ########.fr */
/* Updated: 2016/12/01 14:46:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,12 +16,11 @@ pid_t g_pid;
void sig_handler(int signo)
{
(void)signo;
/* if (signo == SIGINT) */
/* { */
/* ft_printf("got SIGINT, g_pid = %i\n", g_pid); */
/* if (g_pid) */
/* kill(g_pid, SIGINT); */
/* if (kill(g_pid, 0) == 0) */
/* ft_putendl(""); */
/* } */
if (signo == SIGINT)
{
if (g_pid)
kill(g_pid, SIGINT);
if (kill(g_pid, 0) == 0)
ft_putendl("");
}
}