preliminary signals
This commit is contained in:
parent
9f5c134517
commit
49d3a8232b
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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"
|
||||
|
||||
void signal_init_minishell(void);
|
||||
void sigint_heredoc_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
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: willem <willem@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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);
|
||||
executor_close_fds(command->n_fds);
|
||||
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));
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: willem <willem@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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;
|
||||
}
|
||||
waitpid(last_pid, &exit_status, 0);
|
||||
signal_init_minishell();
|
||||
return (((exit_status) & 0xff00) >> 8);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: willem <willem@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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);
|
||||
// waitpid(pid, &status, 0);
|
||||
// return (((status) & 0xff00) >> 8);
|
||||
signal_init_parent();
|
||||
}
|
||||
else if (pid == 0)
|
||||
{
|
||||
signal_init_child();
|
||||
executor_child(command);
|
||||
exit(127);
|
||||
}
|
||||
else
|
||||
perror("fork");
|
||||
return (pid);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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);
|
||||
ft_lstclear(&minishell->commands, free_command_list);
|
||||
}
|
||||
ft_lstclear(&minishell->commands, free_command_list);
|
||||
free_minishell(minishell);
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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(cwd);
|
||||
rl_on_new_line();
|
||||
line = readline(prompt);
|
||||
free(prompt);
|
||||
if (line == NULL)
|
||||
|
||||
@ -6,23 +6,53 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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"
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
signal(SIGINT, sigint_minishell_handler);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
}
|
||||
|
||||
void sigint_minishell_handler(int signum)
|
||||
void signal_init_parent(void)
|
||||
{
|
||||
(void)signum;
|
||||
ft_putstr_fd("\n", 1);
|
||||
rl_on_new_line();
|
||||
rl_redisplay();
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user