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]);
|
close(content->fd_out[1]);
|
||||||
free(content);
|
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;
|
} t_cmd;
|
||||||
|
|
||||||
void ft_cmddel(void *content);
|
void ft_cmddel(void *content);
|
||||||
void ft_cmd_waiter(void *content);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,7 +32,7 @@ static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
|||||||
else if (ft_strcmp(cmd->executable, "exit") == 0)
|
else if (ft_strcmp(cmd->executable, "exit") == 0)
|
||||||
{
|
{
|
||||||
return_code = ft_exit(cmd->args + 1);
|
return_code = ft_exit(cmd->args + 1);
|
||||||
if (return_code > 0)
|
if (return_code >= 0)
|
||||||
{
|
{
|
||||||
data->exit_code = return_code;
|
data->exit_code = return_code;
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -110,6 +110,5 @@ int ft_cmds_executor(t_data *data)
|
|||||||
ft_closer(content->fd_out);
|
ft_closer(content->fd_out);
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
ft_lstiter(*data->cmds, ft_cmd_waiter);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
16
main.c
16
main.c
@ -10,6 +10,8 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cmd/cmd.h"
|
||||||
|
#include "libftx/libft/list.h"
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static char *ft_get_user_input()
|
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)
|
static int ft_minishell(t_data *data, char *line)
|
||||||
{
|
{
|
||||||
char *line_clean;
|
char *line_clean;
|
||||||
|
t_list *current;
|
||||||
|
t_cmd *content;
|
||||||
|
|
||||||
if (ft_syntax_verif(data, line))
|
if (ft_syntax_verif(data, line))
|
||||||
return (0);
|
return (0);
|
||||||
@ -49,12 +53,18 @@ static int ft_minishell(t_data *data, char *line)
|
|||||||
free(line_clean);
|
free(line_clean);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
free(line_clean);
|
||||||
if (ft_cmds_executor(data) == 1)
|
if (ft_cmds_executor(data) == 1)
|
||||||
{
|
|
||||||
free(line_clean);
|
|
||||||
return (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;
|
||||||
}
|
}
|
||||||
free(line_clean);
|
ft_lstclear(data->cmds, ft_cmddel);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,5 +26,7 @@
|
|||||||
# include <readline/readline.h>
|
# include <readline/readline.h>
|
||||||
# include <readline/history.h>
|
# include <readline/history.h>
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <sys/wait.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,7 +5,7 @@ char *ft_get_executable_with_path(const char *name)
|
|||||||
{
|
{
|
||||||
char *path;
|
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");
|
ft_eprintf("minishell: %s bash: No such file or directery\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -50,7 +50,7 @@ char *ft_get_executable_without_path(t_list **env, const char *name)
|
|||||||
ft_eprintf("minishell: malloc failed\n");
|
ft_eprintf("minishell: malloc failed\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (access(path, X_OK))
|
if (access(path, X_OK) == 0)
|
||||||
break;
|
break;
|
||||||
free(path);
|
free(path);
|
||||||
path = NULL;
|
path = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user