MiniDevil As beautiful as a shell
heredoc_signals.c
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* heredoc_signals.c :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: baelgadi <baelgadi@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2025/12/12 22:35:52 by baelgadi #+# #+# */
9 /* Updated: 2026/03/04 04:54:14 by baelgadi ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #include <fcntl.h>
14 #include "signals.h"
15 #include "libft.h"
16 
27 {
28  g_signal = sig;
29  ft_putchar_fd('\n', STDOUT_FILENO);
30  close(STDIN_FILENO);
31 }
32 
41 {
42  struct sigaction sa_int;
43  struct sigaction sa_quit;
44 
45  ft_memset(&sa_int, 0, sizeof(sa_int));
46  sa_int.sa_handler = heredoc_sigint_handler;
47  sigemptyset(&sa_int.sa_mask);
48  sa_int.sa_flags = 0;
49  sigaction(SIGINT, &sa_int, NULL);
50  ft_memset(&sa_quit, 0, sizeof(sa_quit));
51  sa_quit.sa_handler = SIG_IGN;
52  sigemptyset(&sa_quit.sa_mask);
53  sa_quit.sa_flags = 0;
54  sigaction(SIGQUIT, &sa_quit, NULL);
55 }
56 
62 void restore_stdin(void)
63 {
64  int tty_fd;
65 
66  tty_fd = open("/dev/tty", O_RDONLY);
67  if (tty_fd != -1 && tty_fd != STDIN_FILENO)
68  {
69  dup2(tty_fd, STDIN_FILENO);
70  close(tty_fd);
71  }
72 }
void heredoc_sigint_handler(int sig)
SIGINT handler for heredoc.
void restore_stdin(void)
Restore STDIN after heredoc SIGINT closed it.
void setup_heredoc_signals(void)
Configure signals for heredoc.
volatile sig_atomic_t g_signal
The single global variable.
Definition: signals.c:17
Signal handler prototypes.