fixed closing all pipe fds
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/29 22:06:15 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/30 14:00:36 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -97,6 +97,7 @@ void end_execution(t_msh *msh, int cmd_count)
|
||||
status = 0;
|
||||
while (i < cmd_count)
|
||||
waitpid(msh->pids[i++], &status, 0);
|
||||
close_all_pipes(msh, cmd_count, i);
|
||||
if (!g_return_code && WIFEXITED(status))
|
||||
g_return_code = WEXITSTATUS(status);
|
||||
if (WIFSIGNALED(status))
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/29 21:50:52 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/30 14:00:33 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -95,6 +95,7 @@ void redirect_input(t_msh *msh, int i, char **cmd_args);
|
||||
t_env *env_add_back(t_env *env, char *name, char *value);
|
||||
void print_syntax_error_bonus(t_cmd *cmd, t_cmd *cmds);
|
||||
int filename_corresponds(char *wildcard, char *value);
|
||||
void close_all_pipes(t_msh *msh, int cmd_count, int i);
|
||||
t_token *parse_cmds_to_token(t_cmd *command, t_env *env);
|
||||
int ft_export(t_msh *msh, t_token *cmd, t_env *env);
|
||||
void print_env_declare(t_msh *msh, t_env *env_orig);
|
||||
@ -126,6 +127,7 @@ void ft_exit(t_msh *msh, int exit_code);
|
||||
int get_parenthesis_cmd_len(char *cmd);
|
||||
char **split_paths_from_env(t_env *env);
|
||||
int add_return_code_to_str(char *res);
|
||||
void close_pipe_fds(t_msh *msh, int i);
|
||||
void parse_var(t_msh *msh, char *line);
|
||||
int get_var_name_len(char *command);
|
||||
void handle_minishellrc(t_msh *msh);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/24 20:37:41 by marde-vr ### ########.fr */
|
||||
/* Updated: 2024/04/30 14:02:25 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -60,7 +60,8 @@ void get_path(t_msh *msh, int *found)
|
||||
char **paths;
|
||||
|
||||
paths = split_paths_from_env(msh->env);
|
||||
if (!paths || !*(msh->tokens->value))
|
||||
if (!paths || !*(msh->tokens->value)
|
||||
|| ft_str_is_only_char(msh->tokens->value, '.'))
|
||||
{
|
||||
free_paths(paths);
|
||||
return ;
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/26 14:43:52 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/30 13:56:03 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
void close_pipe_fds(t_msh *msh, int i)
|
||||
{
|
||||
if (msh->fds)
|
||||
{
|
||||
if (i != 0)
|
||||
{
|
||||
if (msh->fds[i - 1][0] > 2)
|
||||
@ -21,10 +23,11 @@ void close_pipe_fds(t_msh *msh, int i)
|
||||
if (msh->fds[i - 1][1] > 2)
|
||||
close(msh->fds[i - 1][1]);
|
||||
}
|
||||
if (msh->fds[i][0] > 2)
|
||||
if (msh->fds[i] && msh->fds[i][0] > 2)
|
||||
close(msh->fds[i][0]);
|
||||
if (msh->fds[i][1] > 2)
|
||||
if (msh->fds[i] && msh->fds[i][1] > 2)
|
||||
close(msh->fds[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_parenthesis(t_msh *msh)
|
||||
|
12
srcs/utils.c
12
srcs/utils.c
@ -6,7 +6,7 @@
|
||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
||||
/* Updated: 2024/04/29 13:00:22 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/30 14:03:28 by marde-vr ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -73,3 +73,13 @@ int file_access(t_msh *msh, int *found)
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void close_all_pipes(t_msh *msh, int cmd_count, int i)
|
||||
{
|
||||
i = 0;
|
||||
while (i < cmd_count)
|
||||
{
|
||||
close_pipe_fds(msh, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
9
todo
9
todo
@ -1,16 +1,11 @@
|
||||
- .. # (pas de command not found)
|
||||
- cat Makefile | commandnotfound | cat
|
||||
- cat < Makefile | rev | cat -e | rev | cat
|
||||
|
||||
CPT
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
probably repaired:
|
||||
|
||||
- cat Makefile | commandnotfound | cat
|
||||
- .. # (pas de command not found)
|
||||
- echo -nnn -n -nnnnnn aaa -nn # (invalid write/read)
|
||||
- echo -nnn -n -a -nnnnnn aaa -nn # (pas de print de flag apres le -a) (mais ca marche sur echo -nnn -n -nigga -nnnnnn aaa -nn ????????????????)
|
||||
- cat filenotfound -> exit # (exit avec le status 0 et pas 1)
|
||||
|
Reference in New Issue
Block a user