🏗️」 wip(exec/exec_cmd): fixing redirections with builtins

This commit is contained in:
y-syo
2024-07-18 14:28:19 +02:00
parent fb7f5bdbef
commit a401068e3c
5 changed files with 31 additions and 16 deletions

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
/* Updated: 2024/07/09 14:40:00 by mmoussou ### ########.fr */
/* Updated: 2024/07/18 14:23:00 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -104,7 +104,7 @@ t_env *ft_envnew(char *name, char *content);
unsigned int ft_envsize(t_env *lst);
/**
* @brief DEBUG FUNC : print the actual state of the env struct
* @brief print the actual state of the env struct
*
* @param env the env struct that will be printed
*

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
/* Updated: 2024/07/15 21:04:19 by mmoussou ### ########.fr */
/* Updated: 2024/07/18 14:25:25 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,6 +28,8 @@ typedef struct s_exec
int format_quotes(t_list *list_cmd);
int exec_single_cmd_execution(t_cmd *cmd, char **env,
t_env *env_t, t_exec exec);
char *get_path(char *path, char *cmd);
int exec_split_cmd(t_list *list_cmd, t_env *env);
int switch_cmd_path(t_cmd *cmd, t_env *env);

View File

@ -6,12 +6,13 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/15 21:03:31 by mmoussou #+# #+# */
/* Updated: 2024/07/16 13:36:06 by mmoussou ### ########.fr */
/* Updated: 2024/07/18 14:27:01 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "builtins.h"
#include "error_msg.h"
void exec_cmd(char *cmd, char **argv, char **env, t_env *env_t)
{
@ -59,3 +60,21 @@ void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
if (exec.status != -1)
exec_cmd(cmd->cmd, cmd->argv, env, env_t);
}
int exec_single_cmd_execution(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
{
int fork_pid;
if (is_in_builtins(cmd->cmd) > 0 && is_in_builtins(cmd->cmd) < 5)
__fork_single_cmd(cmd, env, env_t, exec);
if (is_in_builtins(cmd->cmd) > 0 && is_in_builtins(cmd->cmd) < 5)
return (0);
fork_pid = fork();
if (!fork_pid)
{
__fork_single_cmd(cmd, env, env_t, exec);
free_exec(env_t, env);
exit(get_exit_code(-1));
}
return (fork_pid);
}

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
/* Updated: 2024/07/16 14:36:38 by adjoly ### ########.fr */
/* Updated: 2024/07/18 14:26:05 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
@ -50,7 +50,6 @@ int exec_fork_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
{
t_exec exec;
int fork_pid;
char *input;
input = ft_strdup(cmd->cmd);
@ -66,14 +65,8 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2])
return (-1);
}
free(input);
if (is_in_builtins(cmd->cmd) > 0)
exec_cmd(cmd->cmd, cmd->argv, env, env_t);
if (is_in_builtins(cmd->cmd) > 0)
return (0);
fork_pid = fork();
if (!fork_pid)
__fork_single_cmd(cmd, env, env_t, exec);
return (fork_pid);
exec.status = exec_single_cmd_execution(cmd, env, env_t, exec);
return (exec.status);
}
t_exec exec_pipe_unforked(t_exec exec, t_list *list_cmd, t_env *env)

View File

@ -3,15 +3,16 @@
/* ::: :::::::: */
/* run_checks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/18 13:30:27 by adjoly #+# #+# */
/* Updated: 2024/07/18 13:31:33 by adjoly ### ########.fr */
/* Updated: 2024/07/18 14:01:24 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
#include "error_msg.h"
#include <stdio.h>
#include <readline/history.h>
bool run_checks(char *rl)