signal handling works like bash for sigint: doesnt interrupt cat

This commit is contained in:
Jack Halford 2016-12-01 14:27:52 +01:00
parent c6273f22d6
commit 007b4c6a3f
6 changed files with 30 additions and 13 deletions

View file

@ -1,3 +1,4 @@
#!/bin/sh
while [ 1 ]; do
sleep 1
done

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:18 by jhalford #+# #+# */
/* Updated: 2016/11/29 20:22:38 by jhalford ### ########.fr */
/* Updated: 2016/12/01 13:47:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,9 +57,11 @@ 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);
waitpid(pid, &status, 0);
builtin_setenv((char*[3]){"?", ft_itoa(status)}, data);
}
g_pid = 0;
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:12 by jhalford #+# #+# */
/* Updated: 2016/12/01 12:29:32 by jhalford ### ########.fr */
/* Updated: 2016/12/01 12:42:35 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */
/* Updated: 2016/12/01 12:29:41 by jhalford ### ########.fr */
/* Updated: 2016/12/01 14:26:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,11 +24,10 @@ int ft_set_termios(t_data *data, int input_mode)
return (-1);
if (tcgetattr(0, &term) == -1)
return (-1);
term.c_lflag &= ~(ICANON); // Met le terminal en mode canonique.
if (input_mode)
term.c_lflag &= ~(ISIG) & ~(ECHO);
term.c_lflag &= ~(ICANON) & ~(ISIG) & ~(ECHO);
else
term.c_lflag |= ISIG | ECHO;
term.c_lflag |= ICANON | 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/27 21:13:34 by jhalford #+# #+# */
/* Updated: 2016/12/01 12:28:47 by jhalford ### ########.fr */
/* Updated: 2016/12/01 13:47:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -1,12 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sig_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/01 12:43:22 by jhalford #+# #+# */
/* Updated: 2016/12/01 14:27:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
pid_t g_pid;
void sig_handler(int signo)
{
if (signo == SIGINT)
{
exit(1);
if (g_pid)
kill(g_pid, SIGINT);
}
(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(""); */
/* } */
}