fix: non nuiltins is now startable
This commit is contained in:
parent
1a4ed128e7
commit
087a96e54b
BIN
.nfs00000000098c816200000391
Executable file
BIN
.nfs00000000098c816200000391
Executable file
Binary file not shown.
11
cmd/cmd.c
11
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);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,5 @@ typedef struct s_cmd
|
||||
} t_cmd;
|
||||
|
||||
void ft_cmddel(void *content);
|
||||
void ft_cmd_waiter(void *content);
|
||||
|
||||
#endif
|
||||
|
@ -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);
|
||||
}
|
||||
|
20
main.c
20
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);
|
||||
}
|
||||
|
||||
|
@ -26,5 +26,7 @@
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
# include <signal.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/wait.h>
|
||||
|
||||
#endif
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user