fix: leak
This commit is contained in:
parent
5e0ae80404
commit
5caeed312c
51
execution.c
51
execution.c
@ -1,7 +1,17 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* execution.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||||
|
/* Updated: 2023/02/21 13:48:39 by cchauvet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libftx/libftx.h"
|
#include "libftx/libftx.h"
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#include "utils/utils.h"
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
static char *ft_get_executable_path(char *executable_name, t_list **env)
|
static char *ft_get_executable_path(char *executable_name, t_list **env)
|
||||||
{
|
{
|
||||||
@ -83,10 +93,31 @@ static int ft_excutor(t_cmd *cmd, t_list **env)
|
|||||||
return (return_value);
|
return (return_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ft_own_cmd(t_list **env, t_cmd *cmd)
|
||||||
|
{
|
||||||
|
/* if (ft_strcmp(cmd->executable, "pwd") == 0) */
|
||||||
|
/* return (pwd(env, cmd->fd_out)); */
|
||||||
|
if (ft_strcmp(cmd->executable, "env") == 0)
|
||||||
|
return (print_env(env, cmd->fd_out));
|
||||||
|
if (ft_strcmp(cmd->executable, "export") == 0)
|
||||||
|
return (print_export(env, cmd->fd_out));
|
||||||
|
/* if (ft_strcmp(cmd->executable, "cd") == 0) */
|
||||||
|
/* return (move_folder(cmd->args[0], cmd->fd_out)); */
|
||||||
|
/* if (ft_strcmp(cmd->executable, "unset") == 0) */
|
||||||
|
/* return (unset(env, cmd->args, cmd->fd_out)); */
|
||||||
|
/* if (ft_strcmp(cmd->executable, "echo") == 0) */
|
||||||
|
/* return (echo(cmd->fd_out, cmd->args[0])); */
|
||||||
|
if (ft_strcmp(cmd->executable, "exit") == 0)
|
||||||
|
return (-2);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
int ft_cmds_executor(t_list **cmds, t_list **env)
|
int ft_cmds_executor(t_list **cmds, t_list **env)
|
||||||
{
|
{
|
||||||
t_cmd *content;
|
t_cmd *content;
|
||||||
t_list *current;
|
t_list *current;
|
||||||
|
char *return_value;
|
||||||
|
int cmd_return;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
|
|
||||||
current = *cmds;
|
current = *cmds;
|
||||||
@ -103,13 +134,25 @@ int ft_cmds_executor(t_list **cmds, t_list **env)
|
|||||||
content->fd_out = fds[1];
|
content->fd_out = fds[1];
|
||||||
((t_cmd *) current->next->content)->fd_in = fds[0];
|
((t_cmd *) current->next->content)->fd_in = fds[0];
|
||||||
}
|
}
|
||||||
content->executable = ft_get_executable_path(content->executable, env);
|
cmd_return = ft_own_cmd(env, content);
|
||||||
|
if (cmd_return == -1)
|
||||||
|
{
|
||||||
|
content->executable = ft_get_executable_path(
|
||||||
|
content->executable, env);
|
||||||
if (content->executable != NULL)
|
if (content->executable != NULL)
|
||||||
ft_excutor(content, env);
|
cmd_return = ft_excutor(content, env);
|
||||||
|
}
|
||||||
if (content->fd_in != 0)
|
if (content->fd_in != 0)
|
||||||
close(content->fd_in);
|
close(content->fd_in);
|
||||||
if (content->fd_out != 1 && content->fd_out != 2)
|
if (content->fd_out != 1 && content->fd_out != 2)
|
||||||
close(content->fd_out);
|
close(content->fd_out);
|
||||||
|
return_value = ft_itoa(cmd_return);
|
||||||
|
if (return_value == NULL)
|
||||||
|
{
|
||||||
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
set_value_by_key("?", return_value, env);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
Loading…
Reference in New Issue
Block a user