mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
signal: handle redisplaying the prompt correctly
This commit is contained in:
parent
3a309062d8
commit
10e8738336
3 changed files with 28 additions and 13 deletions
|
|
@ -6,10 +6,13 @@
|
|||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/20 10:26:05 by jguelen #+# #+# */
|
||||
/* Updated: 2025/04/04 16:56:06 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/04 16:58:58 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
// stdio must be included before readline
|
||||
#include <stdio.h>
|
||||
#include "readline/readline.h"
|
||||
#include "sig.h"
|
||||
#include "signal.h"
|
||||
|
||||
|
|
@ -22,24 +25,31 @@
|
|||
int g_signum = 0;
|
||||
|
||||
/*
|
||||
** Stores the signal number corresponding to the caught signal into g_signum
|
||||
** for later processing.
|
||||
** redisplay prompt
|
||||
*/
|
||||
static void sig_interactive(int signum)
|
||||
{
|
||||
g_signum = signum;
|
||||
(void)signum;
|
||||
rl_replace_line("", 0);
|
||||
ft_printf("\n");
|
||||
rl_on_new_line();
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
void readline_reset(void)
|
||||
{
|
||||
rl_replace_line("", 0);
|
||||
ft_printf("\n");
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
/*
|
||||
** Ignores the signal if it was sent by a kill command.
|
||||
** Otherwise stores the value of the caught signal in g_signum for later
|
||||
** processing.
|
||||
** Stores the value of the caught signal in g_signum for later processing.
|
||||
*/
|
||||
static void ignoreif_sent_by_kill(int signum, siginfo_t *siginfo, void *context)
|
||||
static void sig_cmd(int signum, siginfo_t *siginfo, void *context)
|
||||
{
|
||||
(void)context;
|
||||
if (siginfo->si_code == SI_USER)
|
||||
return ;
|
||||
(void)siginfo;
|
||||
g_signum = signum;
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +87,9 @@ int set_exec_mode_sig_handling(void)
|
|||
ft_bzero(&sig_act, sizeof(struct sigaction));
|
||||
if (sigemptyset(&sig_act.sa_mask) == -1)
|
||||
return (-1);
|
||||
sig_act.sa_sigaction = &ignoreif_sent_by_kill;
|
||||
sig_act.sa_sigaction = &sig_cmd;
|
||||
sig_act.sa_flags |= SA_SIGINFO;
|
||||
sig_act.sa_flags |= SA_RESTART;
|
||||
if (sigaction(SIGINT, &sig_act, NULL) == -1)
|
||||
return (-1);
|
||||
if (sigaction(SIGQUIT, &sig_act, NULL) == -1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue