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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user