c'est encore cassé mais un peut moins
This commit is contained in:
3
Makefile
3
Makefile
@ -6,7 +6,7 @@
|
||||
# By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
|
||||
# Updated: 2024/04/06 18:46:11 by tomoron ### ########.fr #
|
||||
# Updated: 2024/04/13 12:56:12 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -18,6 +18,7 @@ SRCS_RAW = main.c\
|
||||
lst_token.c\
|
||||
exec.c\
|
||||
exit.c\
|
||||
is_fd_open.c\
|
||||
echo.c\
|
||||
pwd.c\
|
||||
parsing.c\
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/07 17:47:44 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/13 12:47:16 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -80,6 +80,7 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count)
|
||||
}
|
||||
msh->in_fd = fds[0];
|
||||
msh->out_fd = fds[1];
|
||||
print_msh_struct(msh);
|
||||
}
|
||||
pid = fork();
|
||||
if (pid == -1)
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/03 17:20:55 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/13 12:58:01 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -43,6 +43,7 @@ void here_doc_child(t_msh *msh, char *eof, char *here_doc_file)
|
||||
//signal(SIGINT, signal_handler_here_doc);
|
||||
get_here_doc_input(msh, eof);
|
||||
close(msh->in_fd);
|
||||
printf("close2");
|
||||
free(here_doc_file);
|
||||
ft_exit(msh, 0);
|
||||
}
|
||||
@ -57,6 +58,7 @@ void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file)
|
||||
//signal(SIGINT, signal_handler_interactive);
|
||||
signal(SIGQUIT, signal_handler_interactive);
|
||||
close(msh->in_fd);
|
||||
printf("close 1\n");
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status))
|
||||
unlink(here_doc_file);
|
||||
msh->in_fd = open(here_doc_file, O_RDWR, 0644);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/07 19:51:29 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/13 12:54:23 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,6 +22,9 @@ void redirect_input(t_msh *msh)
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("in_fd : %d\n", msh->in_fd);
|
||||
printf("cmd : %s\n", msh->cmds->value);
|
||||
is_fd_open(msh->in_fd);
|
||||
if (dup2(msh->in_fd, 0) < 0)
|
||||
{
|
||||
perror("dup2");
|
||||
|
24
srcs/is_fd_open.c
Normal file
24
srcs/is_fd_open.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* is_fd_open.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 17:31:53 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/03/05 17:35:39 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../srcs/minishell.h"
|
||||
|
||||
int is_fd_open(int fd)
|
||||
{
|
||||
if (fcntl(fd, F_GETFL) == -1)
|
||||
{
|
||||
ft_printf_fd(2, "%d:closed\n", fd);
|
||||
return (0);
|
||||
}
|
||||
ft_printf_fd(2, "%d:open\n", fd);
|
||||
return (1);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/03 16:52:11 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/13 12:56:29 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -88,6 +88,7 @@ void child(t_msh *msh, char **cmd_args, int i);
|
||||
t_token *parse_command(char *command, t_env *env);
|
||||
void parent(t_msh *msh, int i, int cmd_count);
|
||||
char *ft_get_env(t_env *env, char *var_name);
|
||||
int is_fd_open(int fd);
|
||||
void get_out_type(t_msh *msh, t_cmd *cmds);
|
||||
void exec_commands(t_msh *msh);
|
||||
void handle_here_doc(t_msh *msh, char *eof);
|
||||
|
39
srcs/pipe.c
39
srcs/pipe.c
@ -6,25 +6,24 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/07 18:49:09 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/13 13:21:52 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
void close_pipe_fds(t_msh *msh, int i)
|
||||
{
|
||||
if (i != 0)
|
||||
void close_pipe_fds(t_msh *msh)
|
||||
{
|
||||
if (msh->in_fd > 2)
|
||||
{
|
||||
close(msh->in_fd);
|
||||
if (msh->out_fd > 2)
|
||||
close(msh->out_fd);
|
||||
printf("close in");
|
||||
}
|
||||
if (msh->in_fd > 2)
|
||||
if (msh->out_fd > 2)
|
||||
{
|
||||
close(msh->out_fd);
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
printf("close out");
|
||||
}
|
||||
//double close
|
||||
}
|
||||
|
||||
@ -57,7 +56,7 @@ void child(t_msh *msh, char **cmd_args, int i)
|
||||
if (msh->out_type == PIPE || msh->out_type == RED_O
|
||||
|| msh->out_type == RED_O_APP)
|
||||
redirect_output(msh);
|
||||
close_pipe_fds(msh, i);
|
||||
close_pipe_fds(msh);
|
||||
execute_command(msh, cmd_args);
|
||||
close(0);
|
||||
close(1);
|
||||
@ -70,19 +69,23 @@ void parent(t_msh *msh, int i, int cmd_count)
|
||||
{
|
||||
//signal(SIGINT, signal_handler_command);
|
||||
signal(SIGQUIT, signal_handler_command);
|
||||
(void)msh;
|
||||
(void) i;
|
||||
(void) cmd_count;
|
||||
printf("i : %d\n", i);
|
||||
if (i != 0)
|
||||
{
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
if (msh->out_fd > 2)
|
||||
close(msh->out_fd);
|
||||
if (msh->fds[i - 1][0] > 2)
|
||||
close(msh->fds[i - 1][0]);
|
||||
if (msh->fds[i - 1][1] > 2)
|
||||
close(msh->fds[i - 1][1]);
|
||||
}
|
||||
if (i == cmd_count - 1)
|
||||
{
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
if (msh->out_fd > 2)
|
||||
close(msh->out_fd);
|
||||
if (msh->fds[i][0] > 2)
|
||||
close(msh->fds[i][0]);
|
||||
if (msh->fds[i][1] > 2)
|
||||
close(msh->fds[i][1]);
|
||||
}
|
||||
if (msh->in_fd > 2)
|
||||
close(msh->in_fd);
|
||||
|
Reference in New Issue
Block a user