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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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 pid;
|
||||
|
|
@ -29,28 +35,15 @@ int plaunch_file(t_process *p)
|
|||
process_setsig();
|
||||
exec_reset();
|
||||
if (!p->data.cmd.path)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(127);
|
||||
}
|
||||
error_launch("command not found: ", p->data.cmd.av[0], 127);
|
||||
else if (!p->data.cmd.stat)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: %s: no such file or directory\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(127);
|
||||
}
|
||||
error_launch(p->data.cmd.av[0], ": no such file or directory", 127);
|
||||
else if (S_ISDIR(p->data.cmd.stat->st_mode))
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: %s: is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(126);
|
||||
}
|
||||
error_launch(p->data.cmd.av[0], ": is a directory", 126);
|
||||
else if (access(p->data.cmd.path, X_OK) == -1)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(126);
|
||||
}
|
||||
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);
|
||||
ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(42);
|
||||
error_launch("internal execve error on ", p->data.cmd.av[0], 42);
|
||||
}
|
||||
else if (pid > 0)
|
||||
return (pid);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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];
|
||||
if (!word_is_assignment(temp->content))
|
||||
return (error_badidentifier(var));
|
||||
DG();
|
||||
temp = temp->next;
|
||||
while (temp)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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}, */
|
||||
/* }; */
|
||||
|
||||
|
||||
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 pid;
|
||||
pid_t pid;
|
||||
pid_t manage_pid;
|
||||
|
||||
DG("p->type=%i", p->type);
|
||||
/* if (p->type >= PROCESS_MAX) */
|
||||
|
|
@ -38,12 +70,15 @@ int process_launch(t_process *p)
|
|||
/* return (-1); */
|
||||
p->attrs &= ~PROCESS_STATE_MASK;
|
||||
p->attrs |= PROCESS_RUNNING;
|
||||
if (!(manage_pid = check_pipe(p)))
|
||||
if (!(pid = (*p->map.launch)(p)))
|
||||
{
|
||||
DG("launcher did not fork!");
|
||||
process_resetfds(p);
|
||||
return (1);
|
||||
}
|
||||
if (manage_pid)
|
||||
pid = manage_pid;
|
||||
DG("launcher forked!");
|
||||
p->pid = pid;
|
||||
process_setgroup(p, pid);
|
||||
|
|
|
|||
Loading…
Reference in a new issue