en cours de gestion des signaux dans heredoc
This commit is contained in:
24
README.md
24
README.md
@@ -113,7 +113,29 @@ test
|
|||||||
hello
|
hello
|
||||||
test
|
test
|
||||||
```
|
```
|
||||||
|
5. chaque nouvelle ligne doit afficher :
|
||||||
|
|
||||||
|
- non pas les characters "> "
|
||||||
|
|
||||||
|
- mais le contenu de la variable PS2 (qui par defaut est la chaine de characater "> ")
|
||||||
|
|
||||||
|
- (au passage, les characaters "$ " affichés a la fin de chaque prompt devraient etre ceux de la variable PS1)
|
||||||
|
|
||||||
|
- [infos ici](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_03)
|
||||||
|
|
||||||
|
|
||||||
|
## schema d'execution :
|
||||||
|
```text
|
||||||
|
_________________________________________________
|
||||||
|
|LOOP: shell_loop() |
|
||||||
|
| signal(SIGINT, handler) |
|
||||||
|
| mode interactif -> readline return line_input |
|
||||||
|
| signal(SIGINT, ignore) |
|
||||||
|
| lexing |
|
||||||
|
| parsing |
|
||||||
|
| execution |
|
||||||
|
|_________________________________________________|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## understanding some things :
|
## understanding some things :
|
||||||
@@ -125,6 +147,8 @@ test
|
|||||||
- [signal in a child process](https://stackoverflow.com/questions/55190460/using-signals-in-a-child-process)
|
- [signal in a child process](https://stackoverflow.com/questions/55190460/using-signals-in-a-child-process)
|
||||||
- [send signal to process and childs](https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script)
|
- [send signal to process and childs](https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script)
|
||||||
- commande utile pour tester les process parents et enfants : while true ; do ps -o pid,pgid,cmd -C bash ; sleep 0.1 ; echo "\n" ; done
|
- commande utile pour tester les process parents et enfants : while true ; do ps -o pid,pgid,cmd -C bash ; sleep 0.1 ; echo "\n" ; done
|
||||||
|
- [exit code status](https://tldp.org/LDP/abs/html/exitcodes.html)
|
||||||
|
|
||||||
|
|
||||||
```text
|
```text
|
||||||
| BASH | MINISHELL |
|
| BASH | MINISHELL |
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
/* Created: 2021/10/08 02:59:58 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/16 22:58:35 by lperrey ### ########.fr */
|
/* Updated: 2021/11/18 13:18:08 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -81,5 +81,6 @@ char *ft_strdup_quotes(const char *s);
|
|||||||
|
|
||||||
// signals.c
|
// signals.c
|
||||||
void sigint_handler_interactive(int signum);
|
void sigint_handler_interactive(int signum);
|
||||||
|
void sigint_handler_heredoc(int signum);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
|
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/17 01:08:38 by lperrey ### ########.fr */
|
/* Updated: 2021/11/18 10:28:00 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ int cmd_exec_in_subshell(t_cmd *cmd, t_all *c)
|
|||||||
return (ft_reti_perror(EXIT_FAILURE, "dup2()"));
|
return (ft_reti_perror(EXIT_FAILURE, "dup2()"));
|
||||||
close_pipeline_fd(c->cmd_arr);
|
close_pipeline_fd(c->cmd_arr);
|
||||||
if (cmd->builtin_func)
|
if (cmd->builtin_func)
|
||||||
free_exit(c, cmd->builtin_func(ft_2d_arrlen(cmd->argv), cmd->argv,c));
|
free_exit(c, cmd->builtin_func(ft_2d_arrlen(cmd->argv), cmd->argv, c));
|
||||||
else if (execve("/bin/echo", cmd->argv, c->envp) == -1) // WIP, TEST
|
else if (execve("/bin/echo", cmd->argv, c->envp) == -1) // WIP, TEST
|
||||||
return (ft_reti_perror_io(EXIT_FAILURE, "execve() ", cmd->argv[0]));
|
return (ft_reti_perror_io(EXIT_FAILURE, "execve() ", cmd->argv[0]));
|
||||||
//else if (execve(cmd->path, cmd->argv, c->envp) == -1)
|
//else if (execve(cmd->path, cmd->argv, c->envp) == -1)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
/* Created: 2021/11/11 18:46:43 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/16 22:29:01 by lperrey ### ########.fr */
|
/* Updated: 2021/11/18 13:17:19 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -56,7 +56,10 @@ static int here_doc_write(char *delimiter, int doc_fd)
|
|||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
size_t line_count;
|
size_t line_count;
|
||||||
|
struct sigaction signal_action;
|
||||||
|
|
||||||
|
signal_action.sa_handler = sigint_handler_heredoc;
|
||||||
|
sigaction(SIGINT, &signal_action, NULL);
|
||||||
line_count = 0;
|
line_count = 0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,15 +6,12 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/17 01:30:27 by lperrey ### ########.fr */
|
/* Updated: 2021/11/17 15:29:35 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void close_fd(t_cmd *cmd);
|
|
||||||
void execute_cmd(char **envp, t_cmd **cmd_arr, t_all *c);
|
|
||||||
|
|
||||||
void shell_loop(t_all *c)
|
void shell_loop(t_all *c)
|
||||||
{
|
{
|
||||||
char *line_input;
|
char *line_input;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2021/10/23 18:56:53 by lperrey #+# #+# */
|
/* Created: 2021/10/23 18:56:53 by lperrey #+# #+# */
|
||||||
/* Updated: 2021/11/16 22:58:29 by lperrey ### ########.fr */
|
/* Updated: 2021/11/18 13:18:53 by hulamy ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -21,6 +21,15 @@ void sigint_handler_interactive(int signum)
|
|||||||
rl_redisplay();
|
rl_redisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sigint_handler_heredoc(int signum)
|
||||||
|
{
|
||||||
|
(void)signum;
|
||||||
|
write(1, "T", 1);
|
||||||
|
rl_on_new_line();
|
||||||
|
rl_replace_line("", 1);
|
||||||
|
rl_redisplay();
|
||||||
|
}
|
||||||
|
|
||||||
int set_signals_handling(struct sigaction *signal_behaviour)
|
int set_signals_handling(struct sigaction *signal_behaviour)
|
||||||
{
|
{
|
||||||
signal_behaviour->sa_handler = sigint_handler_interactive;
|
signal_behaviour->sa_handler = sigint_handler_interactive;
|
||||||
|
|||||||
Reference in New Issue
Block a user