merging
This commit is contained in:
commit
7195207116
28 changed files with 247 additions and 143 deletions
|
|
@ -78,6 +78,7 @@ exec/exec_semi.c\
|
|||
exec/exec_until.c\
|
||||
exec/exec_var.c\
|
||||
exec/exec_while.c\
|
||||
exec/exec_math.c\
|
||||
exec/fd_is_valid.c\
|
||||
exec/ft_exec.c\
|
||||
exec/ft_findexec.c\
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 14:41:58 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:17:21 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,19 +16,12 @@
|
|||
# define PIPE_READ 0
|
||||
# define PIPE_WRITE 1
|
||||
|
||||
# define PROCESS_BUILTIN (1 << 0)
|
||||
# define PROCESS_BINARY (1 << 1)
|
||||
# define PROCESS_SCRIPT (1 << 2)
|
||||
# define PROCESS_SUBSHELL (1 << 3)
|
||||
# define PROCESS_UNKNOWN (1 << 4)
|
||||
# define PROCESS_CONTROL (1 << 5)
|
||||
# define PROCESS_COMPLETED (1 << 6)
|
||||
# define PROCESS_SUSPENDED (1 << 7)
|
||||
# define PROCESS_RUNNING (1 << 8)
|
||||
# define PROCESS_CONTINUED (1 << 9)
|
||||
# define PROCESS_COMPLETED (1 << 0)
|
||||
# define PROCESS_SUSPENDED (1 << 1)
|
||||
# define PROCESS_RUNNING (1 << 2)
|
||||
# define PROCESS_CONTINUED (1 << 3)
|
||||
|
||||
# define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5)
|
||||
# define PROCESS_STATE_MASK (1 << 6 | 1 << 7 | 1 << 8 | 1 << 9)
|
||||
# define PROCESS_STATE_MASK ((1 << 4) - (1 << 0))
|
||||
|
||||
# define IS_PIPESTART(p) ((p).fdin == STDIN)
|
||||
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
||||
|
|
@ -39,18 +32,20 @@
|
|||
# define EXEC_OR_IF (1 << 3)
|
||||
# define EXEC_IF_BRANCH (1 << 4)
|
||||
# define EXEC_CASE_BRANCH (1 << 5)
|
||||
|
||||
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
||||
|
||||
# define EXEC_IS_BG(j) (j & EXEC_BG)
|
||||
# define EXEC_IS_FG(j) (!EXEC_IS_BG(j))
|
||||
# define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF)
|
||||
# define EXEC_IS_OR_IF(j) (j & EXEC_OR_IF)
|
||||
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
||||
|
||||
# define EXEC_IS_IF_BRANCH(j) (j & EXEC_IF_BRANCH)
|
||||
# define EXEC_IS_CASE_BRANCH(j) (j & EXEC_CASE_BRANCH)
|
||||
|
||||
# include "../libft/includes/libft.h"
|
||||
# include "types.h"
|
||||
# include "job_control.h"
|
||||
# include "minishell.h"
|
||||
|
||||
struct s_data_cmd
|
||||
{
|
||||
|
|
@ -83,32 +78,34 @@ union u_process_data
|
|||
// struct s_data_cond case;
|
||||
};
|
||||
|
||||
typedef union u_process_data t_pdata;
|
||||
enum e_process_type
|
||||
{
|
||||
PROCESS_FUNCTION,
|
||||
PROCESS_BUILTIN,
|
||||
PROCESS_FILE,
|
||||
PROCESS_SUBSHELL,
|
||||
PROCESS_WHILE,
|
||||
PROCESS_IF,
|
||||
PROCESS_FOR,
|
||||
PROCESS_CASE,
|
||||
};
|
||||
|
||||
typedef enum e_process_type t_process_type;
|
||||
typedef union u_process_data t_process_data;
|
||||
typedef struct s_data_cond t_data_while;
|
||||
typedef struct s_data_cond t_data_if;
|
||||
|
||||
struct s_process
|
||||
{
|
||||
//normal_cmd
|
||||
// char **av;
|
||||
// char *path;
|
||||
// t_execf *execf;
|
||||
//while, if, elif ....
|
||||
// t_btree *condition;
|
||||
// t_btree *content;
|
||||
//for => utilisation du av et du content
|
||||
// char **av;
|
||||
// t_btree *content;
|
||||
|
||||
|
||||
t_pdata data;
|
||||
|
||||
pid_t pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int to_close;
|
||||
t_list *redirs;
|
||||
int status;
|
||||
t_flag attrs;
|
||||
t_process_type type;
|
||||
t_process_data data;
|
||||
pid_t pid;
|
||||
int fdin;
|
||||
int fdout;
|
||||
int to_close;
|
||||
t_list *redirs;
|
||||
int status;
|
||||
t_flag attrs;
|
||||
};
|
||||
|
||||
struct s_exec
|
||||
|
|
@ -122,22 +119,10 @@ struct s_exec
|
|||
int control_count;
|
||||
};
|
||||
|
||||
struct s_execmap
|
||||
{
|
||||
t_type type;
|
||||
int (*f)(t_btree **ast);
|
||||
};
|
||||
|
||||
struct s_redirmap
|
||||
{
|
||||
t_flag type;
|
||||
int (*f)(t_redir *redir);
|
||||
};
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
extern t_execmap g_execmap[];
|
||||
extern t_redirmap g_redirmap[];
|
||||
extern t_itof g_execmap[];
|
||||
extern t_itof g_redirmap[];
|
||||
extern t_itof g_launchmap[];
|
||||
|
||||
int ft_exec(t_btree **ast);
|
||||
|
||||
|
|
@ -161,6 +146,7 @@ int exec_var(t_btree **ast);
|
|||
int exec_for(t_btree **ast);
|
||||
int exec_case(t_btree **ast);
|
||||
int exec_case_branch(t_btree **ast);
|
||||
int exec_math(t_btree **ast);
|
||||
|
||||
int launch_process(t_process *p);
|
||||
int set_process(t_process *p, t_btree *ast);
|
||||
|
|
@ -171,7 +157,7 @@ void process_free(void *content, size_t content_size);
|
|||
void process_reset(t_process *p);
|
||||
void process_resetfds(void);
|
||||
|
||||
int fd_is_valid(int fd);
|
||||
int fd_is_valid(int fd, int flag);
|
||||
int bad_fd(int fd);
|
||||
int process_redirect(t_process *p);
|
||||
int redirect_great(t_redir *redir);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/04 16:46:52 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 14:27:40 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/06 17:51:59 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:08:17 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit a966b8a20028daba5580237fa0b0b18e16208f1b
|
||||
Subproject commit bc489f8664fdc24317c31b3069811f54b1178643
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/03 15:58:41 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/07 11:27:49 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/03 16:07:30 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/07 11:29:18 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/17 13:18:25 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/03/07 11:28:05 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 14:39:17 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:17:32 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 15:03:54 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:17:47 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
77
42sh/src/exec/exec_math.c
Normal file
77
42sh/src/exec/exec_math.c
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_math.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 13:42:11 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
static int get_math(char *stream, char **var, char **value, char **operator)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
*var = ft_strduptr(stream, &ft_isalpha);
|
||||
temp = ft_sstrstr(data_singleton()->env, *var);
|
||||
if (temp)
|
||||
{
|
||||
temp += ft_strlenchr(temp, '=') + 1;
|
||||
*value = ft_strdup(temp);
|
||||
if (!(ft_stris(*value, &ft_isdigit)))
|
||||
{
|
||||
ft_strdel(value);
|
||||
*value = ft_itoa(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
*value = ft_itoa(0);
|
||||
stream += ft_strlen(*var);
|
||||
*operator = ft_strdup(stream);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int do_math(char **value, char *operator)
|
||||
{
|
||||
long ope1;
|
||||
long ope2;
|
||||
|
||||
ope1 = ft_atoi(*value);
|
||||
if (operator[2])
|
||||
ope2 = ft_atoi(&operator[2]);
|
||||
else
|
||||
ope2 = 0;
|
||||
if (operator[0] == '/' && ope2 == 0)
|
||||
ope1 = 0;
|
||||
else
|
||||
{
|
||||
ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1;
|
||||
ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1;
|
||||
ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1;
|
||||
ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1;
|
||||
ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1;
|
||||
}
|
||||
ft_strdel(value);
|
||||
*value = ft_itoa(ope1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int exec_math(t_btree **ast)
|
||||
{
|
||||
t_astnode *node;
|
||||
char **av;
|
||||
char *var;
|
||||
char *value;
|
||||
char *operator;
|
||||
|
||||
node = (*ast)->item;
|
||||
av = token_to_argv(node->data.cmd.wordlist, 1);
|
||||
get_math(av[0], &var, &value, &operator);
|
||||
do_math(&value, operator);
|
||||
builtin_setenv("setenv", (char *[]){var, value, 0}, data_singleton()->local_var);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* exec_while.c :+: :+: :+: */
|
||||
/* exec_var.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 12:17:43 by wescande ### ########.fr */
|
||||
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/07 14:40:30 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,12 +14,9 @@
|
|||
|
||||
static int set_var(char *stream, char **var, char **value)
|
||||
{
|
||||
(void)stream;
|
||||
(void)var;
|
||||
(void)value;
|
||||
/* *var = ft_strdupchr(stream, '=');
|
||||
*var = ft_strdupchr(stream, '=');
|
||||
stream += ft_strlenchr(stream, '=') + 1;
|
||||
value = ft_strdup(stream);*/
|
||||
*value = ft_strdup(stream);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,16 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/03 13:46:40 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 19:44:16 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 16:58:38 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int fd_is_valid(int fd)
|
||||
int fd_is_valid(int fd, int has_flag)
|
||||
{
|
||||
return (fcntl(fd, F_GETFD) != -1 || errno != EBADF);
|
||||
int flags;
|
||||
|
||||
flags = fcntl(fd, F_GETFD);
|
||||
return ((flags != -1 || errno != EBADF) && flags & has_flag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 14:33:06 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:18:27 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec.h"
|
||||
|
||||
t_execmap g_execmap[] =
|
||||
t_itof g_execmap[] =
|
||||
{
|
||||
{TK_NEWLINE, &exec_semi},
|
||||
{TK_SEMI, &exec_semi},
|
||||
|
|
@ -29,6 +29,7 @@ t_execmap g_execmap[] =
|
|||
{TK_CASE, &exec_case},
|
||||
{TK_PAREN_OPEN, &exec_case_branch},
|
||||
{TK_ASSIGNEMENT_WORD, &exec_var},
|
||||
{MATH, &exec_math},
|
||||
/* {TK_SUBSHELL, &exec_}, */
|
||||
{CMD, &exec_cmd},
|
||||
{0, 0},
|
||||
|
|
|
|||
59
42sh/src/exec/launch_file.c
Normal file
59
42sh/src/exec/launch_file.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* launch_file.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 14:54:18 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int launch_file(t_process *p)
|
||||
{
|
||||
int pid;
|
||||
|
||||
if (p->attrs & PROCESS_BUILTIN && IS_PIPESINGLE(*p))
|
||||
{
|
||||
if (process_redirect(p))
|
||||
return (1);
|
||||
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1);
|
||||
return (1);
|
||||
}
|
||||
p->attrs &= ~PROCESS_STATE_MASK;
|
||||
p->attrs |= PROCESS_RUNNING;
|
||||
if (p->attrs & (PROCESS_BINARY | PROCESS_SCRIPT)
|
||||
&& access(p->path, X_OK) == -1)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||
set_exitstatus(126, 1);
|
||||
return (1);
|
||||
}
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
if (p->attrs & PROCESS_UNKNOWN)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||
exit(127);
|
||||
}
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
if (p->attrs & PROCESS_BUILTIN)
|
||||
exit((*p->execf)(p->path, p->av, data_singleton()->env));
|
||||
(*p->execf)(p->path, p->av, data_singleton()->env);
|
||||
ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||
}
|
||||
else if (pid > 0)
|
||||
{
|
||||
p->pid = pid;
|
||||
process_setgroup(p, pid);
|
||||
return (0);
|
||||
}
|
||||
else if (pid == -1)
|
||||
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
|
||||
return (1);
|
||||
}
|
||||
|
|
@ -6,59 +6,36 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 14:43:48 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:19:05 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
t_itof g_launchmap[] =
|
||||
{
|
||||
{PROCESS_FUNCTION, NULL},
|
||||
{PROCESS_BUILTIN, NULL},
|
||||
{PROCESS_FILE, launch_file},
|
||||
{PROCESS_SUBSHELL, NULL},
|
||||
{PROCESS_WHILE, NULL},
|
||||
{PROCESS_IF, NULL},
|
||||
{PROCESS_FOR, NULL},
|
||||
{PROCESS_CASE, NULL},
|
||||
};
|
||||
|
||||
int launch_process(t_process *p)
|
||||
{
|
||||
int pid;
|
||||
int i;
|
||||
|
||||
/* DG("gonna launch [%s]", p->av[0]); */
|
||||
/* DG("fdin=[%i]", p->fdin); */
|
||||
/* DG("fdout=[%i]", p->fdout); */
|
||||
if (p->attrs & PROCESS_BUILTIN && IS_PIPESINGLE(*p))
|
||||
i = 0;
|
||||
while (g_launchmap[i].type)
|
||||
{
|
||||
if (process_redirect(p))
|
||||
return (1);
|
||||
set_exitstatus((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env), 1);
|
||||
return (1);
|
||||
if (p->type == g_launchmap[i].type)
|
||||
if (!g_launchmap[i].f)
|
||||
return (-1);
|
||||
return ((*g_launchmap[i].f)(p));
|
||||
i++;
|
||||
}
|
||||
p->attrs &= ~PROCESS_STATE_MASK;
|
||||
p->attrs |= PROCESS_RUNNING;
|
||||
if (p->attrs & (PROCESS_BINARY | PROCESS_SCRIPT)
|
||||
&& 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]);
|
||||
set_exitstatus(126, 1);
|
||||
return (1);
|
||||
}
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
if (p->attrs & PROCESS_UNKNOWN)
|
||||
{
|
||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||
exit(127);
|
||||
}
|
||||
process_setgroup(p, 0);
|
||||
process_setsig();
|
||||
if (process_redirect(p))
|
||||
exit (1);
|
||||
if (p->attrs & PROCESS_BUILTIN)
|
||||
exit((*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]);
|
||||
}
|
||||
else if (pid > 0)
|
||||
{
|
||||
p->pid = pid;
|
||||
process_setgroup(p, pid);
|
||||
return (0);
|
||||
}
|
||||
else if (pid == -1)
|
||||
ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME);
|
||||
return (1);
|
||||
return (-1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 14:42:01 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:34:12 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,23 +15,25 @@
|
|||
int process_setexec(t_process *p)
|
||||
{
|
||||
p->data.cmd.path = NULL;
|
||||
/* if ((p->execf = is_function(p))) */
|
||||
/* p->type = PROCESS_FUNCTION; */
|
||||
if ((p->data.cmd.execf = is_builtin(p)))
|
||||
p->attrs |= PROCESS_BUILTIN;
|
||||
else if (ft_strchr(p->data.cmd.av[0], '/'))
|
||||
{
|
||||
p->data.cmd.execf = &execve;
|
||||
p->attrs |= PROCESS_SCRIPT;
|
||||
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
|
||||
}
|
||||
p->type = PROCESS_BUILTIN;
|
||||
else if (ft_hash(p))
|
||||
{
|
||||
p->data.cmd.execf = &execve;
|
||||
p->attrs |= PROCESS_BINARY;
|
||||
p->type = PROCESS_FILE;
|
||||
}
|
||||
else if (ft_strchr(p->data.cmd.av[0], '/'))
|
||||
{
|
||||
p->data.cmd.execf = &execve;
|
||||
p->type = PROCESS_FILE;
|
||||
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
p->data.cmd.execf = NULL;
|
||||
p->attrs |= PROCESS_UNKNOWN;
|
||||
// p->attrs |= PROCESS_UNKNOWN;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 19:44:10 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 16:54:43 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ int redirect_greatand(t_redir *redir)
|
|||
return (0);
|
||||
if (fdold > 9)
|
||||
return (bad_fd(fdold));
|
||||
if (fd_is_valid(fdold))
|
||||
if (fd_is_valid(fdold, O_RDONLY))
|
||||
dup2_close(fdold, fdnew);
|
||||
else
|
||||
return (bad_fd(fdold));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 19:43:42 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 16:53:29 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ int redirect_lessand(t_redir *redir)
|
|||
return (0);
|
||||
if (fdold > 9)
|
||||
return (bad_fd(fdold));
|
||||
if (fd_is_valid(fdold))
|
||||
if (fd_is_valid(fdold, O_WRONLY))
|
||||
dup2_close(fdold, fdnew);
|
||||
else
|
||||
return (bad_fd(fdold));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/07 15:07:44 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:34:31 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/18 11:20:11 by gwojda #+# #+# */
|
||||
/* Updated: 2017/03/07 14:44:52 by wescande ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:34:57 by wescande ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/06 17:58:39 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:09:53 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */
|
||||
/* Updated: 2017/03/05 17:45:37 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/03/06 16:52:34 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/04 20:42:13 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/06 19:36:37 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 11:52:45 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -90,6 +90,7 @@ int add_pattern(t_btree **ast, t_list **lst)
|
|||
t_token *token;
|
||||
char **my_tab;
|
||||
|
||||
DG("add pattern");
|
||||
token = (*lst)->content;
|
||||
node = (*ast)->item;
|
||||
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 14:27:25 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 10:49:15 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ int add_one_func(t_btree **ast, t_list **lst)
|
|||
t_btree *func_ast;
|
||||
|
||||
(void)lst;
|
||||
func_ast = btree_map(*ast, &id);
|
||||
// func_ast = btree_map(*ast, &id);
|
||||
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
|
||||
DG("arbre ajoute");
|
||||
return (0);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/03/03 15:08:16 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/03 16:17:27 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 14:40:21 by ariard ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ t_stackmatch g_stackmatch[] =
|
|||
{TK_GREATAND, NEWLINE_LIST},
|
||||
{TK_GREATAND, PIPE_SEMI_SEQUENCE},
|
||||
{TK_GREATAND, SEQUENCE},
|
||||
// watch !
|
||||
// watch !
|
||||
{TK_GREATAND, CMD_SUPERIOR},
|
||||
{TK_GREATAND, AND_OR_MAJOR},
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||
/* Updated: 2017/03/06 16:43:10 by ariard ### ########.fr */
|
||||
/* Updated: 2017/03/07 15:09:59 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue