Signal: Added comments for better documentation.

This commit is contained in:
Jérôme Guélen 2025-02-21 17:03:41 +01:00 committed by Khaïs COLIN
parent 776ce85255
commit d26d883a91

View file

@ -6,14 +6,24 @@
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/20 10:26:05 by jguelen #+# #+# */
/* Updated: 2025/02/21 15:32:57 by jguelen ### ########.fr */
/* Updated: 2025/02/21 17:02:33 by jguelen ### ########.fr */
/* */
/* ************************************************************************** */
#include "sig.h"
/*
** g_signum exists to store the value of a signal if relevant for later
** processing.
** NOTE: g_signum starts at 0 and should be set back to 0 after the information
** it stores has been properly processed.
*/
int g_signum = 0;
/*
** Stores the signal number corresponding to the caught signal into g_signum
** for later processing.
*/
static void sig_interactive(int signum)
{
g_signum = signum;
@ -21,6 +31,8 @@ static void sig_interactive(int signum)
/*
** Ignores the signal if it was sent by a kill command.
** Otherwise stores the value of the caught signal in g_signum for later
** processing.
*/
static void ignoreif_sent_by_kill(int signum, siginfo_t *siginfo, void *context)
{
@ -30,6 +42,11 @@ static void ignoreif_sent_by_kill(int signum, siginfo_t *siginfo, void *context)
g_signum = signum;
}
/*
** Catches SIGINT and SIGQUIT.
** Set to ignore SIGQUIT and catch SIGINT to set g_signum for
** further processing when in interactive mode.
*/
int set_interactive_mode_sig_handling(void)
{
struct sigaction sig_act;
@ -46,6 +63,11 @@ int set_interactive_mode_sig_handling(void)
return (0);
}
/*
** Set to ignore SIGINT and SIGQUIT signals if they are generated through
** a call to kill when the program is currently executing commands.
** Otherwise set g_signum to the number corresponding to the caught signal.
*/
int set_exec_mode_sig_handling(void)
{
struct sigaction sig_act;