diff --git a/42sh/Makefile b/42sh/Makefile index acf4b7a3..8c56fe00 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -94,6 +94,7 @@ exec/launch_until.c\ exec/launch_while.c\ exec/mark_process_status.c\ exec/node_copy.c\ +exec/process_empty.c\ exec/process_redirect.c\ exec/process_reset.c\ exec/process_resetfds.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 807bda54..64729cf1 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/10 18:09:53 by ariard ### ########.fr */ +/* Updated: 2017/03/13 17:40:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -93,6 +93,7 @@ enum e_process_type PROCESS_IF, PROCESS_FOR, PROCESS_CASE, + PROCESS_EMPTY, PROCESS_MAX }; @@ -187,6 +188,7 @@ int launch_file(t_process *p); int launch_builtin(t_process *p); int launch_subshell(t_process *p); int launch_function(t_process *p); +int launch_empty(t_process *p); /* ** Mapping pour set les process diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 00985ade..a5af071d 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:29:46 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:19:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index de370722..9126b48d 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/13 14:37:01 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:40:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ int exec_leaf(t_btree **ast) return (1); if (!(launch_process(&p))) { - DG("forked pid=[%i], name=[%s]", p.pid, p.data.cmd.av[0]); + DG("check"); + DG("forked pid=[%i]", p.pid); job_addprocess(&p); /* DG("[IS_BG->%i]", JOB_IS_BG(job->attrs)); */ if (IS_PIPEEND(p)) diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 86d96c83..ff5d9a18 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/13 13:28:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:40:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 3d6a30ed..5e019ad0 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:43:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:38:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,12 +23,14 @@ t_itof g_launchmap[] = {PROCESS_IF, launch_if}, {PROCESS_FOR, launch_for}, {PROCESS_CASE, launch_case}, + {PROCESS_EMPTY, launch_empty}, }; int launch_process(t_process *p) { int pid; + DG("p->type=%i", p->type); if (p->type >= PROCESS_MAX) return (-1); if (!g_launchmap[p->type].f) @@ -41,10 +43,13 @@ int launch_process(t_process *p) return (1); } p->pid = pid; + DG("check"); process_setgroup(p, pid); + DG("check"); if (p->fdin != STDIN) close(p->fdin); if (p->fdout != STDOUT) close(p->fdout); + DG("check"); return (0); } diff --git a/42sh/src/exec/process_empty.c b/42sh/src/exec/process_empty.c new file mode 100644 index 00000000..cc10fd2a --- /dev/null +++ b/42sh/src/exec/process_empty.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_empty.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */ +/* Updated: 2017/03/13 17:31:05 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int launch_empty(t_process *p) +{ + int pid; + + pid = fork(); + if (pid == 0) + { + if (process_redirect(p)) + exit (1); + process_setgroup(p, 0); + process_setsig(); + exec_reset(); + DG("empty exit"); + exit(0); + } + else if (pid > 0) + return (pid); + else if (pid == -1) + ft_dprintf(2, "{red}%s: internal fork error{eoc}\n", SHELL_NAME); + return (0); +} + diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index 13810ae4..2298fecc 100644 --- a/42sh/src/exec/redirect_great.c +++ b/42sh/src/exec/redirect_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ -/* Updated: 2017/03/06 14:58:57 by ariard ### ########.fr */ +/* Updated: 2017/03/13 17:40:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,6 @@ int redirect_great(t_redir* redir) int fdnew; fdnew = redir->n; - DG("redir great"); if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) { diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index 2a1e6809..eb01ddee 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/03/06 15:05:40 by ariard ### ########.fr */ +/* Updated: 2017/03/13 17:41:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,10 +18,9 @@ int redirect_less(t_redir *redir) int fdnew; fdnew = redir->n; - DG("redirect less"); if ((fdold = open(redir->word, O_RDONLY)) < 0) { - ft_dprintf(2, "{red}%s: no such file or directory: %s{eoc}\n", + ft_dprintf(2, "{red}%s: %s: no such file or directory\n", SHELL_NAME, redir->word); exit (1); } diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 4461fc05..2e54d187 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:18:11 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:38:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,7 +31,7 @@ int set_process(t_process *p, t_btree *ast) if (op == TK_PIPE) { pipe(fds); - DG("[%i] -> PIPE -> [%i]", fds[PIPE_WRITE], fds[PIPE_READ]); + /* DG("[%i] -> PIPE -> [%i]", fds[PIPE_WRITE], fds[PIPE_READ]); */ } p->fdin = exec->fdin; p->to_close = fds[PIPE_READ]; diff --git a/42sh/src/exec/set_process_cmd.c b/42sh/src/exec/set_process_cmd.c index 76b4b098..64666f0c 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/set_process_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/08 18:49:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:40:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,10 @@ int set_process_cmd(t_process *p, t_btree *ast) t_btree *func; if (!(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1))) - return (1); + { + p->type = PROCESS_EMPTY; + return (0); + } p->data.cmd.path = NULL; p->data.cmd.execf = NULL; p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); diff --git a/42sh/src/exec/set_process_map.c b/42sh/src/exec/set_process_map.c index 581d5add..0c685464 100644 --- a/42sh/src/exec/set_process_map.c +++ b/42sh/src/exec/set_process_map.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:08:12 by wescande #+# #+# */ -/* Updated: 2017/03/11 13:27:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:39:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/token_to_argv.c b/42sh/src/exec/token_to_argv.c index 10b2c192..53c2a959 100644 --- a/42sh/src/exec/token_to_argv.c +++ b/42sh/src/exec/token_to_argv.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:55:53 by wescande #+# #+# */ -/* Updated: 2017/03/07 15:56:25 by wescande ### ########.fr */ +/* Updated: 2017/03/13 17:23:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index ab75673e..acefe6f1 100644 --- a/42sh/src/job-control/job_wait.c +++ b/42sh/src/job-control/job_wait.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 11:49:05 by jhalford #+# #+# */ -/* Updated: 2017/03/13 15:29:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:36:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index 40a156b4..e145e733 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/08 20:13:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:33:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ t_itof g_freemap[] = {PROCESS_IF, process_free_cond}, {PROCESS_FOR, process_free_list}, {PROCESS_CASE, process_free_list}, + {PROCESS_EMPTY, NULL}, }; void process_free(void *content, size_t content_size) @@ -31,10 +32,13 @@ void process_free(void *content, size_t content_size) p = content; (void)content_size; + DG("gonna free"); if (p->type >= PROCESS_MAX) return ; + DG("gonna free"); if (g_freemap[p->type].f) (g_freemap[p->type].f)(p); + DG("gonna free"); ft_lstdel(&p->redirs, redir_free); free(p); } diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 726d899e..9b2af2f3 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/13 14:03:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 17:37:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,9 +26,11 @@ int put_job_in_foreground(t_job *j, int cont) if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); } - /* if (SH_IS_INTERACTIVE(data_singleton()->opts)) */ + DG("check"); job_wait(j->id); + DG("check"); job_remove(j->id); + DG("check"); if (SH_IS_INTERACTIVE(data_singleton()->opts)) { tcsetpgrp(STDIN, jobc->shell_pgid); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index df085593..a14ebe64 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/13 16:42:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 16:43:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */