some norme + debut de correction des var dans script
This commit is contained in:
parent
0d60e7a410
commit
21f5b377d9
3 changed files with 57 additions and 30 deletions
|
|
@ -6,12 +6,18 @@
|
||||||
/* 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/14 23:30:54 by jhalford ### ########.fr */
|
/* Updated: 2017/03/15 23:11:53 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static void error_launch(char *error_ori, char *error_type, int error_code)
|
||||||
|
{
|
||||||
|
ft_dprintf(2, "{red}%s: %s%s{eoc}\n", SHELL_NAME, error_ori, error_type);
|
||||||
|
exit(error_code);
|
||||||
|
}
|
||||||
|
|
||||||
int plaunch_file(t_process *p)
|
int plaunch_file(t_process *p)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
|
@ -29,28 +35,15 @@ int plaunch_file(t_process *p)
|
||||||
process_setsig();
|
process_setsig();
|
||||||
exec_reset();
|
exec_reset();
|
||||||
if (!p->data.cmd.path)
|
if (!p->data.cmd.path)
|
||||||
{
|
error_launch("command not found: ", p->data.cmd.av[0], 127);
|
||||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
|
||||||
exit(127);
|
|
||||||
}
|
|
||||||
else if (!p->data.cmd.stat)
|
else if (!p->data.cmd.stat)
|
||||||
{
|
error_launch(p->data.cmd.av[0], ": no such file or directory", 127);
|
||||||
ft_dprintf(2, "{red}%s: %s: no such file or directory\n", SHELL_NAME, p->data.cmd.av[0]);
|
|
||||||
exit(127);
|
|
||||||
}
|
|
||||||
else if (S_ISDIR(p->data.cmd.stat->st_mode))
|
else if (S_ISDIR(p->data.cmd.stat->st_mode))
|
||||||
{
|
error_launch(p->data.cmd.av[0], ": is a directory", 126);
|
||||||
ft_dprintf(2, "{red}%s: %s: is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
|
||||||
exit(126);
|
|
||||||
}
|
|
||||||
else if (access(p->data.cmd.path, X_OK) == -1)
|
else if (access(p->data.cmd.path, X_OK) == -1)
|
||||||
{
|
error_launch("permission denied: ", p->data.cmd.av[0], 126);
|
||||||
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
|
||||||
exit(126);
|
|
||||||
}
|
|
||||||
(*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env);
|
(*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env);
|
||||||
ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
error_launch("internal execve error on ", p->data.cmd.av[0], 42);
|
||||||
exit(42);
|
|
||||||
}
|
}
|
||||||
else if (pid > 0)
|
else if (pid > 0)
|
||||||
return (pid);
|
return (pid);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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 03:51:52 by wescande ### ########.fr */
|
/* Updated: 2017/03/15 23:10:25 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,7 +23,6 @@ static int do_for(t_process *p)
|
||||||
var = ((char **)temp->content)[0];
|
var = ((char **)temp->content)[0];
|
||||||
if (!word_is_assignment(temp->content))
|
if (!word_is_assignment(temp->content))
|
||||||
return (error_badidentifier(var));
|
return (error_badidentifier(var));
|
||||||
DG();
|
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
while (temp)
|
while (temp)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* 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/15 01:52:43 by ariard ### ########.fr */
|
/* Updated: 2017/03/15 23:52:30 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,9 +27,41 @@
|
||||||
/* {PROCESS_EMPTY, launch_empty}, */
|
/* {PROCESS_EMPTY, launch_empty}, */
|
||||||
/* }; */
|
/* }; */
|
||||||
|
|
||||||
|
|
||||||
|
int check_pipe(t_process *p)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
|
if (p->map.launch == plaunch_file)
|
||||||
|
return (0);
|
||||||
|
if (IS_PIPESINGLE(*p))
|
||||||
|
{
|
||||||
|
/* 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)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
return (pid);
|
||||||
|
}
|
||||||
|
|
||||||
int process_launch(t_process *p)
|
int process_launch(t_process *p)
|
||||||
{
|
{
|
||||||
int pid;
|
pid_t pid;
|
||||||
|
pid_t manage_pid;
|
||||||
|
|
||||||
DG("p->type=%i", p->type);
|
DG("p->type=%i", p->type);
|
||||||
/* if (p->type >= PROCESS_MAX) */
|
/* if (p->type >= PROCESS_MAX) */
|
||||||
|
|
@ -38,12 +70,15 @@ int process_launch(t_process *p)
|
||||||
/* return (-1); */
|
/* return (-1); */
|
||||||
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 = (*p->map.launch)(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);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue