preliminary signals

This commit is contained in:
whaffman 2025-02-19 13:58:50 +01:00
parent 9f5c134517
commit 49d3a8232b
7 changed files with 62 additions and 14 deletions

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/19 12:26:09 by whaffman #+# #+# */ /* Created: 2025/02/19 12:26:09 by whaffman #+# #+# */
/* Updated: 2025/02/19 12:32:26 by whaffman ######## odam.nl */ /* Updated: 2025/02/19 13:39:58 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,7 +15,10 @@
# include "minishell.h" # include "minishell.h"
void signal_init_minishell(void); void sigint_heredoc_handler(int signum);
void sigint_minishell_handler(int signum); void sigint_minishell_handler(int signum);
void signal_init_child(void);
void signal_init_parent(void);
void signal_init_minishell(void);
#endif // SIGNALS_H #endif // SIGNALS_H

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */ /* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/12 21:25:10 by willem #+# #+# */ /* Created: 2025/02/12 21:25:10 by willem #+# #+# */
/* Updated: 2025/02/13 15:04:12 by whaffman ######## odam.nl */ /* Updated: 2025/02/19 12:56:03 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -21,5 +21,12 @@ void executor_child(t_command *command)
dup2(command->fd_out, 1); dup2(command->fd_out, 1);
executor_close_fds(command->n_fds); executor_close_fds(command->n_fds);
path = executor_absolute_path(command->environment, command->command); path = executor_absolute_path(command->environment, command->command);
if (path == NULL)
{
ft_putstr_fd(RED BOLD, 2);
ft_putstr_fd(command->command, 2);
ft_putstr_fd(": " RESET "command not found\n", 2);
return ;
}
execve(path, command->args, environment_get_arr(command->environment)); execve(path, command->args, environment_get_arr(command->environment));
} }

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */ /* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/12 21:25:02 by willem #+# #+# */ /* Created: 2025/02/12 21:25:02 by willem #+# #+# */
/* Updated: 2025/02/18 15:59:43 by whaffman ######## odam.nl */ /* Updated: 2025/02/19 13:40:45 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,5 +30,6 @@ int executor_execute_pipeline(t_minishell *minishell)
current = current->next; current = current->next;
} }
waitpid(last_pid, &exit_status, 0); waitpid(last_pid, &exit_status, 0);
signal_init_minishell();
return (((exit_status) & 0xff00) >> 8); return (((exit_status) & 0xff00) >> 8);
} }

View File

@ -6,7 +6,7 @@
/* By: willem <willem@student.codam.nl> +#+ */ /* By: willem <willem@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/12 21:24:52 by willem #+# #+# */ /* Created: 2025/02/12 21:24:52 by willem #+# #+# */
/* Updated: 2025/02/18 15:41:56 by whaffman ######## odam.nl */ /* Updated: 2025/02/19 13:40:19 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,9 +26,14 @@ pid_t executor_fork(t_command *command)
close(command->fd_out); close(command->fd_out);
// waitpid(pid, &status, 0); // waitpid(pid, &status, 0);
// return (((status) & 0xff00) >> 8); // return (((status) & 0xff00) >> 8);
signal_init_parent();
} }
else if (pid == 0) else if (pid == 0)
{
signal_init_child();
executor_child(command); executor_child(command);
exit(127);
}
else else
perror("fork"); perror("fork");
return (pid); return (pid);

View File

@ -6,7 +6,7 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */ /* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */
/* Updated: 2025/02/19 12:41:05 by whaffman ######## odam.nl */ /* Updated: 2025/02/19 12:48:13 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -46,6 +46,7 @@ int main(int argc, char **argv, char **envp)
free_minishell_line(minishell); free_minishell_line(minishell);
ft_lstclear(&minishell->commands, free_command_list); ft_lstclear(&minishell->commands, free_command_list);
} }
ft_lstclear(&minishell->commands, free_command_list);
free_minishell(minishell); free_minishell(minishell);
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
} }

View File

@ -6,7 +6,7 @@
/* By: qmennen <qmennen@student.codam.nl> +#+ */ /* By: qmennen <qmennen@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */ /* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
/* Updated: 2025/02/12 12:53:38 by whaffman ######## odam.nl */ /* Updated: 2025/02/19 13:44:20 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -120,6 +120,7 @@ char *ft_prompt(t_minishell *minishell)
} }
free(user); free(user);
free(cwd); free(cwd);
rl_on_new_line();
line = readline(prompt); line = readline(prompt);
free(prompt); free(prompt);
if (line == NULL) if (line == NULL)

View File

@ -6,23 +6,53 @@
/* By: whaffman <whaffman@student.codam.nl> +#+ */ /* By: whaffman <whaffman@student.codam.nl> +#+ */
/* +#+ */ /* +#+ */
/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */ /* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */
/* Updated: 2025/02/19 12:39:05 by whaffman ######## odam.nl */ /* Updated: 2025/02/19 13:42:55 by whaffman ######## odam.nl */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
void sigint_minishell_handler(int signum)
{
(void)signum;
ft_putstr_fd("\n", 1);
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
void sigint_heredoc_handler(int signum)
{
(void)signum;
ft_putstr_fd("\n", 1);
rl_on_new_line();
rl_replace_line("", 0);
exit(130);
}
void signal_init_minishell(void) void signal_init_minishell(void)
{ {
signal(SIGINT, sigint_minishell_handler); signal(SIGINT, sigint_minishell_handler);
signal(SIGQUIT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
} }
void sigint_minishell_handler(int signum) void signal_init_parent(void)
{ {
(void)signum; signal(SIGINT, SIG_IGN);
ft_putstr_fd("\n", 1); signal(SIGQUIT, SIG_IGN);
rl_on_new_line(); }
rl_redisplay();
void signal_init_child(void)
{
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
}
void signal_init_heredoc(void)
{
signal(SIGINT, sigint_heredoc_handler);
signal(SIGQUIT, SIG_IGN);
} }