shell _script() use gnl() instead of readline()
to prevent copy of input to terminal. + here_doc_write_script() for nontty STDIN
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/26 23:47:44 by lperrey #+# #+# */
|
||||
/* Updated: 2021/12/18 08:51:46 by lperrey ### ########.fr */
|
||||
/* Updated: 2021/12/18 15:15:30 by lperrey ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,6 +24,8 @@ void shell_script(t_all *c)
|
||||
{
|
||||
free(line_input);
|
||||
line_input = read_input_script(c);
|
||||
if (!line_input)
|
||||
break ;
|
||||
if (line_input && *line_input)
|
||||
{
|
||||
c->token_list = lexing(line_input);
|
||||
@@ -39,7 +41,6 @@ void shell_script(t_all *c)
|
||||
exit_signal(c);
|
||||
}
|
||||
}
|
||||
free(line_input);
|
||||
exit_free(c, get_last_exit_status());
|
||||
}
|
||||
|
||||
@@ -47,16 +48,23 @@ static char *read_input_script(t_all *c)
|
||||
{
|
||||
char *line_input;
|
||||
struct sigaction signal_behaviour;
|
||||
int ret;
|
||||
|
||||
ft_bzero(&signal_behaviour, sizeof signal_behaviour);
|
||||
signal_behaviour.sa_handler = sigint_handler_interactive;
|
||||
sigaction(SIGINT, &signal_behaviour, NULL);
|
||||
rl_event_hook = NULL;
|
||||
line_input = readline(NULL);
|
||||
signal_behaviour.sa_handler = SIG_IGN;
|
||||
sigaction(SIGINT, &signal_behaviour, NULL);
|
||||
if (!line_input)
|
||||
line_input = NULL;
|
||||
ret = gnl(STDIN_FILENO, &line_input, 0);
|
||||
if (ret == -1)
|
||||
{
|
||||
free(line_input);
|
||||
return (NULL);
|
||||
}
|
||||
if (!line_input[0] && ret == 0)
|
||||
{
|
||||
free(line_input);
|
||||
exit_free(c, get_last_exit_status());
|
||||
}
|
||||
return (line_input);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user