maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
signals.h File Reference
#include <termios.h>
#include <sys/ioctl.h>
#include <signal.h>
#include "shell.h"
Include dependency graph for signals.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  s_signal_context
 

Macros

#define _GNU_SOURCE
 

Typedefs

typedef struct s_signal_context t_signal_context
 

Functions

t_signal_contextget_context (t_ms_data *data)
 
void signal_reset_prompt (int signo, siginfo_t *info, void *ucontext)
 
void set_signals_interactive (t_ms_data *data)
 
void signal_print_newline (int signal)
 
void sigquit_ignore (void)
 
void set_signals_noninteractive (void)
 
void handle_sigint_heredoc (int signo)
 
int ft_perror (char *str)
 
int is_external_command_running (void)
 

Variables

volatile sig_atomic_t g_heredoc_interrupted
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 15 of file signals.h.

Typedef Documentation

◆ t_signal_context

Function Documentation

◆ ft_perror()

int ft_perror ( char *  str)

Definition at line 18 of file exit_status_utils.c.

19{
20 perror (str);
21 exit(EXIT_FAILURE);
22}
#define EXIT_FAILURE
Definition exit_status.h:17

◆ get_context()

t_signal_context * get_context ( t_ms_data data)

Definition at line 21 of file signals_utils.c.

22{
23 static t_signal_context *context = NULL;
24
25 if (data != NULL)
26 {
27 if (!context)
28 {
29 context = malloc(sizeof(t_signal_context));
30 if (!context)
31 return (NULL);
32 }
33 context->data_cxt = data;
34 }
35 return (context);
36}
t_ms_data * data_cxt
Definition signals.h:24

References s_signal_context::data_cxt.

Referenced by free_signal_context().

Here is the caller graph for this function:

◆ handle_sigint_heredoc()

void handle_sigint_heredoc ( int  signo)

Definition at line 38 of file signals_utils.c.

39{
40 (void)signo;
42}
volatile sig_atomic_t g_heredoc_interrupted

References g_heredoc_interrupted.

Referenced by setup_sigint_handler().

Here is the caller graph for this function:

◆ is_external_command_running()

int is_external_command_running ( void  )

Definition at line 44 of file signals_utils.c.

45{
46 pid_t child_pid;
47
48 child_pid = waitpid(-1, NULL, WNOHANG);
49 if (child_pid == 0)
50 return (1);
51 else
52 return (0);
53}

Referenced by signal_reset_prompt().

Here is the caller graph for this function:

◆ set_signals_interactive()

void set_signals_interactive ( t_ms_data data)

Definition at line 43 of file signals.c.

44{
45 struct sigaction sa;
46
47 (void)data;
48 sa.sa_sigaction = signal_reset_prompt;
49 sa.sa_flags = SA_RESTART | SA_SIGINFO;
50 sigemptyset(&sa.sa_mask);
51 sigaction(SIGINT, &sa, NULL);
52}
void signal_reset_prompt(int signo, siginfo_t *info, void *ucontext)
Definition signals.c:54

References signal_reset_prompt().

Referenced by main_loop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_signals_noninteractive()

void set_signals_noninteractive ( void  )

Definition at line 66 of file signals.c.

67{
68 struct sigaction sa;
69
70 sa.sa_handler = SIG_IGN;
71 sigemptyset(&sa.sa_mask);
72 sa.sa_flags = 0;
73 sigaction(SIGQUIT, &sa, NULL);
74}

Referenced by main_loop().

Here is the caller graph for this function:

◆ signal_print_newline()

void signal_print_newline ( int  signal)

Definition at line 26 of file signals.c.

27{
28 (void)signal;
29 write(STDOUT_FILENO, "\n", 1);
30 rl_on_new_line();
31}

◆ signal_reset_prompt()

void signal_reset_prompt ( int  signo,
siginfo_t *  info,
void *  ucontext 
)

Definition at line 54 of file signals.c.

55{
56 (void)signo;
57 (void)info;
58 (void)ucontext;
59 write(STDOUT_FILENO, "\n", 1);
60 rl_on_new_line();
61 rl_replace_line("", 0);
63 rl_redisplay();
64}
int is_external_command_running(void)

References is_external_command_running().

Referenced by set_signals_interactive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigquit_ignore()

void sigquit_ignore ( void  )

Definition at line 33 of file signals.c.

34{
35 struct sigaction a;
36
37 sigemptyset(&a.sa_mask);
38 a.sa_flags = 0;
39 a.sa_handler = SIG_IGN;
40 sigaction(SIGQUIT, &a, NULL);
41}

Variable Documentation

◆ g_heredoc_interrupted

volatile sig_atomic_t g_heredoc_interrupted
extern