stuck at dup2
This commit is contained in:
parent
aa456796ac
commit
b0e7229c54
11 changed files with 39 additions and 38 deletions
|
|
@ -9,18 +9,17 @@ typedef struct s_exec t_exec;
|
||||||
struct s_exec
|
struct s_exec
|
||||||
{
|
{
|
||||||
t_type type;
|
t_type type;
|
||||||
int (*f)(t_btree *ast);
|
int (*f)(t_btree *ast, t_data *data);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern t_exec g_exec[];
|
extern t_exec g_exec[];
|
||||||
|
|
||||||
int ft_exec(t_btree *ast);
|
int ft_exec(t_btree *ast, t_data *data);
|
||||||
|
|
||||||
int ft_exec(t_btree *ast);
|
int exec_semi(t_btree *ast, t_data *data);
|
||||||
int exec_semi(t_btree *ast);
|
int exec_pipe(t_btree *ast, t_data *data);
|
||||||
int exec_pipe(t_btree *ast);
|
int exec_less(t_btree *ast, t_data *data);
|
||||||
int exec_less(t_btree *ast);
|
int exec_great(t_btree *ast, t_data *data);
|
||||||
int exec_great(t_btree *ast);
|
int exec_command(t_btree *ast, t_data *data);
|
||||||
int exec_command(t_btree *ast);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2a60fb6dcefcf969d29c0c70f4da61a305f9ccf2
|
Subproject commit 509c754e17e269f4655286ebad1bf1cf543fbf97
|
||||||
|
|
@ -12,9 +12,15 @@
|
||||||
|
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
int exec_command(t_btree *ast)
|
int exec_command(t_btree *ast, t_data *data)
|
||||||
{
|
{
|
||||||
(void)ast;
|
t_astnode *node;
|
||||||
ft_putendl("exec_commands");
|
|
||||||
|
node = ast->item;
|
||||||
|
ft_putstr_fd("befor exec: ", 2);
|
||||||
|
ft_sstrprint(((t_astnode*)ast->item)->u_data.sstr, ',');
|
||||||
|
ft_putchar('\n');
|
||||||
|
ft_cmd_process(node->u_data.sstr, &data->env);
|
||||||
|
ft_putstr_fd("after exec\n", 2);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,11 @@
|
||||||
|
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
int exec_great(t_btree *ast)
|
int exec_great(t_btree *ast, t_data *data)
|
||||||
{
|
{
|
||||||
(void)ast;
|
(void)ast;
|
||||||
ft_putendl("exec_great");
|
ft_putendl("exec_great");
|
||||||
|
ft_exec(ast->left, data);
|
||||||
|
ft_exec(ast->right, data);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,11 @@
|
||||||
|
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
int exec_less(t_btree *ast)
|
int exec_less(t_btree *ast, t_data *data)
|
||||||
{
|
{
|
||||||
(void)ast;
|
(void)ast;
|
||||||
ft_putendl("exec_less");
|
ft_putendl("exec_less");
|
||||||
|
ft_exec(ast->left, data);
|
||||||
|
ft_exec(ast->right, data);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
int exec_pipe(t_btree *ast)
|
int exec_pipe(t_btree *ast, t_data *data)
|
||||||
{
|
{
|
||||||
int filedes[2];
|
int filedes[2];
|
||||||
|
|
||||||
pipe(filedes);
|
pipe(filedes);
|
||||||
ft_debug();
|
ft_printf("doing dup2\n");
|
||||||
dup2(filedes[1], 1);
|
if ((dup2(filedes[1], 1)) == -1)
|
||||||
ft_debug();
|
return (-1);
|
||||||
ft_exec(ast->left);
|
ft_exec(ast->left, data);
|
||||||
close(filedes[1]);
|
close(filedes[1]);
|
||||||
dup2(filedes[0], 0);
|
dup2(filedes[0], 0);
|
||||||
ft_exec(ast->right);
|
ft_exec(ast->right, data);
|
||||||
close(filedes[0]);
|
close(filedes[0]);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
int exec_semi(t_btree *ast)
|
int exec_semi(t_btree *ast, t_data *data)
|
||||||
{
|
{
|
||||||
ft_exec(ast->left);
|
ft_exec(ast->left, data);
|
||||||
ft_exec(ast->right);
|
ft_exec(ast->right, data);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ t_exec g_exec[] =
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
int ft_exec(t_btree *ast)
|
int ft_exec(t_btree *ast, t_data *data)
|
||||||
{
|
{
|
||||||
t_astnode *item;
|
t_astnode *item;
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -22,7 +22,7 @@ int ft_exec(t_btree *ast)
|
||||||
while (g_exec[i].type)
|
while (g_exec[i].type)
|
||||||
{
|
{
|
||||||
if (item->type == g_exec[i].type)
|
if (item->type == g_exec[i].type)
|
||||||
return ((*g_exec[i].f)(ast));
|
return ((*g_exec[i].f)(ast, data));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ int main(void)
|
||||||
btree_apply_infix(ast, &ft_putast2);
|
btree_apply_infix(ast, &ft_putast2);
|
||||||
/* ft_lstdel(&token, &token_free); */
|
/* ft_lstdel(&token, &token_free); */
|
||||||
token = NULL;
|
token = NULL;
|
||||||
if (ft_exec(ast))
|
if (ft_exec(ast, &data))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ void sig_handler(int signo)
|
||||||
{
|
{
|
||||||
if (signo == SIGINT)
|
if (signo == SIGINT)
|
||||||
{
|
{
|
||||||
|
exit(1);
|
||||||
if (g_pid)
|
if (g_pid)
|
||||||
kill(g_pid, SIGINT);
|
kill(g_pid, SIGINT);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ int ft_cmd_process(char **argv, char ***env_p)
|
||||||
execpath = argv[0];
|
execpath = argv[0];
|
||||||
else if (!(execpath = ft_findexec(path, argv[0])))
|
else if (!(execpath = ft_findexec(path, argv[0])))
|
||||||
{
|
{
|
||||||
ft_printf("minishell: command not found: %s\n", argv[0]);
|
ft_dprintf(2, "minishell: command not found: %s\n", argv[0]);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (ft_cmd_exec(execpath, argv, env_p));
|
return (ft_cmd_exec(execpath, argv, env_p));
|
||||||
|
|
@ -25,12 +25,10 @@ int ft_cmd_exec(char *execpath, char **argv, char ***env_p)
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
char **environ;
|
char **environ;
|
||||||
char **sstr;
|
|
||||||
|
|
||||||
sstr = NULL;
|
|
||||||
if (access(execpath, X_OK) == -1)
|
if (access(execpath, X_OK) == -1)
|
||||||
{
|
{
|
||||||
ft_printf("minishell: permission denied: %s\n", argv[0]);
|
ft_dprintf(2, "minishell: permission denied: %s\n", argv[0]);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if ((pid = fork()) == -1)
|
if ((pid = fork()) == -1)
|
||||||
|
|
@ -44,14 +42,7 @@ int ft_cmd_exec(char *execpath, char **argv, char ***env_p)
|
||||||
{
|
{
|
||||||
g_pid = pid;
|
g_pid = pid;
|
||||||
wait(&status);
|
wait(&status);
|
||||||
sstr = ft_sstradd(sstr, "?");
|
builtin_setenv((char*[2]){"?", ft_itoa(status)}, env_p);
|
||||||
sstr = ft_sstradd(sstr, ft_itoa(status));
|
|
||||||
builtin_setenv(sstr, env_p);
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **ft_cmd_getav(char *cmd)
|
|
||||||
{
|
|
||||||
return (ft_split_whitespaces(cmd));
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue