MiniDevil As beautiful as a shell
signals.h File Reference

Signal handler prototypes. More...

#include <signal.h>
+ Include dependency graph for signals.h:
+ This graph shows which files directly or indirectly include this file:

Detailed Description

Signal handler prototypes.

Definition in file signals.h.

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...
 
void heredoc_sigint_handler (int sig)
 SIGINT handler for heredoc. More...
 
void setup_heredoc_signals (void)
 Configure signals for heredoc. More...
 
void restore_stdin (void)
 Restore STDIN after heredoc SIGINT closed it. More...
 

Variables

volatile sig_atomic_t g_signal
 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:

◆ heredoc_sigint_handler()

void heredoc_sigint_handler ( int  sig)

SIGINT handler for heredoc.

Closes STDIN to force readline/gnl to return NULL, thus breaking the heredoc read loop

Parameters
sigSignal number (SIGINT)
Note
STDIN is later restored via restore_stdin()

Definition at line 26 of file heredoc_signals.c.

References g_signal.

Referenced by setup_heredoc_signals().

+ Here is the caller graph for this function:

◆ setup_heredoc_signals()

void setup_heredoc_signals ( void  )

Configure signals for heredoc.

Definition at line 40 of file heredoc_signals.c.

References heredoc_sigint_handler().

Referenced by handle_heredoc().

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

◆ restore_stdin()

void restore_stdin ( void  )

Restore STDIN after heredoc SIGINT closed it.

Reopens /dev/tty and uses dup2 to reassign it to fd 0 (STDIN)

Definition at line 62 of file heredoc_signals.c.

Referenced by handle_heredoc().

+ Here is the caller graph for this function:

Variable Documentation

◆ g_signal

volatile sig_atomic_t g_signal
extern

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.