mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
69 lines
2.2 KiB
C
69 lines
2.2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* sig.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/05/02 12:16:37 by kcolin #+# #+# */
|
|
/* Updated: 2025/05/05 12:03:56 by jguelen ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "sig.h"
|
|
#include "signal.h"
|
|
#include "sig_handlers.h"
|
|
|
|
int g_signum = 0;
|
|
|
|
int set_interactive_mode_sig_handling(void)
|
|
{
|
|
struct sigaction sig_act;
|
|
|
|
ft_bzero(&sig_act, sizeof(struct sigaction));
|
|
sig_act.sa_handler = &sig_interactive;
|
|
sig_act.sa_flags |= SA_RESTART;
|
|
if (sigemptyset(&sig_act.sa_mask) == -1)
|
|
return (-1);
|
|
if (sigaction(SIGINT, &sig_act, NULL) == -1)
|
|
return (-1);
|
|
sig_act.sa_handler = SIG_IGN;
|
|
if (sigaction(SIGQUIT, &sig_act, NULL) == -1)
|
|
return (-1);
|
|
return (0);
|
|
}
|
|
|
|
int set_exec_mode_sig_handling(void)
|
|
{
|
|
struct sigaction sig_act;
|
|
|
|
ft_bzero(&sig_act, sizeof(struct sigaction));
|
|
if (sigemptyset(&sig_act.sa_mask) == -1)
|
|
return (-1);
|
|
sig_act.sa_sigaction = &sig_cmd;
|
|
sig_act.sa_flags |= SA_SIGINFO;
|
|
sig_act.sa_flags |= SA_RESTART;
|
|
if (sigaction(SIGINT, &sig_act, NULL) == -1)
|
|
return (-1);
|
|
if (sigaction(SIGQUIT, &sig_act, NULL) == -1)
|
|
return (-1);
|
|
return (0);
|
|
}
|
|
|
|
int set_here_doc_mode_sig_handling(void)
|
|
{
|
|
struct sigaction sig_act;
|
|
|
|
ft_bzero(&sig_act, sizeof(struct sigaction));
|
|
if (sigemptyset(&sig_act.sa_mask) == -1)
|
|
return (-1);
|
|
sig_act.sa_sigaction = &sig_heredoc;
|
|
sig_act.sa_flags |= SA_SIGINFO;
|
|
if (sigaction(SIGINT, &sig_act, NULL) == -1)
|
|
return (-1);
|
|
sig_act.sa_handler = SIG_IGN;
|
|
sig_act.sa_flags = 0;
|
|
if (sigaction(SIGQUIT, &sig_act, NULL) == -1)
|
|
return (-1);
|
|
return (0);
|
|
}
|