fix leak mini inception and no path

This commit is contained in:
kinou-p 2022-04-19 07:20:37 +02:00
parent fa522d064f
commit 0d69254798
5 changed files with 27 additions and 16 deletions

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/06 13:27:11 by apommier #+# #+# */ /* Created: 2022/03/06 13:27:11 by apommier #+# #+# */
/* Updated: 2022/04/18 15:19:51 by apommier ### ########.fr */ /* Updated: 2022/04/19 06:46:37 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -47,6 +47,8 @@ char **ft_dup_double(char **env)
int i; int i;
i = 0; i = 0;
if (!env)
return (0);
while (env[i]) while (env[i])
i++; i++;
new_tab = ft_calloc(sizeof(char *), i + 1); new_tab = ft_calloc(sizeof(char *), i + 1);
@ -90,8 +92,8 @@ void print_prompt(char **path)
free_double(path); free_double(path);
exit_shell(cmd, 0); exit_shell(cmd, 0);
} }
add_history(input); add_history(input);
if (ft_strlen(input) && next_space(input, 0) && input) if (ft_strlen(input) && next_space(input, 0) && input && path)
{ {
cmd = set_cmd(input, path, err_var); cmd = set_cmd(input, path, err_var);
//path = ft_dup_double(path); //path = ft_dup_double(path);
@ -129,6 +131,7 @@ int main(int ac, char **av, char **path)
printf("Not today\n"); printf("Not today\n");
return (0); return (0);
} }
//print_double_fd(path, 1);
env = ft_dup_double(path); env = ft_dup_double(path);
av = 0; av = 0;
if (ac != 1) if (ac != 1)
@ -136,7 +139,7 @@ int main(int ac, char **av, char **path)
ft_putstr_fd("Error: too much arguments\n", 2); ft_putstr_fd("Error: too much arguments\n", 2);
return (0); return (0);
} }
printf("---MINISHELL START---\n"); printf("---MINISHELL START---\n");
signal(SIGINT, crtl_c); signal(SIGINT, crtl_c);
//signal(SIGQUIT, sig_quit); //signal(SIGQUIT, sig_quit);
print_prompt(env); print_prompt(env);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/02 18:51:31 by apommier #+# #+# */ /* Created: 2022/04/02 18:51:31 by apommier #+# #+# */
/* Updated: 2022/04/18 06:32:01 by apommier ### ########.fr */ /* Updated: 2022/04/19 07:01:19 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -89,7 +89,7 @@ void exec_cmd(t_cmd *cmd, char **env, int *fdpipe)
if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK)) if (!cmd->current_s_cmd->cmd || access(cmd->current_s_cmd->cmd, F_OK))
{ {
ft_putstr_fd("Minishell: command not found: ", 2); ft_putstr_fd("Minishell: command not found: ", 2);
ft_putstr_fd(cmd->current_s_cmd->cmd + 1, 2); ft_putstr_fd(cmd->current_s_cmd->cmd, 2);
ft_putstr_fd("\n", 2); ft_putstr_fd("\n", 2);
close(0); close(0);
close(1); close(1);
@ -124,8 +124,8 @@ void execute(t_cmd *cmd, char **env)
int tmpout = -1; int tmpout = -1;
int i; int i;
tmpin = -1;
tmpout = -1;
i = 0; i = 0;
fdpipe[1] = -1; fdpipe[1] = -1;
tmpin = dup(0); tmpin = dup(0);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/08 16:58:40 by apommier #+# #+# */ /* Created: 2022/03/08 16:58:40 by apommier #+# #+# */
/* Updated: 2022/04/10 21:07:05 by apommier ### ########.fr */ /* Updated: 2022/04/19 07:01:35 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,6 +49,11 @@ char *does_access(char **path, char **exec)
char *cmd; char *cmd;
char *swap; char *swap;
// if (!path)
// {
// ft_putstr_fd("Minishell: no PATH\n", 2);
// return (0);
// }
swap = 0; swap = 0;
cmd = 0; cmd = 0;
i = 0; i = 0;
@ -76,17 +81,15 @@ char *get_command(char **exec, char **path)
char *swap; char *swap;
swap = 0; swap = 0;
if (!path)
return (0);
if ((exec[0][0] == '/' || exec[0][0] == '.') && !access(exec[0], F_OK)) if ((exec[0][0] == '/' || exec[0][0] == '.') && !access(exec[0], F_OK))
{ {
//free_double(path); //free_double(path);
return (exec[0]); return (exec[0]);
} }
else if (exec[0][0] == '/') else if (exec[0][0] == '/')
{
printf("BAD PATH FOR CMD\n");
//free_double(path);
return(0); return(0);
}
swap = does_access(path, exec); swap = does_access(path, exec);
return (swap); return (swap);
} }

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/09 12:33:30 by apommier #+# #+# */ /* Created: 2022/03/09 12:33:30 by apommier #+# #+# */
/* Updated: 2022/04/17 11:05:04 by apommier ### ########.fr */ /* Updated: 2022/04/19 07:14:17 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,6 +19,7 @@ void exit_shell(t_cmd *cmd, int ret)
i = 0; i = 0;
//if (cmd) //if (cmd)
// free_double(cmd->env); // free_double(cmd->env);
ft_putstr_fd("exit\n", 1);
if (!cmd) if (!cmd)
exit(ret); exit(ret);
if (cmd->tmpin != -1) if (cmd->tmpin != -1)
@ -38,7 +39,7 @@ void exit_shell(t_cmd *cmd, int ret)
free_cmd(cmd); free_cmd(cmd);
clear_history(); clear_history();
//print_double_fd(cmd->s_cmds[0]->env, 1); //print_double_fd(cmd->s_cmds[0]->env, 1);
ft_putstr_fd("exit\n", 1);
//if (cmd->path) //if (cmd->path)
//free_double(cmd->path); //free_double(cmd->path);
cmd = 0; cmd = 0;

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/09 23:58:21 by apommier #+# #+# */ /* Created: 2022/04/09 23:58:21 by apommier #+# #+# */
/* Updated: 2022/04/18 06:43:23 by apommier ### ########.fr */ /* Updated: 2022/04/19 07:09:58 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -230,7 +230,11 @@ int parse_quote(t_cmd *cmd)
if (!is_builtin(cmd->s_cmds[i]->args[0])) if (!is_builtin(cmd->s_cmds[i]->args[0]))
cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path); cmd->s_cmds[i]->cmd = get_command(cmd->s_cmds[i]->args, cmd->path);
else else
cmd->s_cmds[i]->cmd = cmd->s_cmds[i]->args[0];
if (!cmd->s_cmds[i]->cmd)
cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]); cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]);
else
cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->cmd);
//free(cmd->s_cmds[i]->cmd); //free(cmd->s_cmds[i]->cmd);
//cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]); //cmd->s_cmds[i]->cmd = ft_strdup(cmd->s_cmds[i]->args[0]);
//printf("parse quote -%s-\n", cmd->s_cmds[i]->cmd); //printf("parse quote -%s-\n", cmd->s_cmds[i]->cmd);