it compiles ! much more testing for simple commands to work
This commit is contained in:
parent
3857b06785
commit
418859e9e8
32 changed files with 190 additions and 196 deletions
|
|
@ -71,7 +71,6 @@ exec/exec_else.c\
|
||||||
exec/exec_for.c\
|
exec/exec_for.c\
|
||||||
exec/exec_func.c\
|
exec/exec_func.c\
|
||||||
exec/exec_if.c\
|
exec/exec_if.c\
|
||||||
exec/exec_less.c\
|
|
||||||
exec/exec_or_if.c\
|
exec/exec_or_if.c\
|
||||||
exec/exec_pipe.c\
|
exec/exec_pipe.c\
|
||||||
exec/exec_semi.c\
|
exec/exec_semi.c\
|
||||||
|
|
@ -135,11 +134,11 @@ history/history_parsing_toolz.c\
|
||||||
history/history_parsing_toolz_2.c\
|
history/history_parsing_toolz_2.c\
|
||||||
history/list_toolz.c\
|
history/list_toolz.c\
|
||||||
history/surch_in_history.c\
|
history/surch_in_history.c\
|
||||||
|
job-control/add_new_job.c\
|
||||||
job-control/builtin_bg.c\
|
job-control/builtin_bg.c\
|
||||||
job-control/builtin_fg.c\
|
job-control/builtin_fg.c\
|
||||||
job-control/builtin_jobs.c\
|
job-control/builtin_jobs.c\
|
||||||
job-control/do_job_notification.c\
|
job-control/do_job_notification.c\
|
||||||
job-control/job_addprocess.c\
|
|
||||||
job-control/job_cmp_id.c\
|
job-control/job_cmp_id.c\
|
||||||
job-control/job_format.c\
|
job-control/job_format.c\
|
||||||
job-control/job_format_head.c\
|
job-control/job_format_head.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:02:14 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:39:06 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -29,18 +29,23 @@
|
||||||
# define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4)
|
# define PROCESS_TYPE_MASK (1 << 0 | 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4)
|
||||||
# define PROCESS_STATE_MASK (1 << 5 | 1 << 6 | 1 << 7 | 1 << 8)
|
# define PROCESS_STATE_MASK (1 << 5 | 1 << 6 | 1 << 7 | 1 << 8)
|
||||||
|
|
||||||
# define IS_PIPESTART(p) (p->fdin == STDIN)
|
# define IS_PIPESTART(p) ((p).fdin == STDIN)
|
||||||
# define IS_PIPEEND(p) (p->fdout == STDOUT)
|
# define IS_PIPEEND(p) ((p).fdout == STDOUT)
|
||||||
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
# define IS_PIPESINGLE(p) (IS_PIPESTART(p) && IS_PIPEEND(p))
|
||||||
|
|
||||||
# define EXEC_BG (1 << 1)
|
# define EXEC_BG (1 << 1)
|
||||||
# define EXEC_AND_IF (1 << 2)
|
# define EXEC_AND_IF (1 << 2)
|
||||||
# define EXEC_OR_IF (1 << 3)
|
# define EXEC_OR_IF (1 << 3)
|
||||||
# define EXEC_IS_BG(j) (j & EXEC_BG)
|
# define EXEC_IF_BRANCH (1 << 4)
|
||||||
# define EXEC_IS_FG(j) (!EXEC_IS_BG(j))
|
# define EXEC_CASE_BRANCH (1 << 5)
|
||||||
# define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF)
|
# define EXEC_IS_BG(j) (j & EXEC_BG)
|
||||||
# define EXEC_IS_OR_IF(j) (j & EXEC_JOB_OR_IF)
|
# define EXEC_IS_FG(j) (!EXEC_IS_BG(j))
|
||||||
# define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF)
|
# define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF)
|
||||||
|
# define EXEC_IS_OR_IF(j) (j & EXEC_JOB_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.h"
|
# include "libft.h"
|
||||||
# include "types.h"
|
# include "types.h"
|
||||||
|
|
@ -58,20 +63,19 @@ struct s_process
|
||||||
t_list *redirs;
|
t_list *redirs;
|
||||||
int status;
|
int status;
|
||||||
t_flag attributes;
|
t_flag attributes;
|
||||||
t_condition if_branch;
|
|
||||||
t_condition case_branch;
|
|
||||||
char *case_pattern;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_exec
|
struct s_exec
|
||||||
{
|
{
|
||||||
/* char *aol_status; */
|
/* char *aol_status; */
|
||||||
/* int aol_search; */
|
/* int aol_search; */
|
||||||
/* t_job job; */
|
t_job job;
|
||||||
/* t_process process; */
|
/* t_process process; */
|
||||||
int fd_save[3];
|
int fd_save[3];
|
||||||
t_flag attrs;
|
t_flag attrs;
|
||||||
|
int fdin;
|
||||||
t_list *op_stack;
|
t_list *op_stack;
|
||||||
|
char *case_pattern;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_execmap
|
struct s_execmap
|
||||||
|
|
@ -101,7 +105,7 @@ int exec_or_if(t_btree **ast);
|
||||||
int exec_and_if(t_btree **ast);
|
int exec_and_if(t_btree **ast);
|
||||||
int exec_pipe(t_btree **ast);
|
int exec_pipe(t_btree **ast);
|
||||||
/* int exec_redir(t_btree **ast); */
|
/* int exec_redir(t_btree **ast); */
|
||||||
int exec_job(t_btree **ast);
|
int exec_cmd(t_btree **ast);
|
||||||
|
|
||||||
int exec_while(t_btree **ast);
|
int exec_while(t_btree **ast);
|
||||||
int exec_if(t_btree **ast);
|
int exec_if(t_btree **ast);
|
||||||
|
|
@ -115,7 +119,7 @@ int exec_case(t_btree **ast);
|
||||||
int exec_case_branch(t_btree **ast);
|
int exec_case_branch(t_btree **ast);
|
||||||
|
|
||||||
int launch_process(t_process *p);
|
int launch_process(t_process *p);
|
||||||
int process_setexec(t_type type, t_process *p);
|
int process_setexec(t_process *p);
|
||||||
int process_setgroup(t_process *p, pid_t pid);
|
int process_setgroup(t_process *p, pid_t pid);
|
||||||
void process_setsig(void);
|
void process_setsig(void);
|
||||||
void process_free(void *content, size_t content_size);
|
void process_free(void *content, size_t content_size);
|
||||||
|
|
@ -138,6 +142,8 @@ void set_exitstatus(int status, int override);
|
||||||
|
|
||||||
void ast_free(void *data, size_t content_size);
|
void ast_free(void *data, size_t content_size);
|
||||||
|
|
||||||
char **token_to_argv(t_astnode *node);
|
char **token_to_argv(t_ld *ld);
|
||||||
|
|
||||||
|
int add_new_job(t_job *job);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:01:59 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:38:51 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
# define JOB_NOTIFIED (1 << 0)
|
# define JOB_NOTIFIED (1 << 0)
|
||||||
# define JOB_BG (1 << 1)
|
# define JOB_BG (1 << 1)
|
||||||
|
# define JOB_IS_BG(j) (j & JOB_BG)
|
||||||
|
# define JOB_IS_FG(j) (!JOB_IS_BG(j))
|
||||||
|
|
||||||
# define JOBS_OPTS_L (1 << 0)
|
# define JOBS_OPTS_L (1 << 0)
|
||||||
|
|
||||||
|
|
@ -28,7 +30,7 @@ struct s_job
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
pid_t pgid;
|
pid_t pgid;
|
||||||
t_flag attributes;
|
t_flag attrs;
|
||||||
t_list *first_process;
|
t_list *first_process;
|
||||||
struct termios tmodes;
|
struct termios tmodes;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/17 15:56:55 by gwojda ### ########.fr */
|
/* Updated: 2017/03/03 16:07:30 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
/* Created: 2016/12/10 16:01:30 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:02:41 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:05:30 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ int exec_ampersand(t_btree **ast)
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
push(&exec->op_stack, TK_AMP);
|
push(&exec->op_stack, TK_AMP);
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
exec->attrs &= ~JOB_BG;
|
exec->attrs &= ~EXEC_BG;
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
|
|
||||||
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
|
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
|
/* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 20:41:02 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:05:42 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ int exec_and_if(t_btree **ast)
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
push(&exec->op_stack, TK_AND_IF);
|
push(&exec->op_stack, TK_AND_IF);
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
exec->attrs |= JOB_AND_IF;
|
exec->attrs |= EXEC_AND_IF;
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
|
|
||||||
/* data = data_singleton(); */
|
/* data = data_singleton(); */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/01 16:29:20 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 16:29:52 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,11 +15,16 @@
|
||||||
int exec_case(t_btree **ast)
|
int exec_case(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
char **av;
|
/* char **av; */
|
||||||
|
t_exec *exec;
|
||||||
|
|
||||||
|
exec = &data_singleton()->exec;
|
||||||
|
/* data_singleton()->exec.process.case_branch = 0; */
|
||||||
|
exec->attrs |= EXEC_CASE_BRANCH;
|
||||||
|
|
||||||
data_singleton()->exec.process.case_branch = 0;
|
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
av = token_to_argv(node);
|
/* av = token_to_argv(node); */
|
||||||
data_singleton()->exec.process.case_pattern = av[0];
|
/* data_singleton()->exec.process.case_pattern = av[0]; */
|
||||||
|
/* exec->case_pattern = av[0]; */
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 22:31:46 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:28:15 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,16 +15,19 @@
|
||||||
int exec_case_branch(t_btree **ast)
|
int exec_case_branch(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
char **av;
|
/* char **av; */
|
||||||
|
t_exec *exec;
|
||||||
|
|
||||||
if (data_singleton()->exec.process.case_branch == 1)
|
exec = &data_singleton()->exec;
|
||||||
|
/* if (data_singleton()->exec.process.case_branch == 1) */
|
||||||
|
if (EXEC_IS_CASE_BRANCH(exec->attrs))
|
||||||
return (0);
|
return (0);
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
av = token_to_argv(node);
|
/* av = token_to_argv(node); */
|
||||||
if (ft_strcmp(av[0], data_singleton()->exec.process.case_pattern) == 1)
|
/* if (ft_strcmp(av[0], data_singleton()->exec.process.case_pattern) == 1) */
|
||||||
{
|
/* { */
|
||||||
data_singleton()->exec.process.case_branch = 1;
|
/* data_singleton()->exec.process.case_branch = 1; */
|
||||||
ft_exec(&(*ast)->right);
|
/* ft_exec(&(*ast)->right); */
|
||||||
}
|
/* } */
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,19 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:16:23 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:36:29 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
char **token_to_argv(t_cmd *cmd)
|
char **token_to_argv(t_ld *ld)
|
||||||
{
|
{
|
||||||
char **my_tab;
|
char **my_tab;
|
||||||
int index;
|
int index;
|
||||||
char **expand;
|
char **expand;
|
||||||
char **content;
|
char **content;
|
||||||
t_ld *ld;
|
|
||||||
|
|
||||||
ld = cmd->token;
|
|
||||||
my_tab = NULL;
|
my_tab = NULL;
|
||||||
while (ld)
|
while (ld)
|
||||||
{
|
{
|
||||||
|
|
@ -37,33 +35,40 @@ char **token_to_argv(t_cmd *cmd)
|
||||||
return (my_tab);
|
return (my_tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
int exec_job(t_btree **ast)
|
int exec_cmd(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_list *cmd;
|
t_cmd *cmd;
|
||||||
|
t_job *job;
|
||||||
|
t_exec *exec;
|
||||||
t_process p;
|
t_process p;
|
||||||
t_list *first_process;
|
|
||||||
int fds[2];
|
int fds[2];
|
||||||
|
int op;
|
||||||
|
|
||||||
cmd = ((t_astnode *)(*ast)->item)->data;
|
cmd = &((t_astnode *)(*ast)->item)->data.cmd;
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
if (pop(&exec.op_stack) == TK_AMP)
|
job = &data_singleton()->exec.job;
|
||||||
exec->attrs |= JOB_BG;
|
process_reset(&p);
|
||||||
first_process = NULL;
|
op = pop(&exec->op_stack);
|
||||||
|
fds[PIPE_WRITE] = STDOUT;
|
||||||
fds[PIPE_READ] = STDIN;
|
fds[PIPE_READ] = STDIN;
|
||||||
while (cmd)
|
if (op == TK_AMP)
|
||||||
|
exec->attrs |= JOB_BG;
|
||||||
|
else if (op == TK_PIPE)
|
||||||
|
pipe(fds);
|
||||||
|
p.fdin = exec->fdin;
|
||||||
|
p.fdout = fds[PIPE_WRITE];
|
||||||
|
exec->fdin = fds[PIPE_READ];
|
||||||
|
if (IS_PIPESTART(p))
|
||||||
{
|
{
|
||||||
p.fdin = fds[PIPE_READ];
|
job->first_process = NULL;
|
||||||
p.fdout = cmd->next ? pipe(fds) && fds[PIPE_WRITE] : STDOUT;
|
job->attrs = EXEC_IS_FG(exec->attrs) ? 0 : JOB_BG;
|
||||||
process_reset(&p);
|
|
||||||
if (!(p.av = token_to_argv(cmd->content)))
|
|
||||||
return (1);
|
|
||||||
process_setexec(cmd->content, &p);
|
|
||||||
if (!(launch_process(p)))
|
|
||||||
ft_lstadd(&first_process, ft_lstnew(&p, sizeof(p)));
|
|
||||||
cmd = cmd->next;
|
|
||||||
}
|
}
|
||||||
add_new_job(first_process, EXEC_IS_FG(exec->attrs));
|
if (!(p.av = token_to_argv(cmd->token)))
|
||||||
ft_lstadd(&jobc->first_job, ft_lstnew(&job, sizeof(*job)));
|
return (1);
|
||||||
// btree_delone(ast, &ast_free);
|
process_setexec(&p);
|
||||||
|
if (!(launch_process(&p)))
|
||||||
|
ft_lstadd(&job->first_process, ft_lstnew(&p, sizeof(p)));
|
||||||
|
if (IS_PIPEEND(p))
|
||||||
|
add_new_job(job);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 18:08:53 by ariard #+# #+# */
|
/* Created: 2017/02/06 18:08:53 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 22:35:47 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:14:25 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,12 +14,18 @@
|
||||||
|
|
||||||
int exec_elif(t_btree **ast)
|
int exec_elif(t_btree **ast)
|
||||||
{
|
{
|
||||||
if (data_singleton()->exec.process.if_branch == 1)
|
t_exec *exec;
|
||||||
|
|
||||||
|
exec = &data_singleton()->exec;
|
||||||
|
/* if (data_singleton()->exec.process.if_branch == 1) */
|
||||||
|
if (EXEC_IS_IF_BRANCH(exec->attrs))
|
||||||
return (0);
|
return (0);
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
if (data_singleton()->exec.process.status == 1)
|
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
|
||||||
|
/* if (data_singleton()->exec.process.status == 1) */
|
||||||
{
|
{
|
||||||
data_singleton()->exec.process.if_branch = 1;
|
/* data_singleton()->exec.process.if_branch = 1; */
|
||||||
|
exec->attrs |= EXEC_IF_BRANCH;
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 18:55:07 by ariard #+# #+# */
|
/* Created: 2017/02/06 18:55:07 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 19:13:05 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 15:56:25 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,9 +14,14 @@
|
||||||
|
|
||||||
int exec_else(t_btree **ast)
|
int exec_else(t_btree **ast)
|
||||||
{
|
{
|
||||||
if (data_singleton()->exec.process.if_branch == 0)
|
t_exec *exec;
|
||||||
|
|
||||||
|
exec = &data_singleton()->exec;
|
||||||
|
if (EXEC_IS_IF_BRANCH(exec->attrs))
|
||||||
|
/* if (data_singleton()->exec.process.if_branch == 0) */
|
||||||
{
|
{
|
||||||
data_singleton()->exec.process.if_branch = 1;
|
exec->attrs |= EXEC_IF_BRANCH;
|
||||||
|
/* data_singleton()->exec.process.if_branch = 1; */
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
|
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 20:42:21 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 16:26:40 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
/* Created: 2017/02/06 18:07:31 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/20 22:31:46 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:30:46 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,11 +14,18 @@
|
||||||
|
|
||||||
int exec_if(t_btree **ast)
|
int exec_if(t_btree **ast)
|
||||||
{
|
{
|
||||||
data_singleton()->exec.process.if_branch = 0;
|
t_exec *exec;
|
||||||
|
|
||||||
|
exec = &data_singleton()->exec;
|
||||||
|
|
||||||
|
/* data_singleton()->exec.process.if_branch = 0; */
|
||||||
|
exec->attrs &= ~EXEC_IF_BRANCH;
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
if (data_singleton()->exec.process.status == 1)
|
/* if (data_singleton()->exec.process.status == 1) */
|
||||||
|
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
|
||||||
{
|
{
|
||||||
data_singleton()->exec.process.if_branch = 1;
|
/* data_singleton()->exec.process.if_branch = 1; */
|
||||||
|
exec->attrs |= EXEC_IF_BRANCH;
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* exec_less.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/14 17:27:08 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/03/01 16:37:28 by ariard ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "exec.h"
|
|
||||||
|
|
||||||
int exec_less(t_btree **ast)
|
|
||||||
{
|
|
||||||
t_astnode *node;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = 0;
|
|
||||||
node = (*ast)->item;
|
|
||||||
// fd = open(node->data.redir.word.word, O_RDONLY);
|
|
||||||
data_singleton()->exec.process.fdin = fd;
|
|
||||||
/* ft_strappend(&data->exec.process.command, "<"); */
|
|
||||||
/* ft_strappend(&data->exec.process.command, node->data.redir.word.word); */
|
|
||||||
ft_exec(&(*ast)->left);
|
|
||||||
data_singleton()->exec.process.fdin = STDIN;
|
|
||||||
/* data->exec.process.command = NULL; */
|
|
||||||
|
|
||||||
// btree_delone(ast, &ast_free);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
|
/* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:02:34 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:07:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ int exec_or_if(t_btree **ast)
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
push(&exec->op_stack, TK_OR_IF);
|
push(&exec->op_stack, TK_OR_IF);
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
exec->attrs |= JOB_OR_IF;
|
exec->attrs |= EXEC_OR_IF;
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
|
|
||||||
/* data = data_singleton(); */
|
/* data = data_singleton(); */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
|
/* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/21 21:47:43 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:27:48 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,13 +14,10 @@
|
||||||
|
|
||||||
int exec_pipe(t_btree **ast)
|
int exec_pipe(t_btree **ast)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_exec *exec;
|
||||||
t_process *p;
|
|
||||||
|
|
||||||
DG("exec pipe");
|
exec = &data_singleton()->exec;
|
||||||
data = data_singleton();
|
push(&exec->op_stack, TK_PIPE);
|
||||||
p = &data->exec.process;
|
|
||||||
p->pipe_count++;
|
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
/* btree_delone(ast, &ast_free); */
|
/* btree_delone(ast, &ast_free); */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
|
/* Created: 2016/11/30 20:52:05 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 20:41:25 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:26:08 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ int exec_semi(t_btree **ast)
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
push(&exec->op_stack, TK_SEMI);
|
push(&exec->op_stack, TK_SEMI);
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
exec->attrs ~= ~JOB_AOL_MASK;
|
exec->attrs &= ~EXEC_AOL_MASK;
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
// btree_delone(ast, &ast_free);
|
// btree_delone(ast, &ast_free);
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
|
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 20:42:21 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 16:30:13 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
int exec_until(t_btree **ast)
|
int exec_until(t_btree **ast)
|
||||||
{
|
{
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
while (data_singleton()->exec.process.status == 0)
|
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
|
||||||
{
|
{
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 16:28:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ int exec_var(t_btree **ast)
|
||||||
char **av;
|
char **av;
|
||||||
|
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
av = token_to_argv(node);
|
/* av = token_to_argv(node); */
|
||||||
builtin_setenv("setenv", av, data_singleton()->local_var);
|
builtin_setenv("setenv", av, data_singleton()->local_var);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
|
||||||
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 16:05:12 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
int exec_while(t_btree **ast)
|
int exec_while(t_btree **ast)
|
||||||
{
|
{
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
while (data_singleton()->exec.process.status == 1)
|
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0"))
|
||||||
{
|
{
|
||||||
ft_exec(&(*ast)->right);
|
ft_exec(&(*ast)->right);
|
||||||
ft_exec(&(*ast)->left);
|
ft_exec(&(*ast)->left);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 20:53:28 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:28:22 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ t_execmap g_execmap[] =
|
||||||
{TK_ELSE, &exec_else},
|
{TK_ELSE, &exec_else},
|
||||||
{TK_UNTIL, &exec_until},
|
{TK_UNTIL, &exec_until},
|
||||||
/* {TK_SUBSHELL, &exec_}, */
|
/* {TK_SUBSHELL, &exec_}, */
|
||||||
{TK_WORD, &exec_job},
|
{TK_WORD, &exec_cmd},
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 20:29:33 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:29:12 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,12 +18,7 @@ int launch_process(t_process *p)
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
exec = &data_singleton()->exec;
|
exec = &data_singleton()->exec;
|
||||||
if (p->attributes & PROCESS_UNKNOWN)
|
if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(*p))
|
||||||
{
|
|
||||||
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
|
||||||
set_exitstatus(127, 1);
|
|
||||||
}
|
|
||||||
else if (p->attributes & PROCESS_BUILTIN && IS_PIPESINGLE(p))
|
|
||||||
{
|
{
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
return (1);
|
return (1);
|
||||||
|
|
@ -43,6 +38,12 @@ int launch_process(t_process *p)
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
{
|
{
|
||||||
|
if (p->attributes & PROCESS_UNKNOWN)
|
||||||
|
{
|
||||||
|
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->av[0]);
|
||||||
|
exit(127);
|
||||||
|
/* set_exitstatus(127, 1); */
|
||||||
|
}
|
||||||
process_setgroup(p, 0);
|
process_setgroup(p, 0);
|
||||||
process_setsig();
|
process_setsig();
|
||||||
if (process_redirect(p))
|
if (process_redirect(p))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */
|
/* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 20:44:12 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:36:06 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,16 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:00:51 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:32:15 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int process_setexec(t_cmd *cmd, t_process *p)
|
int process_setexec(t_process *p)
|
||||||
{
|
{
|
||||||
t_flag type;
|
|
||||||
|
|
||||||
type = cmd->type;
|
|
||||||
p->path = NULL;
|
p->path = NULL;
|
||||||
/* if (type == TK_SUBSHELL) */
|
if ((p->execf = is_builtin(p)))
|
||||||
/* { */
|
|
||||||
/* p->execf = &execve; */
|
|
||||||
/* p->attributes |= PROCESS_SUBSHELL; */
|
|
||||||
/* p->path = ft_strdup(p->av[0]); */
|
|
||||||
/* } */
|
|
||||||
else if ((p->execf = is_builtin(p)))
|
|
||||||
p->attributes |= PROCESS_BUILTIN;
|
p->attributes |= PROCESS_BUILTIN;
|
||||||
else if (ft_strchr(p->av[0], '/'))
|
else if (ft_strchr(p->av[0], '/'))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 20:13:48 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:34:02 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ int process_setgroup(t_process *p, pid_t pid)
|
||||||
if (!j->pgid)
|
if (!j->pgid)
|
||||||
j->pgid = pid ? pid : getpid();
|
j->pgid = pid ? pid : getpid();
|
||||||
setpgid(pid, j->pgid);
|
setpgid(pid, j->pgid);
|
||||||
if (pid == 0 && JOB_IS_FG(j->attributes))
|
if (pid == 0 && JOB_IS_FG(j->attrs))
|
||||||
tcsetpgrp(STDIN, j->pgid);
|
tcsetpgrp(STDIN, j->pgid);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/24 22:04:43 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 16:45:40 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,33 +15,34 @@
|
||||||
|
|
||||||
char *command_getoutput(char *command)
|
char *command_getoutput(char *command)
|
||||||
{
|
{
|
||||||
int fds[2];
|
return (command);
|
||||||
t_btree *ast;
|
/* int fds[2]; */
|
||||||
t_astnode item;
|
/* t_btree *ast; */
|
||||||
char *output;
|
/* t_astnode item; */
|
||||||
char buf[BUF_SIZE + 1];
|
/* char *output; */
|
||||||
int ret;
|
/* char buf[BUF_SIZE + 1]; */
|
||||||
t_exec *exec;
|
/* int ret; */
|
||||||
|
/* t_exec *exec; */
|
||||||
|
|
||||||
output = NULL;
|
/* output = NULL; */
|
||||||
exec = &data_singleton()->exec;
|
/* exec = &data_singleton()->exec; */
|
||||||
item.type = TK_SUBSHELL;
|
/* item.type = TK_SUBSHELL; */
|
||||||
item.data.sstr = malloc(4 * sizeof(char *));
|
/* item.data.sstr = malloc(4 * sizeof(char *)); */
|
||||||
item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]);
|
/* item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]); */
|
||||||
item.data.sstr[1] = ft_strdup("-c");
|
/* item.data.sstr[1] = ft_strdup("-c"); */
|
||||||
item.data.sstr[2] = ft_strdup(command);
|
/* item.data.sstr[2] = ft_strdup(command); */
|
||||||
item.data.sstr[3] = NULL;
|
/* item.data.sstr[3] = NULL; */
|
||||||
ast = btree_create_node(&item, sizeof(item));
|
/* ast = btree_create_node(&item, sizeof(item)); */
|
||||||
pipe(fds);
|
/* pipe(fds); */
|
||||||
exec->process.fdout = fds[PIPE_WRITE];
|
/* exec->process.fdout = fds[PIPE_WRITE]; */
|
||||||
exec_command(&ast);
|
/* exec_command(&ast); */
|
||||||
exec->process.fdout = STDOUT;
|
/* exec->process.fdout = STDOUT; */
|
||||||
close(fds[PIPE_WRITE]);
|
/* close(fds[PIPE_WRITE]); */
|
||||||
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)))
|
/* while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE))) */
|
||||||
{
|
/* { */
|
||||||
buf[ret] = 0;
|
/* buf[ret] = 0; */
|
||||||
ft_strappend(&output, buf);
|
/* ft_strappend(&output, buf); */
|
||||||
}
|
/* } */
|
||||||
close(fds[PIPE_READ]);
|
/* close(fds[PIPE_READ]); */
|
||||||
return (output);
|
/* return (output); */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,22 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
|
/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:04:51 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:47:47 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "job_control.h"
|
#include "job_control.h"
|
||||||
|
|
||||||
int add_new_job(t_list *first_process, int foreground)
|
int add_new_job(t_job *job)
|
||||||
{
|
{
|
||||||
t_jobc *jobc;
|
t_jobc *jobc;
|
||||||
t_job job;
|
|
||||||
|
|
||||||
if (!first_process)
|
if (!job->first_process)
|
||||||
return (1);
|
return (1);
|
||||||
jobc = &data_singleton()->jobc;
|
jobc = &data_singleton()->jobc;
|
||||||
job_update_id();
|
job_update_id();
|
||||||
job->id = jobc->current_id;
|
job->id = jobc->current_id;
|
||||||
job->pgid = ((t_process*)first_process->content)->pid;
|
job->pgid = ((t_process*)job->first_process->content)->pid;
|
||||||
job->attrs = foreground ? 0 : JOB_BG;
|
|
||||||
job->first_process = first_process;
|
|
||||||
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
|
||||||
if (JOB_IS_FG(job->attrs))
|
if (JOB_IS_FG(job->attrs))
|
||||||
put_job_in_foreground(job, 0);
|
put_job_in_foreground(job, 0);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
|
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/03 15:47:44 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:46:51 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -27,14 +27,14 @@ int do_job_notification(void)
|
||||||
{
|
{
|
||||||
j = jlist->content;
|
j = jlist->content;
|
||||||
if (job_is_completed(j->id)
|
if (job_is_completed(j->id)
|
||||||
|| (job_is_stopped(j->id) && !(j->attributes & JOB_NOTIFIED)))
|
|| (job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED)))
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
job_notify_change(j->id);
|
job_notify_change(j->id);
|
||||||
if (job_is_completed(j->id))
|
if (job_is_completed(j->id))
|
||||||
job_remove(j->id);
|
job_remove(j->id);
|
||||||
else
|
else
|
||||||
j->attributes |= JOB_NOTIFIED;
|
j->attrs |= JOB_NOTIFIED;
|
||||||
}
|
}
|
||||||
jlist = jlist->next;
|
jlist = jlist->next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */
|
/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/01/31 15:08:11 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:47:28 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -28,5 +28,5 @@ void mark_job_as_running(t_job *j)
|
||||||
}
|
}
|
||||||
plist = plist->next;
|
plist = plist->next;
|
||||||
}
|
}
|
||||||
j->attributes &= ~JOB_NOTIFIED;
|
j->attrs &= ~JOB_NOTIFIED;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */
|
/* Created: 2017/02/09 22:03:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/17 15:36:49 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:48:07 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ int lexer_bquote(t_list **alst, t_lexer *lexer)
|
||||||
push(&lexer->stack, lexer->state);
|
push(&lexer->stack, lexer->state);
|
||||||
return (lexer_lex(alst, lexer));
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
top_state = *(int*)pop(&lexer->stack)->content;
|
top_state = pop(&lexer->stack);
|
||||||
lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT;
|
lexer->state = top_state == DQUOTE_BQUOTE ? DQUOTE : DEFAULT;
|
||||||
return (lexer_lex(alst, lexer));
|
return (lexer_lex(alst, lexer));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:02:17 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 16:48:29 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -35,7 +35,8 @@ int data_init(void)
|
||||||
data->exec.fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC);
|
data->exec.fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC);
|
||||||
data->exec.fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC);
|
data->exec.fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC);
|
||||||
data->exec.op_stack = NULL;
|
data->exec.op_stack = NULL;
|
||||||
data->attrs = 0;
|
data->exec.fdin = STDIN;
|
||||||
|
data->exec.attrs = 0;
|
||||||
|
|
||||||
/* data->exec.aol_status = NULL; */
|
/* data->exec.aol_status = NULL; */
|
||||||
/* data->exec.aol_search = 0; */
|
/* data->exec.aol_search = 0; */
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:00:57 by jhalford ### ########.fr */
|
/* Updated: 2017/03/03 15:59:40 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue