replaced occurrences of last exit_status

+ deleted envp comments
+ WIP Macro exit status
+ TODO : Invalid free of environ in readline
This commit is contained in:
LuckyLaszlo
2021-11-27 12:59:16 +01:00
parent 843b6d84c5
commit 3baf91afb3
16 changed files with 59 additions and 65 deletions

View File

@@ -1,9 +1,6 @@
#include "minishell.h"
// a integrer dans header
char *init_prompt(char *prompt_base);
int builtin_cd(int argc, char *argv[], t_all *c)
{
(void)argc;

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 05:01:26 by lperrey #+# #+# */
/* Updated: 2021/11/26 21:51:48 by lperrey ### ########.fr */
/* Updated: 2021/11/27 11:18:55 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,7 +16,6 @@ int builtin_env(int argc, char *argv[], t_all *c) // WIP
{
(void)argc;
(void)argv;
//ft_putendl_arr_fd(c->envp, 1);
ft_putendl_arr_fd(environ, 1);
return (0);
}

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/10 05:01:22 by lperrey #+# #+# */
/* Updated: 2021/10/22 14:49:01 by lperrey ### ########.fr */
/* Updated: 2021/11/27 10:47:32 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,7 +17,7 @@ int builtin_exit(int argc, char *argv[], t_all *c) // WIP
unsigned char status;
int i;
status = c->last_exit_status;
status = get_last_exit_status();
if (argc > 2)
return (ft_reti_print(1, "exit: too many arguments\n", 2));
if (argc == 2)

View File

@@ -1,7 +1,7 @@
#include "minishell.h"
int getenv_position(char **envp, char *name)
int getenv_position(char **envp, char *name) // TODO : virer arg envp et utiliser "extern **environ" à la place
{
int i;
@@ -26,7 +26,7 @@ int builtin_export(int argc, char *argv[], t_all *c)
environ = ft_resize_2d_arr(environ, 1);
environ[env_position] = ft_strdup(argv[1]);
if (!ft_strncmp(var[0], "PATH", 4 + 1))
c->path = retrieve_path(environ);
c->path = retrieve_path();
// free var
return (0);
}

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
/* Updated: 2021/11/18 23:08:16 by hulamy ### ########.fr */
/* Updated: 2021/11/27 10:48:13 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,7 +25,7 @@ int pipeline(t_all *c)
if (ft_2d_arrlen(c->cmd_arr) == 1 && c->cmd_arr[0]->builtin_func)
simple_command_builtin(c->cmd_arr[0], c);
else
wait_subshell(pipeline_exec(c->cmd_arr, c), &c->last_exit_status);
wait_subshell(pipeline_exec(c->cmd_arr, c));
free_pipeline(&c->cmd_arr);
return (1);
}
@@ -90,6 +90,6 @@ static pid_t pipeline_exec(t_cmd *pipeline[], t_all *c)
close_pipeline_fd(c->cmd_arr);
i -= 1;
if (pipeline[i]->error)
c->last_exit_status = pipeline[i]->error;
set_last_exit_status(pipeline[i]->error);
return (pipeline[i]->pid);
}

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
/* Updated: 2021/11/18 14:08:56 by lperrey ### ########.fr */
/* Updated: 2021/11/27 11:07:19 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,7 +37,7 @@ int simple_command_builtin(t_cmd *cmd, t_all *c)
if (dup2(cmd->fd_out, STDOUT_FILENO) == -1)
return (ft_reti_perror(EXIT_FAILURE, "dup2()"));
}
c->last_exit_status = cmd->builtin_func(ft_2d_arrlen(cmd->argv), cmd->argv, c);
set_last_exit_status(cmd->builtin_func(ft_2d_arrlen(cmd->argv), cmd->argv, c));
if (!restore_stdio(stdin_dup, stdout_dup))
return (EXIT_FAILURE);
return (EXIT_SUCCESS);

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
/* Updated: 2021/11/26 21:51:15 by lperrey ### ########.fr */
/* Updated: 2021/11/27 11:11:12 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,7 +30,6 @@ int cmd_exec_in_subshell(t_cmd *cmd, t_all *c)
close_pipeline_fd(c->cmd_arr);
if (cmd->builtin_func)
free_exit(c, cmd->builtin_func(ft_2d_arrlen(cmd->argv), cmd->argv, c));
//else if (execve(cmd->path, cmd->argv, c->envp) == -1)
else if (execve(cmd->path, cmd->argv, environ) == -1)
return (ft_reti_perror_io(EXIT_FAILURE, "execve() ", cmd->argv[0]));
}

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 01:57:38 by lperrey #+# #+# */
/* Updated: 2021/11/18 23:09:46 by hulamy ### ########.fr */
/* Updated: 2021/11/27 10:43:46 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,7 @@
static int handle_wait_error(void);
void wait_subshell(pid_t last_cmd_pid, int *last_exit_status)
void wait_subshell(pid_t last_cmd_pid)
{
int wstatus;
int ret;
@@ -25,11 +25,11 @@ void wait_subshell(pid_t last_cmd_pid, int *last_exit_status)
if (waitpid(last_cmd_pid, &wstatus, 0) == -1)
perror("waitpid()");
if (WIFEXITED(wstatus))
*last_exit_status = WEXITSTATUS(wstatus);
set_last_exit_status(WEXITSTATUS(wstatus));
if (WIFSIGNALED(wstatus))
{
write(STDIN_FILENO, "\n", 1);
*last_exit_status = 128 + WTERMSIG(wstatus);
set_last_exit_status(EXIT_SIGNAL + WTERMSIG(wstatus));
}
}
ret = 0;

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/08 09:25:35 by lperrey #+# #+# */
/* Updated: 2021/11/14 08:27:40 by lperrey ### ########.fr */
/* Updated: 2021/11/27 12:58:20 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -84,7 +84,7 @@ size_t ft_2d_arrlen(void *ptr) // Replace ft_arrlen()
len++;
return (len);
}
/*
char **ft_dup_2d_char_arr(char **ptr) // Superflu si ft_dup_2d_arr() fonctionne
{
unsigned int i;
@@ -105,7 +105,7 @@ char **ft_dup_2d_char_arr(char **ptr) // Superflu si ft_dup_2d_arr() fonctionne
}
new_arr[i] = NULL;
return (new_arr);
}
} */
// Test generic. Pas certain que ça fonctionne bien avec le pointeur sur fonction
void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *))
@@ -114,7 +114,7 @@ void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *))
char **arr;
char **new_arr;
new_arr = malloc((ft_2d_arrlen(ptr) + 1) * sizeof (void *));
new_arr = ft_calloc(ft_2d_arrlen(ptr) + 1, sizeof (void *));
if (!new_arr)
return (NULL);
arr = (char **)ptr;
@@ -126,7 +126,6 @@ void *ft_dup_2d_arr(void *ptr, void *(*dup_func)(void *))
return (ft_retp_free(NULL, new_arr, ft_free_2d_arr));
i++;
}
new_arr[i] = NULL;
return (new_arr);
}

View File

@@ -6,13 +6,12 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
/* Updated: 2021/11/26 20:33:54 by lperrey ### ########.fr */
/* Updated: 2021/11/27 11:19:15 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
//int main(int argc, char *argv[], char *envp[])
int main(int argc, char *argv[])
{
t_all c;

View File

@@ -6,19 +6,12 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/24 10:52:40 by lperrey #+# #+# */
/* Updated: 2021/11/18 22:35:07 by hulamy ### ########.fr */
/* Updated: 2021/11/27 11:09:48 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
// HUGO WIP
void handle_path(t_cmd **cmd_arr, char **envp);
void find_path(char **argv, char **envp);
int handle_builtin(t_cmd *cmd);
int fill_builtin(t_cmd *cmd, int (*builtin)(int, char **, t_all *));
// HUGO WIP
void save_redirections_words(t_token *t)
{
while (t)

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
/* Updated: 2021/11/17 15:29:35 by hulamy ### ########.fr */
/* Updated: 2021/11/27 10:47:05 by lperrey ### ########.fr */
/* */
/* ************************************************************************** */
@@ -46,7 +46,7 @@ void shell_loop(t_all *c)
else if (!line_input)
{
write(1, "exit\n", 5);
free_exit(c, c->last_exit_status);
free_exit(c, get_last_exit_status());
}
}
}