fix: signals (^C in $ cat
)
This commit is contained in:
parent
368b46e82c
commit
3f3028880b
5 changed files with 28 additions and 26 deletions
1
dev/TODO
1
dev/TODO
|
@ -10,7 +10,6 @@
|
||||||
x exit (with no options)
|
x exit (with no options)
|
||||||
- fix
|
- fix
|
||||||
- the builtins should get all arguments and check if they're good
|
- the builtins should get all arguments and check if they're good
|
||||||
- `$ cat` then ^C
|
|
||||||
|
|
||||||
(unnecessary part)
|
(unnecessary part)
|
||||||
- working history (rl_* functions?)
|
- working history (rl_* functions?)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
/* Created: 2024/04/23 14:15:12 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/06/13 13:08:35 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/28 12:55:17 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -15,6 +15,13 @@
|
||||||
|
|
||||||
# include "include.h"
|
# include "include.h"
|
||||||
|
|
||||||
void handle_signals(void);
|
typedef enum e_sigmode {
|
||||||
|
SIGMODE_PROMPT, SIGMODE_IGNORE, SIGMODE_DEFAULT
|
||||||
|
} t_sigmode;
|
||||||
|
|
||||||
|
// If sigmode is SIGMODE_PROMPT, ^C redisplays the prompt and ^\ is ignored.
|
||||||
|
// If sigmode is SIGMODE_IGNORE, ^C and ^\ are ignored.
|
||||||
|
// If sigmode is SIGMODE_DEFAULT, ^C and ^\ are reset by default.
|
||||||
|
void handle_signals(t_sigmode sigmode);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/24 13:48:00 by jschaft #+# #+# */
|
/* Created: 2024/04/24 13:48:00 by jschaft #+# #+# */
|
||||||
/* Updated: 2024/06/28 12:03:49 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/28 12:54:07 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ static int execute_call(
|
||||||
return (minishell_error("errno"), errno);
|
return (minishell_error("errno"), errno);
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
|
handle_signals(SIGMODE_DEFAULT);
|
||||||
if (dup2(inout[0], 0) < 0 || dup2(inout[1], 1) < 0)
|
if (dup2(inout[0], 0) < 0 || dup2(inout[1], 1) < 0)
|
||||||
return (minishell_error("errno"), errno);
|
return (minishell_error("errno"), errno);
|
||||||
close_all_pipes(global);
|
close_all_pipes(global);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
/* By: jschaft <cecile.schaft@orange.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */
|
/* Created: 2024/04/23 14:33:45 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/06/28 11:51:01 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/28 12:53:23 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -62,7 +62,9 @@ static void prompt_command(t_env *env)
|
||||||
const char *command_str;
|
const char *command_str;
|
||||||
|
|
||||||
env->mc_command = mem_subclass(fatal_error, env->mc_global);
|
env->mc_command = mem_subclass(fatal_error, env->mc_global);
|
||||||
|
handle_signals(SIGMODE_PROMPT);
|
||||||
command_str = ask_command(env);
|
command_str = ask_command(env);
|
||||||
|
handle_signals(SIGMODE_IGNORE);
|
||||||
if (!command_str)
|
if (!command_str)
|
||||||
env->exit = true;
|
env->exit = true;
|
||||||
else
|
else
|
||||||
|
@ -93,7 +95,6 @@ int main(const int argc, const char *argv[], char *const envp[])
|
||||||
env.envp = envp;
|
env.envp = envp;
|
||||||
variables = variables_from_envp(env, envp);
|
variables = variables_from_envp(env, envp);
|
||||||
env.variables = &variables;
|
env.variables = &variables;
|
||||||
handle_signals();
|
|
||||||
start(&env);
|
start(&env);
|
||||||
while (!env.exit)
|
while (!env.exit)
|
||||||
prompt_command(&env);
|
prompt_command(&env);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/12 14:04:30 by mcolonna #+# #+# */
|
/* Created: 2024/06/12 14:04:30 by mcolonna #+# #+# */
|
||||||
/* Updated: 2024/06/18 15:40:09 by mcolonna ### ########.fr */
|
/* Updated: 2024/06/28 12:52:32 by mcolonna ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -21,33 +21,27 @@ static void handle_sigint(int _)
|
||||||
rl_redisplay();
|
rl_redisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_signals(void)
|
void handle_signals(t_sigmode sigmode)
|
||||||
{
|
|
||||||
struct sigaction sa;
|
|
||||||
|
|
||||||
sa.sa_flags = SA_RESTART;
|
|
||||||
sa.sa_handler = handle_sigint;
|
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
if (sigaction(SIGINT, &sa, NULL) == -1)
|
|
||||||
fatal_error(NULL);
|
|
||||||
sa.sa_flags = 0;
|
|
||||||
sa.sa_handler = SIG_IGN;
|
|
||||||
sigemptyset(&sa.sa_mask);
|
|
||||||
if (sigaction(SIGQUIT, &sa, NULL) == -1)
|
|
||||||
fatal_error(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_signals_default(void)
|
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = 0;
|
||||||
sa.sa_handler = SIG_DFL;
|
if (sigmode == SIGMODE_PROMPT)
|
||||||
|
sa.sa_flags = SA_RESTART;
|
||||||
|
if (sigmode == SIGMODE_PROMPT)
|
||||||
|
sa.sa_handler = handle_sigint;
|
||||||
|
else if (sigmode == SIGMODE_IGNORE)
|
||||||
|
sa.sa_handler = SIG_IGN;
|
||||||
|
else
|
||||||
|
sa.sa_handler = SIG_DFL;
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
if (sigaction(SIGINT, &sa, NULL) == -1)
|
if (sigaction(SIGINT, &sa, NULL) == -1)
|
||||||
fatal_error(NULL);
|
fatal_error(NULL);
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = 0;
|
||||||
sa.sa_handler = SIG_DFL;
|
if (sigmode == SIGMODE_DEFAULT)
|
||||||
|
sa.sa_handler = SIG_DFL;
|
||||||
|
else
|
||||||
|
sa.sa_handler = SIG_IGN;
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
if (sigaction(SIGQUIT, &sa, NULL) == -1)
|
if (sigaction(SIGQUIT, &sa, NULL) == -1)
|
||||||
fatal_error(NULL);
|
fatal_error(NULL);
|
||||||
|
|
Loading…
Add table
Reference in a new issue