MiniDevil As beautiful as a shell
signals.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* signals.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2025/12/10 23:44:56 by baelgadi #+# #+# */
9 /* Updated: 2026/03/04 07:22:26 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <readline/readline.h>
14 #include "signals.h"
15 #include "libft.h"
16 
17 volatile sig_atomic_t g_signal = 0;
18 
27 {
28  g_signal = sig;
29  ft_putchar_fd('\n', STDOUT_FILENO);
30  rl_on_new_line();
31  rl_replace_line("", 0);
32  rl_redisplay();
33 }
34 
44 {
45  struct sigaction sa_int;
46  struct sigaction sa_quit;
47 
48  ft_memset(&sa_int, 0, sizeof(sa_int));
49  sa_int.sa_handler = &interactive_sigint_handler;
50  sigemptyset(&sa_int.sa_mask);
51  sa_int.sa_flags = SA_RESTART;
52  sigaction(SIGINT, &sa_int, NULL);
53  ft_memset(&sa_quit, 0, sizeof(sa_quit));
54  sa_quit.sa_handler = SIG_IGN;
55  sigemptyset(&sa_quit.sa_mask);
56  sa_quit.sa_flags = 0;
57  sigaction(SIGQUIT, &sa_quit, NULL);
58 }
59 
67 {
68  struct sigaction sa;
69 
70  sa.sa_handler = SIG_DFL;
71  sigemptyset(&sa.sa_mask);
72  sa.sa_flags = 0;
73  sigaction(SIGINT, &sa, NULL);
74  sigaction(SIGQUIT, &sa, NULL);
75 }
76 
84 {
85  struct sigaction sa;
86 
87  sa.sa_handler = SIG_IGN;
88  sigemptyset(&sa.sa_mask);
89  sa.sa_flags = 0;
90  sigaction(SIGINT, &sa, NULL);
91  sigaction(SIGQUIT, &sa, NULL);
92 }
void interactive_sigint_handler(int sig)
SIGINT handler for the interactive prompt.
Definition: signals.c:26
volatile sig_atomic_t g_signal
The single global variable.
Definition: signals.c:17
void setup_execution_signals(void)
Ignore signals during command execution in the parent.
Definition: signals.c:83
void setup_interactive_signals(void)
Configure signals for the interactive prompt.
Definition: signals.c:43
void reset_child_signals(void)
Reset signals to default behavior for the child processes.
Definition: signals.c:66
Signal handler prototypes.