heredoc fix

This commit is contained in:
Jack Halford 2017-03-13 14:13:33 +01:00
parent eb4af04a36
commit 4a46f6db57
18 changed files with 45 additions and 38 deletions

View file

@ -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/11 16:06:07 by jhalford ### ########.fr */ /* Updated: 2017/03/13 13:52:40 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -154,7 +154,7 @@ int join_ast(t_btree **ast, t_btree **new_node);
int gen_node(t_btree **ast); int gen_node(t_btree **ast);
int superflous_token(t_btree **ast, t_list **list); int superflous_token(t_btree **ast, t_list **list);
int ft_show_heredoc_data(t_btree **ast); int ft_show_heredoc_data(t_astnode *node);
struct s_distrostree struct s_distrostree
{ {

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/11 18:32:51 by jhalford ### ########.fr */ /* Updated: 2017/03/13 14:13:02 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,13 +22,14 @@ int exec_leaf(t_btree **ast)
return (1); return (1);
if (!(launch_process(&p))) if (!(launch_process(&p)))
{ {
/* DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); */ DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]);
job_addprocess(&p); job_addprocess(&p);
/* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */ /* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */
if (IS_PIPEEND(p)) if (IS_PIPEEND(p))
{ {
if (JOB_IS_FG(job->attrs)) if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0); put_job_in_foreground(job, 0);
DG("job->pgid RESET (end of pipe)");
job->pgid = 0; job->pgid = 0;
} }
} }

View file

@ -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/10 15:45:12 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:03:44 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* 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/11 18:16:40 by jhalford ### ########.fr */ /* Updated: 2017/03/13 13:28:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,10 +22,10 @@ int launch_file(t_process *p)
/* data_singleton()->opts &= ~SH_INTERACTIVE; */ /* data_singleton()->opts &= ~SH_INTERACTIVE; */
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */ /* data_singleton()->opts &= ~SH_OPTS_JOBC; */
/* DG("fork! [%s]", p->data.cmd.av[0]); */ /* DG("fork! [%s]", p->data.cmd.av[0]); */
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p)) if (process_redirect(p))
exit (1); exit (1);
process_setgroup(p, 0);
process_setsig();
exec_reset(); exec_reset();
if (!p->data.cmd.path) if (!p->data.cmd.path)
{ {

View file

@ -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/11 17:59:03 by jhalford ### ########.fr */ /* Updated: 2017/03/13 14:12:52 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
/* Updated: 2017/03/11 18:09:35 by jhalford ### ########.fr */ /* Updated: 2017/03/13 13:27:48 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,10 +36,10 @@ int launch_subshell(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p)) if (process_redirect(p))
exit (1); exit (1);
process_setgroup(p, 0);
process_setsig();
exec_reset(); exec_reset();
exit(do_subshell(p)); exit(do_subshell(p));
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/11 19:44:31 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:01:23 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,8 +33,9 @@ int process_redirect(t_process *p)
while (redirs) while (redirs)
{ {
redir = redirs->content; redir = redirs->content;
DG("redirs content : %p", redirs->content); /* DG("redirs content : %p", redirs->content); */
// DG("redir.type [%li]", redir->type); DG("redir @ %p", redir);
DG("redir.type [%li]", redir->type);
DG("redir.word [%s]", redir->word); DG("redir.word [%s]", redir->word);
DG("redir.n [%i]", redir->n); DG("redir.n [%i]", redir->n);
if (redir->n > 9) if (redir->n > 9)

View file

@ -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/11 16:07:43 by jhalford ### ########.fr */ /* Updated: 2017/03/13 13:37:03 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -25,7 +25,10 @@ int process_setgroup(t_process *p, pid_t pid)
return (0); return (0);
DG("setpgid(%i, %i)", pid, j->pgid); DG("setpgid(%i, %i)", pid, j->pgid);
if (setpgid(pid, j->pgid) == -1) if (setpgid(pid, j->pgid) == -1)
ft_dprintf(2, "{red}%s: internal setpgid() error{eoc}\n", SHELL_NAME); {
ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno);
perror("");
}
if (pid == 0 && JOB_IS_FG(j->attrs)) if (pid == 0 && JOB_IS_FG(j->attrs))
{ {
DG("tcsetpgrp[%i]", j->pgid); DG("tcsetpgrp[%i]", j->pgid);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */
/* Updated: 2017/03/08 11:53:26 by jhalford ### ########.fr */ /* Updated: 2017/03/13 14:13:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,5 +24,6 @@ void *redir_copy(void *data)
new->type = old->type; new->type = old->type;
new->n = old->n; new->n = old->n;
new->word = ft_strdup(old->word); new->word = ft_strdup(old->word);
new->heredoc_data = ft_strdup(old->heredoc_data);
return (new); return (new);
} }

View file

@ -18,7 +18,8 @@ int redirect_dless(t_redir *redir)
pipe(fds); pipe(fds);
str = redir->heredoc_data; str = redir->heredoc_data;
DG("[%s] && adr %p", str, redir); DG("[%s] && adr %p", str, str);
DG("redir @ %p", redir);
write(fds[PIPE_WRITE], str, ft_strlen(str)); write(fds[PIPE_WRITE], str, ft_strlen(str));
close(fds[PIPE_WRITE]); close(fds[PIPE_WRITE]);
dup2(fds[PIPE_READ], 0); dup2(fds[PIPE_READ], 0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/11 17:49:28 by jhalford ### ########.fr */ /* Updated: 2017/03/13 14:13:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/03/11 16:00:09 by jhalford ### ########.fr */ /* Updated: 2017/03/13 13:22:22 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/11 18:22:21 by jhalford ### ########.fr */ /* Updated: 2017/03/13 14:03:43 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,7 @@ int put_job_in_foreground(t_job *j, int cont)
if (kill(-j->pgid, SIGCONT) < 0) if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed"); DG("kill(SIGCONT) failed");
} }
/* if (SH_IS_INTERACTIVE(data_singleton()->opts)) */
job_wait(j->id); job_wait(j->id);
job_remove(j->id); job_remove(j->id);
if (SH_IS_INTERACTIVE(data_singleton()->opts)) if (SH_IS_INTERACTIVE(data_singleton()->opts))

View file

@ -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/11 19:56:53 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:12:55 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -70,8 +70,8 @@ int handle_instruction(int fd)
return (error_syntax(&token, &parser, &ast)); return (error_syntax(&token, &parser, &ast));
} }
} }
/* ft_show_heredoc_data(&ast); */
btree_print(STDBUG, ast, &ft_putast); btree_print(STDBUG, ast, &ft_putast);
/* ft_show_heredoc_data(ast->left->item); */
if (ft_exec(&ast)) if (ft_exec(&ast))
return (1); return (1);
instruction_free(&token, &parser, &ast); instruction_free(&token, &parser, &ast);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/03/11 19:57:02 by ariard ### ########.fr */ /* Updated: 2017/03/13 13:06:20 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:21:05 by ariard #+# #+# */ /* Created: 2017/03/08 16:21:05 by ariard #+# #+# */
/* Updated: 2017/03/11 19:40:43 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:01:28 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,8 @@ int pop_heredoc(t_list **lst)
temp2 = temp->next; temp2 = temp->next;
// free(temp); // free(temp);
data_singleton()->heredoc_queue = temp2; data_singleton()->heredoc_queue = temp2;
DG("data is %s et adr %p", head->heredoc_data, temp); DG("data is %s et adr %p", head->heredoc_data, head->heredoc_data);
DG("redir @ %p", head);
} }
else else
{ {

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
/* Updated: 2017/03/11 19:55:57 by ariard ### ########.fr */ /* Updated: 2017/03/13 14:13:05 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -224,18 +224,16 @@ int ft_read_stack(t_sym *stack)
} }
int ft_show_heredoc_data(t_btree **ast) int ft_show_heredoc_data(t_astnode *node)
{ {
t_astnode *node;
t_redir *redir; t_redir *redir;
if (*ast) if (node->type != CMD)
if ((*ast)->left) return (1);
{ redir = (node->data.cmd.redir)->content;
node = ((*ast)->left)->item; if (redir->type != TK_DLESS)
redir = (node->data.cmd.redir)->content; return (1);
if (redir->type == TK_DLESS) DG("heredoc_data=[%s] @ %p", redir->heredoc_data, redir->heredoc_data);
DG("Show me heredoc data from node :%s", redir->heredoc_data); DG("redir @ %p", redir);
}
return (0); return (0);
} }