builtins no longer remain in job control

This commit is contained in:
Jack Halford 2017-03-05 15:07:43 +01:00
parent 56b106ee0f
commit 566cd522ae
8 changed files with 81 additions and 126 deletions

View file

@ -95,6 +95,7 @@ exec/redirect_greatand.c\
exec/redirect_less.c\
exec/redirect_lessand.c\
exec/set_exitstatus.c\
exec/set_process.c\
glob/command_getoutput.c\
glob/dir_glob.c\
glob/esc_print.c\
@ -137,11 +138,11 @@ history/history_parsing_toolz.c\
history/history_parsing_toolz_2.c\
history/list_toolz.c\
history/surch_in_history.c\
job-control/add_new_job.c\
job-control/builtin_bg.c\
job-control/builtin_fg.c\
job-control/builtin_jobs.c\
job-control/do_job_notification.c\
job-control/job_addprocess.c\
job-control/job_cmp_id.c\
job-control/job_format.c\
job-control/job_format_head.c\
@ -223,12 +224,12 @@ main/data_exit.c\
main/data_init.c\
main/data_singleton.c\
main/ft_putast.c\
main/instruction_free.c\
main/main.c\
main/shell_exit.c\
main/shell_get_avdata.c\
main/shell_get_opts.c\
main/shell_init.c\
main/instruction_free.c\
parser/add_case.c\
parser/add_cmd.c\
parser/add_condition.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/03 20:28:08 by wescande ### ########.fr */
/* Updated: 2017/03/05 15:04:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -119,6 +119,7 @@ int exec_case(t_btree **ast);
int exec_case_branch(t_btree **ast);
int launch_process(t_process *p);
int set_process(t_process *p, t_btree *ast);
int process_setexec(t_process *p);
int process_setgroup(t_process *p, pid_t pid);
void process_setsig(void);

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/03/04 17:11:10 by ariard ### ########.fr */
/* Updated: 2017/03/05 15:03:35 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -37,51 +37,25 @@ char **token_to_argv(t_ld *ld, int do_match)
int exec_cmd(t_btree **ast)
{
t_cmd *cmd;
t_job *job;
t_exec *exec;
t_process p;
int fds[2];
int op;
t_job *job;
cmd = &((t_astnode *)(*ast)->item)->data.cmd;
exec = &data_singleton()->exec;
job = &data_singleton()->exec.job;
process_reset(&p);
op = pop(&exec->op_stack);
fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN;
if (op == TK_AMP)
exec->attrs |= JOB_BG;
else if (op == TK_PIPE)
pipe(fds);
p.fdin = exec->fdin;
p.to_close = fds[PIPE_READ];
p.fdout = fds[PIPE_WRITE];
p.redirs = cmd->redir;
exec->fdin = fds[PIPE_READ];
if (IS_PIPESTART(p))
{
job->first_process = NULL;
job->attrs = EXEC_IS_FG(exec->attrs) ? 0 : JOB_BG;
}
if (!(p.av = token_to_argv(cmd->token, 1)))
if (set_process(&p, *ast))
return (1);
process_setexec(&p);
if (!(launch_process(&p)))
ft_lstadd(&job->first_process, ft_lstnew(&p, sizeof(p)));
if (fds[PIPE_WRITE] != STDOUT)
close(fds[PIPE_WRITE]);
if (IS_PIPEEND(p))
{
add_new_job(job);
if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0);
else
job_addprocess(&p);
if (IS_PIPEEND(p))
{
job_notify_new(job);
put_job_in_background(job, 0);
if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0);
else
put_job_in_background(job, 0);
}
job->pgid = 0;
}
if (p.fdout != STDOUT)
close(p.fdout);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/03/03 19:53:26 by jhalford ### ########.fr */
/* Updated: 2017/03/05 14:41:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,7 @@ int launch_process(t_process *p)
if (process_redirect(p))
return (1);
set_exitstatus((*p->execf)(p->path, p->av, data_singleton()->env), 1);
return (0);
return (1);
}
else
{

View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:05:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "exec.h"
int set_process(t_process *p, t_btree *ast)
{
t_exec *exec;
t_cmd *cmd;
int op;
int fds[2];
cmd = &((t_astnode *)ast->item)->data.cmd;
process_reset(p);
exec = &data_singleton()->exec;
op = pop(&exec->op_stack);
if (!(p->av = token_to_argv(cmd->token, 1)))
return (1);
fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN;
if (op == TK_AMP)
exec->attrs |= JOB_BG;
else if (op == TK_PIPE)
pipe(fds);
p->fdin = exec->fdin;
p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE];
exec->fdin = fds[PIPE_READ];
p->redirs = cmd->redir;
process_setexec(p);
return (0);
}

View file

@ -1,28 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_new_job.c :+: :+: :+: */
/* job_addprocess.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
/* Updated: 2017/03/03 19:33:29 by jhalford ### ########.fr */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/03/05 15:05:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "job_control.h"
int add_new_job(t_job *job)
int job_addprocess(t_process *p)
{
t_jobc *jobc;
t_job *job;
DG("adding new job");
if (!job->first_process)
return (1);
jobc = &data_singleton()->jobc;
job_update_id();
job->id = jobc->current_id;
job->pgid = ((t_process*)job->first_process->content)->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
job = &data_singleton()->exec.job;
if (IS_PIPESTART(*p))
{
job_update_id();
job->id = jobc->current_id;
job->pgid = p->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
}
job = jobc->first_job->content;
if (p->pid > 0)
{
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
}
if (JOB_IS_BG(job->attrs) && IS_PIPEEND(*p))
job_notify_new(job);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:48:28 by jhalford ### ########.fr */
/* Updated: 2017/03/05 14:46:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -1,71 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
/* Updated: 2017/03/04 21:31:18 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "parser.h"
int add_cmd(t_btree **ast, t_list **lst)
{
t_token *token;
t_astnode *node;
char **my_tab;
if ((token = (*lst)->content)->type == TK_IN || token->type == TK_PAREN_OPEN)
return (0);
else if (isdir_sep(ast, lst))
return (add_redir_type(ast, lst));
else if (!*ast)
gen_node(ast);
else if (isdir_word(ast, lst))
return (add_redir_word(ast, lst));
else if (isvar(ast, lst))
return (add_var(ast, lst));
else if (isloop(ast, lst) == 3)
return (add_loop_condition(ast, lst));
else if (isloop(ast, lst))
return (add_loop_cmd(ast, lst));
else if (iscondition(ast, lst) == 1)
return (add_condition_cmd(ast, lst));
else if (iscondition(ast, lst) == 2)
return (add_branch(ast, lst));
else if (iscase(ast, lst) == 1)
return (add_pattern(ast, lst));
else if (iscase(ast, lst) == 2)
return (add_case_cmd(ast, lst));
else if (iscase(ast, lst) == 3)
return (add_branch(ast, lst));
else if (issubshell(ast, lst))
return (add_subshell_cmd(ast, lst));
else if (isfunc(ast, lst))
return (add_func_cmd(ast, lst));
else if ((node = (*ast)->item)->type != TK_DO && node->type != TK_THEN
&& node->type != TK_PAREN_CLOSE && node->type != CMD
&& node->type != REDIR)
return (add_cmd(&(*ast)->right, lst));
node = (*ast)->item;
if (token->type != TK_WORD)
node->type = token->type;
else
node->type = CMD;
if (token->type == TK_WORD || token->type == TK_ASSIGNEMENT_WORD)
{
DG("add data");
if ((my_tab = (char **)malloc(sizeof(char *) * 4)))
{
my_tab[0] = ft_strdup(token->data);
my_tab[1] = (char *)dup_char_esc(token->esc, token->size >> 3);
my_tab[2] = (char *)dup_char_esc(token->esc2, token->size >> 3);
my_tab[3] = NULL;
}
ft_ld_pushback(&node->data.cmd.token, my_tab);
}
return (0);
}