Browse Source

fix: lastcmd pipe, subshell return code

master
narnaud 3 years ago
parent
commit
fe58fe4057
  1. 12
      caller.c
  2. 2
      minishell.h
  3. 4
      utils.c

12
caller.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */
/* Updated: 2022/05/11 15:29:42 by narnaud@stude ### ########.fr */
/* Updated: 2022/05/12 08:43:04 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -71,7 +71,7 @@ int piper(t_datas *datas, t_command *cmd)
pipe(pip);
if (!cmd->fd[1])
cmd->fd[1] = pip[1];
if (!cmd->fd[0])
if (!cmd->next->fd[0])
cmd->next->fd[0] = pip[0];
}
pid = caller(datas, cmd);
@ -82,11 +82,11 @@ int piper(t_datas *datas, t_command *cmd)
if (DEBUG)
printf("%s -ope: %d, pid: %d, fdin: %d, fdout: %d\n", cmd->argv[0], cmd->ope, pid, cmd->fd[0], cmd->fd[1]);
if (cmd->ope == PIPE)
pid = piper(datas, cmd->next);
else
pid = piper(datas, cmd->next);
waitpid(pid, &status, 0);
datas->exit_code = handle_status(datas, status);
if (cmd->ope != PIPE)
{
waitpid(pid, &status, 0);
datas->exit_code = handle_status(datas, status);
while (cmd->next && check_skip(datas, cmd))
cmd = cmd->next;
if (cmd->next)

2
minishell.h

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */
/* Updated: 2022/05/11 15:19:11 by narnaud@stude ### ########.fr */
/* Updated: 2022/05/12 08:43:53 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */

4
utils.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 08:57:53 by narnaud #+# #+# */
/* Updated: 2022/05/11 00:22:13 by narnaud@stude ### ########.fr */
/* Updated: 2022/05/12 08:45:47 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -66,5 +66,7 @@ void halt(t_datas *datas, int ret_code, int silent)
clear_history();
if (!silent)
printf("exit\n");
if (silent)
exit(datas->exit_code);
exit(ret_code);
}

Loading…
Cancel
Save