Merge branch 'master' of https://git.chauvet.pro/starnakin/minishell
This commit is contained in:
commit
86f01779cc
Binary file not shown.
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ NAME = minishell
|
||||
|
||||
CC = clang
|
||||
|
||||
CFLAGS = -Werror -Wextra -g
|
||||
CFLAGS = -Werror -Wextra -Wall -g
|
||||
|
||||
LIBS = libftx/libftx.a
|
||||
|
||||
|
2
cmd.c
2
cmd.c
@ -12,6 +12,7 @@
|
||||
|
||||
#include "libftx/libftx.h"
|
||||
#include "minishell.h"
|
||||
#include <sys/wait.h>
|
||||
|
||||
void ft_cmddel(void *ptr)
|
||||
{
|
||||
@ -51,5 +52,6 @@ int ft_cmd_filler(t_data *data, t_list *element, char **args)
|
||||
}
|
||||
content->args = args;
|
||||
content->executable = args[0];
|
||||
content->pid = -1;
|
||||
return (0);
|
||||
}
|
||||
|
4
cmds.c
4
cmds.c
@ -66,9 +66,7 @@ static int ft_cmds_prep(t_list **cmds, const char *line, int infile, int outfile
|
||||
current = *cmds;
|
||||
cmd = current->content;
|
||||
cmd->fd_in = infile;
|
||||
while (current->next != NULL)
|
||||
current = current->next;
|
||||
cmd = current->content;
|
||||
cmd = ft_lstlast(*cmds)->content;
|
||||
cmd->fd_out = outfile;
|
||||
return (0);
|
||||
}
|
||||
|
25
execution.c
25
execution.c
@ -12,6 +12,7 @@
|
||||
|
||||
#include "libftx/libftx.h"
|
||||
#include "minishell.h"
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static char *ft_get_executable_path(t_data *data, char *executable_name)
|
||||
@ -71,22 +72,21 @@ static char *ft_get_executable_path(t_data *data, char *executable_name)
|
||||
return (path);
|
||||
}
|
||||
|
||||
static int ft_executor(t_data *data, t_cmd *cmd)
|
||||
static void ft_executor(t_data *data, t_cmd *cmd)
|
||||
{
|
||||
int pid;
|
||||
int return_value;
|
||||
char **tab;
|
||||
|
||||
if (cmd->fd_in == -1 || cmd->fd_out == -1)
|
||||
return (1);
|
||||
return ;
|
||||
pid = fork();
|
||||
if (pid == -1)
|
||||
return (1);
|
||||
return ;
|
||||
if (pid == 0)
|
||||
{
|
||||
tab = env_to_strs(data->env);
|
||||
if (tab == NULL)
|
||||
return (1);
|
||||
return ;
|
||||
dup2(cmd->fd_out, 1);
|
||||
dup2(cmd->fd_in, 0);
|
||||
if (cmd->fd_out > 2)
|
||||
@ -95,10 +95,7 @@ static int ft_executor(t_data *data, t_cmd *cmd)
|
||||
close(cmd->fd_in);
|
||||
execve(cmd->executable, cmd->args, tab);
|
||||
}
|
||||
else
|
||||
waitpid(pid, &return_value, 0);
|
||||
data->exit_code = return_value;
|
||||
return (return_value);
|
||||
cmd->pid = pid;
|
||||
}
|
||||
|
||||
static int ft_own_cmd(t_data *data, t_cmd *cmd)
|
||||
@ -167,7 +164,7 @@ int ft_cmds_executor(t_data *data, t_list **cmds)
|
||||
content->executable = ft_get_executable_path(data,
|
||||
content->executable);
|
||||
if (content->executable != NULL)
|
||||
exit_code = ft_executor(data, content);
|
||||
ft_executor(data, content);
|
||||
}
|
||||
else if (exit_code == -2)
|
||||
return (1);
|
||||
@ -179,5 +176,13 @@ int ft_cmds_executor(t_data *data, t_list **cmds)
|
||||
close(content->fd_out);
|
||||
current = current->next;
|
||||
}
|
||||
current = *cmds;
|
||||
while (current != NULL)
|
||||
{
|
||||
content = current->content;
|
||||
if (content->pid != -1)
|
||||
waitpid(content->pid, &(data->exit_code), 0);
|
||||
current = current->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
6
main.c
6
main.c
@ -45,10 +45,10 @@ static int ft_minishell(t_data *data, char *line)
|
||||
int outfile;
|
||||
|
||||
if (ft_syntatic_verif(data, line))
|
||||
return (1);
|
||||
return (0);
|
||||
line_clean = ft_normalizer(line);
|
||||
if (line_clean == NULL)
|
||||
return (1);
|
||||
return (0);
|
||||
outfile = ft_outfile(data, line_clean);
|
||||
if (outfile == -2)
|
||||
{
|
||||
@ -69,8 +69,6 @@ static int ft_minishell(t_data *data, char *line)
|
||||
close(outfile);
|
||||
if (infile > 2)
|
||||
close(infile);
|
||||
ft_lstclear(cmds, ft_cmddel);
|
||||
free(cmds);
|
||||
free(line_clean);
|
||||
return (1);
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ typedef struct s_cmd
|
||||
{
|
||||
int fd_in;
|
||||
int fd_out;
|
||||
int pid;
|
||||
char *executable;
|
||||
char **args;
|
||||
} t_cmd;
|
||||
|
Loading…
Reference in New Issue
Block a user