MiniDevil As beautiful as a shell
signals.c File Reference

Signal handlers: SIGINT / SIGQUIT for interactive & exec modes. More...

#include <readline/readline.h>
#include "signals.h"
#include "libft.h"
+ Include dependency graph for signals.c:

Detailed Description

Signal handlers: SIGINT / SIGQUIT for interactive & exec modes.

Definition in file signals.c.

Functions

void interactive_sigint_handler (int sig)
 SIGINT handler for the interactive prompt. More...
 
void setup_interactive_signals (void)
 Configure signals for the interactive prompt. More...
 
void reset_child_signals (void)
 Reset signals to default behavior for the child processes. More...
 
void setup_execution_signals (void)
 Ignore signals during command execution in the parent. More...
 

Variables

volatile sig_atomic_t g_signal = 0
 The single global variable. More...
 

Function Documentation

◆ interactive_sigint_handler()

void interactive_sigint_handler ( int  sig)

SIGINT handler for the interactive prompt.

Prints a newline and resets the readline prompt to a fresh line

Parameters
sigSignal number (SIGINT)

Definition at line 26 of file signals.c.

References g_signal.

Referenced by setup_interactive_signals().

+ Here is the caller graph for this function:

◆ setup_interactive_signals()

void setup_interactive_signals ( void  )

Configure signals for the interactive prompt.

Definition at line 43 of file signals.c.

References interactive_sigint_handler().

Referenced by handle_heredoc(), and main_loop().

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

◆ reset_child_signals()

void reset_child_signals ( void  )

Reset signals to default behavior for the child processes.

This is called after fork in child processes so that SIGINT and SIGQUIT terminate the child normally

Definition at line 66 of file signals.c.

Referenced by child_execute(), exec_left_pipe_child(), and exec_right_pipe_child().

+ Here is the caller graph for this function:

◆ setup_execution_signals()

void setup_execution_signals ( void  )

Ignore signals during command execution in the parent.

While a child process is running, the parent ignores both SIGINT and SIGQUIT so only the child is affected

Definition at line 83 of file signals.c.

Referenced by main_loop().

+ Here is the caller graph for this function:

Variable Documentation

◆ g_signal

volatile sig_atomic_t g_signal = 0

The single global variable.

Set by signal handlers and checked/cleared in the main loop. Only stores signal numbers.

Definition at line 17 of file signals.c.

Referenced by check_resize(), handle_heredoc(), handle_ui_sigwinch(), heredoc_sigint_handler(), interactive_sigint_handler(), main_loop(), and read_heredoc_lines().

Go to the source code of this file.