debut signal

This commit is contained in:
2024-03-22 20:12:25 +01:00
parent 2718546387
commit 7b6c75b5c3
8 changed files with 59 additions and 14 deletions

View File

@ -6,7 +6,7 @@
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
# Updated: 2024/03/05 19:11:56 by marde-vr ### ########.fr #
# Updated: 2024/03/22 14:32:18 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -36,7 +36,8 @@ SRCS_RAW = main.c\
builtins.c\
commands.c\
pipe.c\
utils.c
utils.c\
signal_handler.c
OBJS_DIR = objs/
SRCS_DIR = srcs/

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */
/* Updated: 2024/03/21 13:51:22 by marde-vr ### ########.fr */
/* Updated: 2024/03/22 14:07:57 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -70,7 +70,10 @@ char **get_cmd_args(t_msh *msh)
{
if (cur_cmd->type == ARG)
{
if(!i)
cmd_args[i] = remove_path(cur_cmd->token);
else
cmd_args[i] = cur_cmd->token;
i++;
}
else

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
/* Updated: 2024/03/21 13:42:56 by tomoron ### ########.fr */
/* Updated: 2024/03/22 17:48:45 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -93,4 +93,6 @@ void exec_commands(t_msh *msh)
free(msh->fds);
msh->fds = 0;
free(msh->pids);
signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
/* Updated: 2024/03/22 13:35:19 by tomoron ### ########.fr */
/* Updated: 2024/03/22 16:45:49 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -77,6 +77,8 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp)
(void)argv;
(*msh)->env = get_env(envp);
(*msh)->aliases = 0;
signal(SIGINT, signal_handler_interactive);
signal(SIGQUIT, signal_handler_interactive);
return (0);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
/* Updated: 2024/03/21 13:30:59 by marde-vr ### ########.fr */
/* Updated: 2024/03/22 16:44:54 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,6 +21,7 @@
# include "../libft/libft.h"
# include "fcntl.h"
# include <sys/stat.h>
# include <signal.h>
typedef enum e_token_type
{
@ -118,5 +119,7 @@ char **get_cmd_args(t_msh *msh);
void remove_command_from_msh(t_msh *msh);
int file_access(t_msh *msh, int *found);
char *remove_path(char *token);
void signal_handler_interactive(int signum);
void signal_handler_command(int signum);
#endif

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */
/* Updated: 2024/03/21 16:39:06 by marde-vr ### ########.fr */
/* Updated: 2024/03/22 15:45:44 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,10 +30,7 @@ char **split_paths_from_env(t_env *env)
cur_env_var = cur_env_var->next;
}
if (!path_in_envp)
{
ft_printf_fd(2, "minishell: error: PATH not found\n");
return (0);
}
return (ft_split(cur_env_var->value, ':'));
}
@ -71,7 +68,7 @@ void free_paths(char **paths)
int i;
i = 0;
while (paths[i])
while (paths && paths[i])
{
free(paths[i]);
i++;
@ -87,7 +84,7 @@ void get_path(t_msh *msh, int *found)
if (!paths)
{
free_paths(paths);
ft_exit(msh, 1);
return;
}
find_cmd_path(msh, paths, found);
free_paths(paths);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
/* Updated: 2024/03/21 13:50:47 by tomoron ### ########.fr */
/* Updated: 2024/03/22 17:45:02 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
@ -77,6 +77,8 @@ void child(t_msh *msh, char **cmd_args, int i)
void parent(t_msh *msh, int i, int cmd_count)
{
signal(SIGINT, signal_handler_command);
signal(SIGQUIT, signal_handler_command);
if (i != 0)
{
if (msh->fds[i - 1][0] > 2)

35
srcs/signal_handler.c Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* signal_handler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
/* Updated: 2024/03/22 19:53:02 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void signal_handler_interactive(int signum)
{
if(signum == 2)
{
g_return_code = 130;
ft_putstr_fd("\n", 1);
rl_replace_line("", 0);
rl_on_new_line();
rl_redisplay();
}
if(signum == 3)
{
rl_redisplay();
ft_putstr_fd("filsdeup", 1);
}
}
void signal_handler_command(int signum)
{
(void)signum;
}