fixed subshells normally

This commit is contained in:
Jack Halford 2017-03-11 16:06:39 +01:00
parent 58c6491d23
commit 971da39d1b
20 changed files with 71 additions and 72 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:57:46 by jhalford ### ########.fr */
/* Updated: 2017/03/11 16:06:07 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

@ -1 +1 @@
Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6
Subproject commit 934ff3af934eaecf04575a0a7e7e1b76628ae53b

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/10 16:58:57 by jhalford ### ########.fr */
/* Updated: 2017/03/11 16:00:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,7 +24,7 @@ int exec_leaf(t_btree **ast)
{
DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]);
job_addprocess(&p);
DG("[BG:%i]", JOB_IS_BG(job->attrs));
DG("[IS_BG->%i]", JOB_IS_BG(job->attrs));
if (IS_PIPEEND(p))
{
if (JOB_IS_FG(job->attrs))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:49:14 by jhalford ### ########.fr */
/* Updated: 2017/03/11 14:19:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,17 +15,16 @@
int exec_reset(void)
{
t_exec *exec;
t_jobc *jobc;
exec = &data_singleton()->exec;
/* exec->fd_save[0] = 1;//fcntl(STDIN, F_DUPFD_CLOEXEC); */
/* exec->fd_save[1] = 1;//fcntl(STDOUT, F_DUPFD_CLOEXEC); */
/* exec->fd_save[2] = 1;//fcntl(STDERR, F_DUPFD_CLOEXEC); */
jobc = &data_singleton()->jobc;
if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i %s{eoc}\n", SHELL_NAME, errno);
ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i{eoc}\n", SHELL_NAME, errno);
if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i %s{eoc}\n", SHELL_NAME, errno);
ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i{eoc}\n", SHELL_NAME, errno);
if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF)
ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i %s{eoc}\n", SHELL_NAME, errno);
ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i{eoc}\n", SHELL_NAME, errno);
/* DG("saved [%i:%i:%i]", exec->fd_save[0], exec->fd_save[1], exec->fd_save[2]); */
exec->op_stack = NULL;
exec->fdin = STDIN;
@ -34,5 +33,7 @@ int exec_reset(void)
exec->job.pgid = 0;
exec->job.attrs = 0;
exec->job.first_process = NULL;
jobc->first_job = NULL;
jobc->current_id = 1;
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
/* Updated: 2017/03/10 12:12:59 by jhalford ### ########.fr */
/* Updated: 2017/03/11 16:00:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,10 +16,12 @@ int launch_file(t_process *p)
{
int pid;
/* DG("in file"); */
pid = fork();
if (pid == 0)
{
/* data_singleton()->opts &= ~SH_INTERACTIVE; */
/* data_singleton()->opts &= ~SH_OPTS_JOBC; */
DG("fork! [%s]", p->data.cmd.av[0]);
if (!p->data.cmd.path)
{
ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
/* Updated: 2017/03/10 17:08:46 by jhalford ### ########.fr */
/* Updated: 2017/03/11 13:48:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -52,19 +52,3 @@ int launch_if(t_process *p)
do_if(p);
return (0);
}
/*
int exec_if(t_btree **ast)
{
t_exec *exec;
exec = &data_singleton()->exec;
exec->attrs &= ~EXEC_IF_BRANCH;
ft_exec(&(*ast)->left);
if (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)
{
exec->attrs |= EXEC_IF_BRANCH;
ft_exec(&(*ast)->right);
}
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/10 16:50:33 by jhalford ### ########.fr */
/* Updated: 2017/03/11 15:49:36 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
/* Updated: 2017/03/10 11:51:55 by jhalford ### ########.fr */
/* Updated: 2017/03/11 15:38:56 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2017/03/10 15:31:30 by jhalford ### ########.fr */
/* Updated: 2017/03/11 15:42:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,14 +33,13 @@ int process_redirect(t_process *p)
while (redirs)
{
redir = redirs->content;
DG("redir type :%s", read_state(redir->type));
DG("redir word : %s", redir->word);
/* DG("redir type :%s", read_state(redir->type)); */
/* DG("redir word : %s", redir->word); */
if (redir->n > 9)
return (bad_fd(redir->n));
i = 0;
while (g_redirmap[i].id)
{
DG("process redirect");
if (g_redirmap[i].id == redir->type)
{
if ((g_redirmap[i].f)(redir))
@ -51,7 +50,7 @@ int process_redirect(t_process *p)
}
redirs = redirs->next;
}
DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close);
/* DG("redirecting [%i:%i] [%i]", p->fdin, p->fdout, p->to_close); */
if (p->to_close != STDIN)
close(p->to_close);
if (p->fdin != STDIN)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:51:47 by jhalford ### ########.fr */
/* Updated: 2017/03/11 16:05:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,12 +20,18 @@ int process_setgroup(t_process *p, pid_t pid)
(void)p;
data = data_singleton();
if (!SH_HAS_JOBC(data->opts))
return (0);
/* if (!SH_HAS_JOBC(data->opts)) */
/* return (0); */
j = &data->exec.job;
/* DG("setpgid(%i, %i)", pid, j->pgid); */
setpgid(pid, j->pgid);
/* if (!j->pgid) */
/* j->pgid = getpid(); */
DG("setpgid(%i, %i)", pid, j->pgid);
if (setpgid(pid, j->pgid) == -1)
ft_dprintf(2, "{red}%s: internal setpgid() error{eoc}\n", SHELL_NAME);
if (pid == 0 && JOB_IS_FG(j->attrs))
{
DG("I'm taking the terminal !");
tcsetpgrp(STDIN, j->pgid);
}
return (0);
}

View file

@ -1,3 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_setsig.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 14:08:35 by jhalford #+# #+# */
/* Updated: 2017/03/11 14:08:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void process_setsig(void)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:22:00 by ariard ### ########.fr */
/* Updated: 2017/03/11 13:26:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:08:12 by wescande #+# #+# */
/* Updated: 2017/03/08 14:58:36 by wescande ### ########.fr */
/* Updated: 2017/03/11 13:27:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,12 +14,6 @@
t_itof g_setprocessmap[] =
{
{TK_NEWLINE, NULL},
{TK_SEMI, NULL},
{TK_AMP, NULL},
{TK_AND_IF, NULL},
{TK_OR_IF,NULL},
{TK_PIPE, NULL},
{TK_WHILE, &set_process_while},
{TK_IF, &set_process_if},
{TK_ELIF, NULL},

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:45:11 by jhalford ### ########.fr */
/* Updated: 2017/03/11 16:05:22 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,14 +19,15 @@ int job_addprocess(t_process *p)
jobc = &data_singleton()->jobc;
job = &data_singleton()->exec.job;
DG("adding pid=[%i] to job", p->pid);
if (IS_PIPESTART(*p))
{
job_update_id();
job->id = jobc->current_id;
/* job->pgid = SH_HAS_JOBC(data_singleton()->opts) ? p->pid : getpid(); */
job->pgid = p->pid;
ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job)));
}
DG("adding pid=[%i] to pgid=[%i]", p->pid, job->pgid);
job = jobc->first_job->content;
ft_lsteadd(&job->first_process, ft_lstnew(p, sizeof(*p)));
/* DG("[BG:%i]", JOB_IS_BG(job->attrs)); */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:45:32 by jhalford ### ########.fr */
/* Updated: 2017/03/11 14:17:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,9 @@ void job_update_status(void)
do
{
pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG);
if ((pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG)) == -1
&& errno != ECHILD)
ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", SHELL_NAME, errno);
DG("pid=[%d]", pid);
}
while (pid > 1 && !mark_process_status(pid, status));

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:48:38 by jhalford ### ########.fr */
/* Updated: 2017/03/11 16:00:09 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,8 +24,9 @@ int job_wait(int id)
DG("job wait id=[%i], pgid=[%i]", id, j->pgid);
do
{
pid = waitpid(-j->pgid, &status, WUNTRACED);
DG("pid=[%d]", pid);
if ((pid = waitpid(-j->pgid, &status, WUNTRACED)) == -1)
ft_dprintf(2, "{red}%s: waitpid error errno=%i{eoc}\n", SHELL_NAME, errno);
DG("waitpid->[%d]", pid);
}
while (pid > 1 && !mark_process_status(pid, status)
&& !job_is_stopped(id)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:27:05 by jhalford ### ########.fr */
/* Updated: 2017/03/11 15:39:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,9 +17,8 @@ int put_job_in_foreground(t_job *j, int cont)
t_jobc *jobc;
jobc = &data_singleton()->jobc;
DG("givving terminal to job [%i]", j->pgid);
DG("giving terminal to pgid->[%i]", j->pgid);
tcsetpgrp(STDIN, j->pgid);
/* tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); */
if (cont)
{
@ -30,11 +29,11 @@ int put_job_in_foreground(t_job *j, int cont)
job_wait(j->id);
job_remove(j->id);
if (SH_HAS_JOBC(data_singleton()->opts))
{
tcsetpgrp(STDIN, jobc->shell_pgid);
/* if (SH_HAS_JOBC(data_singleton()->opts)) */
/* { */
tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
/* } */
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/10 13:48:20 by jhalford ### ########.fr */
/* Updated: 2017/03/11 14:19:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,8 +26,6 @@ int data_init(void)
data->comp = NULL;
data->opts = 0;
exec_reset();
data->jobc.first_job = NULL;
data->jobc.current_id = 1;
data->lst_func = NULL;
data->heredoc_queue = NULL;
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:29:09 by ariard ### ########.fr */
/* Updated: 2017/03/11 13:13:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -72,8 +72,8 @@ int handle_instruction(int fd)
}
DG("Before execution:");
btree_print(STDBUG, ast, &ft_putast);
// if (ft_exec(&ast))
// return (1);
if (ft_exec(&ast))
return (1);
instruction_free(&token, &parser, &ast);
ft_add_str_in_history(lexer.str);
return (0);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/10 12:12:30 by jhalford ### ########.fr */
/* Updated: 2017/03/11 14:08:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,7 +34,7 @@ void shell_init(int ac, char **av)
signal(SIGTSTP, sigtstp_handler);
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, sigchld_handler);
signal(SIGCHLD, SIG_DFL);
*shell_pgid = getpid();
if (setpgid(*shell_pgid, *shell_pgid))
{