ajout de reinitialisation du des exec dans les forks + correctif d'un segv sur free du subshell

This commit is contained in:
wescande 2017-03-08 15:19:10 +01:00
parent ec531721ea
commit 145c116e18
22 changed files with 90 additions and 72 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:51:04 by jhalford ### ########.fr */
/* Updated: 2017/03/08 14:58:19 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -193,14 +193,14 @@ int launch_function(t_process *p);
*/
int set_process(t_process *p, t_btree *ast);
int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd);
int set_process_map(t_process *p, t_btree *ast);
int set_process_cmd(t_process *p, t_btree *ast);
int set_process_while(t_process *p, t_btree *ast);
int set_process_until(t_process *p, t_btree *ast);
int set_process_if(t_process *p, t_btree *ast);
int set_process_for(t_process *p, t_btree *ast);
int set_process_case(t_process *p, t_btree *ast);
int set_process_subshell(t_process *p, t_btree *ast);
/*
** Mapping pour exec les process

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:43:35 by jhalford ### ########.fr */
/* Updated: 2017/03/08 15:10:49 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -30,6 +30,7 @@ int launch_builtin(t_process *p)
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William
exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:02:23 by wescande #+# #+# */
/* Updated: 2017/03/07 21:02:46 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:11:02 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -57,6 +57,11 @@ int launch_case(t_process *p)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_case(p));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */
/* Updated: 2017/03/07 21:02:18 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:07:55 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -51,6 +51,11 @@ int launch_for(t_process *p)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_for(p));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/08 03:24:53 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:08:20 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,6 +29,11 @@ int launch_function(t_process *p)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_function(p));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
/* Updated: 2017/03/07 21:03:04 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:07:47 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,6 +38,11 @@ int launch_if(t_process *p)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_if(p));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
/* Updated: 2017/03/08 14:44:57 by jhalford ### ########.fr */
/* Updated: 2017/03/08 15:08:04 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,6 +29,11 @@ int launch_subshell(t_process *p)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_subshell(p));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
/* Updated: 2017/03/08 02:35:09 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:08:13 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -38,6 +38,11 @@ int launch_until(t_process *p)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_until(p));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
/* Updated: 2017/03/07 20:59:40 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:18:36 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -55,6 +55,11 @@ int launch_while(t_process *p)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_while(p));
}
else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:51:22 by jhalford ### ########.fr */
/* Updated: 2017/03/08 14:58:21 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,11 +15,11 @@
int set_process(t_process *p, t_btree *ast)
{
t_exec *exec;
t_cmd *cmd;
// t_cmd *cmd;
int op;
int fds[2];
cmd = &((t_astnode *)ast->item)->data.cmd;
// cmd = &((t_astnode *)ast->item)->data.cmd;
/* process_reset(p); */
exec = &data_singleton()->exec;
op = pop(&exec->op_stack);
@ -38,6 +38,6 @@ int set_process(t_process *p, t_btree *ast)
p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE];
exec->fdin = fds[PIPE_READ];
p->redirs = ft_lstmap(cmd->redir, &redir_copy);
return (set_process_map(p, ast, cmd));
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy);
return (set_process_map(p, ast));
}

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:36:04 by wescande #+# #+# */
/* Updated: 2017/03/08 01:49:48 by ariard ### ########.fr */
/* Updated: 2017/03/08 14:59:25 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_case(t_process *p, t_btree *ast)
{
(void)cmd;
p->data.d_case.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy);
p->data.d_case.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_CASE;

View file

@ -6,23 +6,23 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
/* Updated: 2017/03/08 14:46:10 by jhalford ### ########.fr */
/* Updated: 2017/03/08 15:03:40 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_cmd(t_process *p, t_btree *ast)
{
t_btree *func;
(void)ast;
if (!(p->data.cmd.av = token_to_argv(cmd->token, 1)))
if (!(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1)))
return (1);
p->data.cmd.path = NULL;
p->data.cmd.execf = NULL;
p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]);
p->type = PROCESS_FILE;
if ((func = is_function(p)))
{
p->data.subshell.content = func;
@ -32,24 +32,19 @@ int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd)
p->type = PROCESS_BUILTIN;
else if (ft_strchr(p->data.cmd.av[0], '/'))
{
p->type = PROCESS_FILE;
p->data.cmd.execf = &execve;
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
ft_memdel((void**)&p->data.cmd.stat);
}
else
else if (ft_hash(p))
{
p->type = PROCESS_FILE;
if (ft_hash(p))
p->data.cmd.execf = &execve;
DG("found hash at [%s]", p->data.cmd.path);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
{
p->data.cmd.execf = &execve;
DG("found hash at [%s]", p->data.cmd.path);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
{
ft_memdel((void**)&p->data.cmd.stat);
ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path);
}
ft_memdel((void**)&p->data.cmd.stat);
ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path);
}
}
return (0);

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:05 by wescande #+# #+# */
/* Updated: 2017/03/08 01:50:33 by ariard ### ########.fr */
/* Updated: 2017/03/08 14:59:08 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_for(t_process *p, t_btree *ast)
{
(void)cmd;
p->data.d_for.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy);
p->data.d_for.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_FOR;

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:19:50 by wescande #+# #+# */
/* Updated: 2017/03/08 01:51:09 by ariard ### ########.fr */
/* Updated: 2017/03/08 14:59:17 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_if(t_process *p, t_btree *ast)
{
(void)cmd;
p->data.d_if.condition = btree_map(ast->left, &node_copy);
p->data.d_if.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_IF;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:08:12 by wescande #+# #+# */
/* Updated: 2017/03/08 14:48:02 by jhalford ### ########.fr */
/* Updated: 2017/03/08 14:58:36 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,7 +35,7 @@ t_itof g_setprocessmap[] =
{0, NULL}
};
int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_map(t_process *p, t_btree *ast)
{
int i;
t_astnode *item;
@ -49,7 +49,7 @@ int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd)
{
if (!g_setprocessmap[i].f)
return (1);
return ((*g_setprocessmap[i].f)(p, ast, cmd));
return ((*g_setprocessmap[i].f)(p, ast));
}
return (1);
}

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:02:01 by wescande #+# #+# */
/* Updated: 2017/03/08 11:51:04 by jhalford ### ########.fr */
/* Updated: 2017/03/08 14:59:55 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_subshell(t_process *p, t_btree *ast)
{
(void)cmd;
p->data.subshell.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_SUBSHELL;
return (0);

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:22:24 by wescande #+# #+# */
/* Updated: 2017/03/08 03:06:03 by ariard ### ########.fr */
/* Updated: 2017/03/08 14:59:36 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_until(t_process *p, t_btree *ast)
{
(void)cmd;
p->data.d_while.condition = btree_map(ast->left, &node_copy);
p->data.d_while.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_UNTIL;

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:10 by wescande #+# #+# */
/* Updated: 2017/03/08 01:51:38 by ariard ### ########.fr */
/* Updated: 2017/03/08 14:58:54 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd)
int set_process_while(t_process *p, t_btree *ast)
{
(void)cmd;
p->data.d_while.condition = btree_map(ast->left, &node_copy);
p->data.d_while.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_WHILE;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */
/* Updated: 2017/03/08 02:03:58 by ariard ### ########.fr */
/* Updated: 2017/03/08 15:06:12 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,6 @@ void job_remove(int id)
j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
if (job_is_completed(id))
{
DG();
p = ft_lstlast(j->first_process)->content;
set_exitstatus(p->status, 0);
if (id < data_singleton()->jobc.current_id)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:58:02 by wescande #+# #+# */
/* Updated: 2017/03/08 02:31:01 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:04:45 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,5 +16,7 @@ int process_free_cmd(t_process *p)
{
ft_strdel(&p->data.cmd.path);
ft_sstrfree(p->data.cmd.av);
p->data.cmd.execf = NULL;
ft_memdel((void**)&p->data.cmd.stat);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:38:12 by wescande #+# #+# */
/* Updated: 2017/03/08 02:38:27 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:16:22 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,6 @@
int process_free_subshell(t_process *p)
{
btree_del(&p->data.d_while.content, &ast_free);
btree_del(&p->data.subshell.content, &ast_free);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/08 00:35:38 by wescande ### ########.fr */
/* Updated: 2017/03/08 15:05:31 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,24 +26,16 @@ int put_job_in_foreground(t_job *j, int cont)
if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed");
}
DG();
job_wait(j->id);
DG();
job_remove(j->id);
DG();
tcsetpgrp(STDIN, jobc->shell_pgid);
tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
}
else
{
DG();
job_wait(j->id);
DG();
job_remove(j->id);
DG();
}
return (0);
}