added prints

This commit is contained in:
mdev9
2024-04-18 17:41:25 +02:00
parent 6fb0af3d17
commit be46825893
3 changed files with 43 additions and 12 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
/* Updated: 2024/04/17 16:45:34 by tomoron ### ########.fr */ /* Updated: 2024/04/18 17:22:28 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,7 +26,10 @@ void redirect_input(t_msh *msh, int i)
ft_printf_fd(2, "redirecting pipe input\n"); ft_printf_fd(2, "redirecting pipe input\n");
ft_printf_fd(2, "input of cmd %d: 0 -> %d\n", i, msh->fds[i - 1][0]); ft_printf_fd(2, "input of cmd %d: 0 -> %d\n", i, msh->fds[i - 1][0]);
if (dup2(msh->fds[i - 1][0], 0) < 0) if (dup2(msh->fds[i - 1][0], 0) < 0)
{
perror("dup2"); //debug
ft_exit(msh, 1); ft_exit(msh, 1);
}
} }
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */ /* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */
/* Updated: 2024/04/17 18:33:43 by tomoron ### ########.fr */ /* Updated: 2024/04/18 17:23:18 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,9 +24,6 @@ void redirect_output(t_msh *msh, int i)
else else
{ {
ft_printf_fd(2, "redirecting pipe output\n"); ft_printf_fd(2, "redirecting pipe output\n");
ft_printf_fd(2, "%p\n", msh->fds[i]);
//ft_printf_fd(2, "output of cmd %d: 1 -> %d\n", i, msh->fds[i - 1][1]);
ft_printf_fd(2, "yes\n");
//sleep(1); //sleep(1);
if (dup2(msh->fds[i][1], 1) < 0) if (dup2(msh->fds[i][1], 1) < 0)
{ {
@ -34,8 +31,6 @@ void redirect_output(t_msh *msh, int i)
ft_printf_fd(2, "exiting\n"); ft_printf_fd(2, "exiting\n");
//ft_exit(msh, 1); //ft_exit(msh, 1);
} }
ft_printf_fd(2,"help pls\n");
fflush(stdout); // Flush stdout
} }
} }

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */ /* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
/* Updated: 2024/04/14 11:34:47 by marde-vr ### ########.fr */ /* Updated: 2024/04/18 17:37:19 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,14 +17,26 @@ void close_pipe_fds(t_msh *msh, int i)
if (i != 0) if (i != 0)
{ {
if (msh->fds[i - 1][0] > 2) if (msh->fds[i - 1][0] > 2)
{
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i-1][0]);
close(msh->fds[i - 1][0]); close(msh->fds[i - 1][0]);
}
if (msh->fds[i - 1][1] > 2) if (msh->fds[i - 1][1] > 2)
{
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i-1][1]);
close(msh->fds[i - 1][1]); close(msh->fds[i - 1][1]);
}
} }
if (msh->fds[i][0] > 2) if (msh->fds[i][0] > 2)
{
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i][0]);
close(msh->fds[i][0]); close(msh->fds[i][0]);
}
if (msh->fds[i][1] > 2) if (msh->fds[i][1] > 2)
{
ft_printf_fd(2, "closing fd %d in child\n", msh->fds[i][1]);
close(msh->fds[i][1]); close(msh->fds[i][1]);
}
} }
void execute_command(t_msh *msh, char **cmd_args) void execute_command(t_msh *msh, char **cmd_args)
@ -42,7 +54,10 @@ void execute_command(t_msh *msh, char **cmd_args)
set_echoctl(msh->echoctl); set_echoctl(msh->echoctl);
env = env_to_char_tab(msh->env); env = env_to_char_tab(msh->env);
if(env) if(env)
{
ft_printf_fd(2, "execveing %s\n", msh->tokens->value);
execve(msh->tokens->value, cmd_args, env); execve(msh->tokens->value, cmd_args, env);
}
ft_free_str_arr(env); ft_free_str_arr(env);
} }
} }
@ -72,20 +87,38 @@ void parent(t_msh *msh, int i, int cmd_count)
signal(SIGQUIT, signal_handler_command); signal(SIGQUIT, signal_handler_command);
if (i != 0) if (i != 0)
{ {
if (msh->fds[i - 1][0] > 2) if (msh->fds[i - 1][0] > 2)
close(msh->fds[i - 1][0]); {
if (msh->fds[i - 1][1] > 2) ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i - 1][0]);
close(msh->fds[i - 1][1]); close(msh->fds[i - 1][0]);
}
if (msh->fds[i - 1][1] > 2)
{
ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i - 1][1]);
close(msh->fds[i - 1][1]);
}
} }
if (i == cmd_count - 1) if (i == cmd_count - 1)
{ {
if (msh->fds[i][0] > 2) if (msh->fds[i][0] > 2)
{
ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i][0]);
close(msh->fds[i][0]); close(msh->fds[i][0]);
}
if (msh->fds[i][1] > 2) if (msh->fds[i][1] > 2)
{
ft_printf_fd(2, "closing fd %d in parent\n", msh->fds[i][1]);
close(msh->fds[i][1]); close(msh->fds[i][1]);
}
} }
if (msh->in_fd > 2) if (msh->in_fd > 2)
{
ft_printf_fd(2, "closing in_fd %d in parent\n", msh->in_fd);
close(msh->in_fd); close(msh->in_fd);
}
if (msh->out_fd > 2) if (msh->out_fd > 2)
{
ft_printf_fd(2, "closing in_fd %d in parent\n", msh->out_fd);
close(msh->out_fd); close(msh->out_fd);
}
} }