fix: non nuiltins is now startable

This commit is contained in:
Camille Chauvet 2023-03-10 13:34:23 +01:00
parent 1a4ed128e7
commit 087a96e54b
7 changed files with 20 additions and 21 deletions

BIN
.nfs00000000098c816200000391 Executable file

Binary file not shown.

View File

@ -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);
}
}

View File

@ -14,6 +14,5 @@ typedef struct s_cmd
} t_cmd;
void ft_cmddel(void *content);
void ft_cmd_waiter(void *content);
#endif

View File

@ -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);
}

16
main.c
View File

@ -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);
}
free(line_clean);
if (ft_cmds_executor(data) == 1)
{
free(line_clean);
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;
}
free(line_clean);
ft_lstclear(data->cmds, ft_cmddel);
return (0);
}

View File

@ -26,5 +26,7 @@
# include <readline/readline.h>
# include <readline/history.h>
# include <signal.h>
# include <sys/types.h>
# include <sys/wait.h>
#endif

View File

@ -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;