Browse Source

fix: lastcmd pipe, subshell return code

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

8
caller.c

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

2
minishell.h

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */ /* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ /* 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> +#+ +:+ +#+ */ /* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 08:57:53 by narnaud #+# #+# */ /* 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(); clear_history();
if (!silent) if (!silent)
printf("exit\n"); printf("exit\n");
if (silent)
exit(datas->exit_code);
exit(ret_code); exit(ret_code);
} }

Loading…
Cancel
Save