some pb for execution

This commit is contained in:
wescande 2017-03-17 20:45:27 +01:00
parent 76584b9ff7
commit 0fbcf79789
14 changed files with 78 additions and 315 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */ /* Created: 2016/08/03 16:17:21 by jhalford #+# #+# */
/* Updated: 2016/11/03 15:13:04 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:36:22 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,6 +27,8 @@ int ft_atoi(const char *str)
int res; int res;
int sign; int sign;
if (!str || !*str)
return (0);
i = 0; i = 0;
res = 0; res = 0;
sign = 1; sign = 1;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */
/* Updated: 2017/03/16 21:42:35 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:35:24 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,16 +14,6 @@
int plaunch_brace(t_process *p) int plaunch_brace(t_process *p)
{ {
DG(" do brace"); ft_exec(&p->data.brace.content);
if (IS_PIPESINGLE(*p)) return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
{
DG("is pipgesingle");
if (process_redirect(p))
set_exitstatus(1, 1);
else
ft_exec(&p->data.brace.content);
return (0);
}
else
return (plaunch_subshell(p));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
/* Updated: 2017/03/14 22:34:53 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:22:12 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,32 +14,8 @@
int plaunch_builtin(t_process *p) int plaunch_builtin(t_process *p)
{ {
pid_t pid; return ((*p->data.cmd.execf)(
p->data.cmd.path,
if (IS_PIPESINGLE(*p)) p->data.cmd.av,
{ data_singleton()->env));
if (process_redirect(p))
{
set_exitstatus(1, 1);
return (0);
}
set_exitstatus((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env), 1);
return (0);
}
pid = fork();
if (pid == 0)
{
if (process_redirect(p))
exit (1);
process_setgroup(p, 0);
process_setsig();
exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William
// je pense ca ne change rien si on l'enleve car on excve apres
exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env));
}
else if (pid > 0)
return (pid);
else if (pid == -1)
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
return (0);
} }

View file

@ -6,13 +6,13 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */
/* Updated: 2017/03/15 01:10:32 by ariard ### ########.fr */ /* Updated: 2017/03/17 20:17:07 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int do_case(t_process *p) int plaunch_case(t_process *p)
{ {
t_exec *exec; t_exec *exec;
@ -23,29 +23,3 @@ static int do_case(t_process *p)
ft_exec(&p->data.d_if.content); ft_exec(&p->data.d_if.content);
return (0); return (0);
} }
int plaunch_case(t_process *p)
{
pid_t pid;
if (SH_IS_INTERACTIVE(data_singleton()->opts))
{
pid = fork();
if (pid == 0)
{
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)
return (pid);
}
else
do_case(p);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */ /* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */
/* Updated: 2017/03/13 20:29:43 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:23:18 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,23 +14,7 @@
int plaunch_empty(t_process *p) int plaunch_empty(t_process *p)
{ {
int pid; (void)p;
pid = fork();
if (pid == 0)
{
if (process_redirect(p))
exit (1);
process_setgroup(p, 0);
process_setsig();
exec_reset();
DG("empty exit");
exit(0);
}
else if (pid > 0)
return (pid);
else if (pid == -1)
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
/* Updated: 2017/03/15 23:11:53 by wescande ### ########.fr */ /* Updated: 2017/03/17 20:22:38 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,34 +20,18 @@ static void error_launch(char *error_ori, char *error_type, int error_code)
int plaunch_file(t_process *p) int plaunch_file(t_process *p)
{ {
int pid; if (!p->data.cmd.path)
error_launch("command not found: ", p->data.cmd.av[0], 127);
DG("plaunch_file"); else if (!p->data.cmd.stat)
pid = fork(); error_launch(p->data.cmd.av[0], ": no such file or directory", 127);
if (pid == 0) else if (S_ISDIR(p->data.cmd.stat->st_mode))
{ error_launch(p->data.cmd.av[0], ": is a directory", 126);
/* data_singleton()->opts &= ~SH_INTERACTIVE; */ else if (access(p->data.cmd.path, X_OK) == -1)
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */ error_launch("permission denied: ", p->data.cmd.av[0], 126);
DG("fork! [%s]", p->data.cmd.av[0]); (*p->data.cmd.execf)(
if (process_redirect(p)) p->data.cmd.path,
exit (1); p->data.cmd.av,
process_setgroup(p, 0); data_singleton()->env);
process_setsig(); error_launch("internal execve error on ", p->data.cmd.av[0], 42);
exec_reset();
if (!p->data.cmd.path)
error_launch("command not found: ", p->data.cmd.av[0], 127);
else if (!p->data.cmd.stat)
error_launch(p->data.cmd.av[0], ": no such file or directory", 127);
else if (S_ISDIR(p->data.cmd.stat->st_mode))
error_launch(p->data.cmd.av[0], ": is a directory", 126);
else if (access(p->data.cmd.path, X_OK) == -1)
error_launch("permission denied: ", p->data.cmd.av[0], 126);
(*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env);
error_launch("internal execve error on ", p->data.cmd.av[0], 42);
}
else if (pid > 0)
return (pid);
else if (pid == -1)
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
return (0); return (0);
} }

View file

@ -6,13 +6,13 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ /* Created: 2017/03/15 00:49:20 by wescande #+# #+# */
/* Updated: 2017/03/15 23:10:25 by wescande ### ########.fr */ /* Updated: 2017/03/17 20:16:46 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int do_for(t_process *p) int plaunch_for(t_process *p)
{ {
t_ld *temp; t_ld *temp;
int i; int i;
@ -38,29 +38,3 @@ static int do_for(t_process *p)
} }
return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
} }
int plaunch_for(t_process *p)
{
pid_t pid;
if (SH_IS_INTERACTIVE(data_singleton()->opts))
{
pid = fork();
if (pid == 0)
{
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)
return (pid);
}
else
do_for(p);
return (0);
}

View file

@ -6,41 +6,15 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/15 19:17:01 by ariard ### ########.fr */ /* Updated: 2017/03/17 20:29:36 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int do_function(t_process *p) int plaunch_function(t_process *p)
{ {
DG("do function"); DG("do function");
ft_exec(&p->data.function.content); ft_exec(&p->data.function.content);
return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
} }
int plaunch_function(t_process *p)
{
pid_t pid;
if (SH_IS_INTERACTIVE(data_singleton()->opts))
{
pid = fork();
if (pid == 0)
{
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)
return (pid);
}
else
do_function(p);
return (0);
}

View file

@ -6,44 +6,15 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
/* Updated: 2017/03/15 02:04:23 by ariard ### ########.fr */ /* Updated: 2017/03/17 20:30:36 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int do_if(t_process *p) int plaunch_if(t_process *p)
{ {
t_exec *exec; data_singleton()->exec.attrs &= ~EXEC_IF_BRANCH;
exec = &data_singleton()->exec;
exec->attrs &= ~EXEC_IF_BRANCH;
ft_exec(&p->data.d_if.content); ft_exec(&p->data.d_if.content);
return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
} }
int plaunch_if(t_process *p)
{
pid_t pid;
if (SH_IS_INTERACTIVE(data_singleton()->opts))
{
pid = fork();
if (pid == 0)
{
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)
return (pid);
}
else
do_if(p);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
/* Updated: 2017/03/14 00:00:26 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:28:08 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,24 +14,6 @@
int plaunch_subshell(t_process *p) int plaunch_subshell(t_process *p)
{ {
pid_t pid; ft_exec(&p->data.subshell.content);
exit(ft_atoi(ft_getenv(data_singleton()->env, "?")));
pid = fork();
if (pid == 0)
{
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
if (process_redirect(p))
exit (1);
process_setgroup(p, 0);
process_setsig();
exec_reset();
ft_exec(&p->data.subshell.content);
exit(ft_atoi(ft_getenv(data_singleton()->env, "?")));
}
else if (pid > 0)
return (pid);
else if (pid == -1)
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
return (0);
} }

View file

@ -6,13 +6,13 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:20:04 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int do_until(t_process *p) int plaunch_until(t_process *p)
{ {
int ret; int ret;
@ -26,29 +26,3 @@ static int do_until(t_process *p)
} }
return (ret); return (ret);
} }
int plaunch_until(t_process *p)
{
pid_t pid;
if (SH_IS_INTERACTIVE(data_singleton()->opts))
{
pid = fork();
if (pid == 0)
{
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)
return (pid);
}
else
do_until(p);
return (0);
}

View file

@ -6,13 +6,13 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
/* Updated: 2017/03/16 18:44:00 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:16:10 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int do_while(t_process *p) int plaunch_while(t_process *p)
{ {
int ret; int ret;
@ -26,29 +26,3 @@ static int do_while(t_process *p)
} }
return (ret); return (ret);
} }
int plaunch_while(t_process *p)
{
pid_t pid;
if (SH_IS_INTERACTIVE(data_singleton()->opts))
{
pid = fork();
if (pid == 0)
{
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)
return (pid);
}
else
do_while(p);
return (0);
}

View file

@ -6,59 +6,63 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
/* Updated: 2017/03/16 20:08:57 by jhalford ### ########.fr */ /* Updated: 2017/03/17 20:31:20 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int check_pipe(t_process *p)
int do_the_muther_forker(t_process *p)
{ {
pid_t pid; pid_t pid;
if (p->map.launch == plaunch_file) if (IS_PIPESINGLE(*p) && p->type != PROCESS_FILE && p->type != PROCESS_SUBSHELL)
return (0);
if (IS_PIPESINGLE(*p))
{ {
/* if (process_redirect(p)) if (process_redirect(p))
{ {
set_exitstatus(1, 1); set_exitstatus(1, 1);
return (0); return (0);
} }
set_exitstatus((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env), 1);*/ set_exitstatus(p->map.launch(p), 1);
return (0); return (0);
} }
pid = fork(); if ((pid = fork()) == -1)
if (!pid)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; ft_dprintf(3, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
data_singleton()->opts &= ~SH_OPTS_JOBC; exit(1);
if (process_redirect(p))
exit (1);
process_setgroup(p, 0);
process_setsig();
exec_reset();
} }
return (pid); else if (pid)
return (pid);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTSTP, SIG_DFL);
signal(SIGTTIN, SIG_DFL);
signal(SIGTTOU, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
if (process_redirect(p))
exit (1);
process_setgroup(p, 0);
process_setsig();
exec_reset();
exit(p->map.launch(p));
} }
int process_launch(t_process *p) int process_launch(t_process *p)
{ {
pid_t pid; pid_t pid;
/* pid_t manage_pid; */
DG("p->type=%i", p->type); DG("p->type=%i", p->type);
p->attrs &= ~PROCESS_STATE_MASK; p->attrs &= ~PROCESS_STATE_MASK;
p->attrs |= PROCESS_RUNNING; p->attrs |= PROCESS_RUNNING;
/* if (!(manage_pid = check_pipe(p))) */ if (!(pid = do_the_muther_forker(p)))
if (!(pid = (*p->map.launch)(p))) {
{ DG("launcher did not fork!");
DG("launcher did not fork!"); process_resetfds(p);
process_resetfds(p); return (1);
return (1); }
}
/* if (manage_pid) */
/* pid = manage_pid; */
DG("launcher forked!"); DG("launcher forked!");
p->pid = pid; p->pid = pid;
process_setgroup(p, pid); process_setgroup(p, pid);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/16 23:25:29 by ariard ### ########.fr */ /* Updated: 2017/03/17 19:57:55 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -63,12 +63,12 @@ static int interactive_settings(void)
shell_pgid = &data->jobc.shell_pgid; shell_pgid = &data->jobc.shell_pgid;
while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp())) while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp()))
kill(-*shell_pgid, SIGTTIN); kill(-*shell_pgid, SIGTTIN);
signal(SIGINT, sigint_handler); signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN); signal(SIGQUIT, SIG_IGN);
signal(SIGTSTP, sigtstp_handler); signal(SIGTSTP, SIG_IGN);
signal(SIGTTIN, SIG_IGN); signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN); signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, SIG_IGN);
*shell_pgid = getpid(); *shell_pgid = getpid();
if (setpgid(*shell_pgid, *shell_pgid)) if (setpgid(*shell_pgid, *shell_pgid))
{ {