diff --git a/.nfs00000000098c816200000391 b/.nfs00000000098c816200000391 new file mode 100755 index 0000000..c1c0570 Binary files /dev/null and b/.nfs00000000098c816200000391 differ diff --git a/cmd/cmd.c b/cmd/cmd.c index 59d9639..0824964 100644 --- a/cmd/cmd.c +++ b/cmd/cmd.c @@ -31,14 +31,3 @@ void ft_cmddel(void *ptr) close(content->fd_out[1]); free(content); } - -void ft_cmd_waiter(void *ptr) -{ - t_cmd *cmd; - - cmd = ptr; - if (cmd->pid != -1) - { - waitpid(cmd->pid, ft_get_exit_code(), 0); - } -} diff --git a/cmd/cmd.h b/cmd/cmd.h index 4c34143..b04dbbb 100644 --- a/cmd/cmd.h +++ b/cmd/cmd.h @@ -14,6 +14,5 @@ typedef struct s_cmd } t_cmd; void ft_cmddel(void *content); -void ft_cmd_waiter(void *content); #endif diff --git a/execution/execution.c b/execution/execution.c index 9cc79fd..f18548d 100644 --- a/execution/execution.c +++ b/execution/execution.c @@ -32,7 +32,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd) else if (ft_strcmp(cmd->executable, "exit") == 0) { return_code = ft_exit(cmd->args + 1); - if (return_code > 0) + if (return_code >= 0) { data->exit_code = return_code; return (-1); @@ -110,6 +110,5 @@ int ft_cmds_executor(t_data *data) ft_closer(content->fd_out); current = current->next; } - ft_lstiter(*data->cmds, ft_cmd_waiter); return (0); } diff --git a/main.c b/main.c index a4e8002..c6ae897 100644 --- a/main.c +++ b/main.c @@ -10,6 +10,8 @@ /* */ /* ************************************************************************** */ +#include "cmd/cmd.h" +#include "libftx/libft/list.h" #include "minishell.h" static char *ft_get_user_input() @@ -38,6 +40,8 @@ static char *ft_get_user_input() static int ft_minishell(t_data *data, char *line) { char *line_clean; + t_list *current; + t_cmd *content; if (ft_syntax_verif(data, line)) return (0); @@ -49,12 +53,18 @@ static int ft_minishell(t_data *data, char *line) free(line_clean); return (0); } - if (ft_cmds_executor(data) == 1) - { - free(line_clean); - return (1); - } free(line_clean); + if (ft_cmds_executor(data) == 1) + return (1); + current = *data->cmds; + while (current != NULL) + { + content = current->content; + if (content->own_cmd == 0 && content->pid != -1) + waitpid(content->pid, &data->exit_code, 0); + current = current->next; + } + ft_lstclear(data->cmds, ft_cmddel); return (0); } diff --git a/minishell.h b/minishell.h index aed8af2..7a14123 100644 --- a/minishell.h +++ b/minishell.h @@ -26,5 +26,7 @@ # include # include # include +# include +# include #endif diff --git a/utils/ft_get_executable.c b/utils/ft_get_executable.c index 4c99a6d..60976ee 100644 --- a/utils/ft_get_executable.c +++ b/utils/ft_get_executable.c @@ -5,7 +5,7 @@ char *ft_get_executable_with_path(const char *name) { char *path; - if (access(name, F_OK) == 0) + if (access(name, F_OK) != 0) { ft_eprintf("minishell: %s bash: No such file or directery\n"); return (NULL); @@ -50,7 +50,7 @@ char *ft_get_executable_without_path(t_list **env, const char *name) ft_eprintf("minishell: malloc failed\n"); break; } - if (access(path, X_OK)) + if (access(path, X_OK) == 0) break; free(path); path = NULL;