From 8ef36cb2262ef04d68faeba04d647885c4492b90 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Thu, 29 Aug 2024 17:22:14 +0200 Subject: [PATCH] Implement signal handling on wildcard expansion --- src/input_handling.c | 7 ++++++- src/main.c | 30 ++++++++++++++++++++++++++++-- src/wildcards.c | 6 +++++- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/input_handling.c b/src/input_handling.c index d892870..554306e 100644 --- a/src/input_handling.c +++ b/src/input_handling.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/03 09:00:00 by ljiriste #+# #+# */ -/* Updated: 2024/08/26 09:43:17 by ljiriste ### ########.fr */ +/* Updated: 2024/08/29 16:45:00 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,11 @@ void handle_input(char **input, t_execution_env *env) ft_vec_init(&tokens, sizeof(t_token)); parse_tree = NULL; res = expand_wildcards(input, env); + if (g_last_signal) + { + g_last_signal = 0; + return ; + } res = res || tokenize(input, &tokens); if (tokens.size == 0 && res == 0) { diff --git a/src/main.c b/src/main.c index 0975ba6..d65381c 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/26 13:11:47 by ljiriste #+# #+# */ -/* Updated: 2024/08/29 17:11:26 by ljiriste ### ########.fr */ +/* Updated: 2024/08/29 17:17:15 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,6 +42,30 @@ void setup_signal_hadling(void) return ; } +void catch_sigquit(void) +{ + struct sigaction sa; + + ft_memset(&sa, 0, sizeof(sa)); + sa.sa_handler = handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGQUIT, &sa, NULL); + return ; +} + +void ignore_sigquit(void) +{ + struct sigaction sa; + + ft_memset(&sa, 0, sizeof(sa)); + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGQUIT, &sa, NULL); + return ; +} + static void print_help(void) { ft_printf("Minishell should be used without any arguments.\n"); @@ -121,13 +145,15 @@ int main(int argc, __attribute__((unused)) char **argv, char **envp) while (env.exit == 0) { setup_terminal(); + ignore_sigquit(); line = get_line(); - regenerate_terminal(); if (!line) { env.ret_val = 0; break ; } + catch_sigquit(); + regenerate_terminal(); handle_input(&line, &env); free(line); } diff --git a/src/wildcards.c b/src/wildcards.c index 7159aaf..dabdf85 100644 --- a/src/wildcards.c +++ b/src/wildcards.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/08 10:50:26 by ljiriste #+# #+# */ -/* Updated: 2024/08/26 09:42:45 by ljiriste ### ########.fr */ +/* Updated: 2024/08/29 17:09:47 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,6 +37,8 @@ int branch_at_star(t_vec *expanded, t_wildcard_info *info) const size_t start_size = expanded->size; t_wildcard_info info_dup; + if (g_last_signal != 0) + return (2); info_dup = *info; if (!(*(info->current_expand_char + 1) == '/' && info->current_entry_char == info->entry)) { @@ -73,6 +75,8 @@ int expand_further(t_vec *expanded, t_wildcard_info info) int add_conformant(t_vec *expanded, t_wildcard_info *info, char quote) { + if (g_last_signal != 0) + return (2); if (*info->current_expand_char == '\0' && *info->current_entry_char == '\0') return (add_entry(expanded, info)); if (*info->current_expand_char == '/' && *info->current_entry_char == '\0') -- 2.30.2