From 8b88d41ed9556819936ffdd4480f348b8a7c68d4 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 3 Mar 2017 19:05:42 +0100 Subject: [PATCH] trying to make files work --- 42sh/sample/ls | 1 + 42sh/src/exec/exec_command.c | 16 +++++---- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/exec/mark_process_status.c | 4 +-- 42sh/src/job-control/add_new_job.c | 3 +- 42sh/src/job-control/job_getprocess.c | 2 +- 42sh/src/job-control/job_remove.c | 2 +- 42sh/src/job-control/job_update_status.c | 8 ++--- 42sh/src/job-control/job_wait.c | 14 +------- 42sh/src/job-control/put_job_in_foreground.c | 37 ++++++++++++-------- 42sh/src/main/data_init.c | 2 +- 42sh/src/main/main.c | 11 +++--- 12 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 42sh/sample/ls diff --git a/42sh/sample/ls b/42sh/sample/ls new file mode 100644 index 00000000..9e2740c6 --- /dev/null +++ b/42sh/sample/ls @@ -0,0 +1 @@ +ls diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 32162a94..b63752a6 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:50:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:02:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -76,13 +76,15 @@ int exec_cmd(t_btree **ast) 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_notify_new(job); - put_job_in_background(job, 0); + add_new_job(job); + if (JOB_IS_FG(job->attrs)) + put_job_in_foreground(job, 0); + else + { + job_notify_new(job); + put_job_in_background(job, 0); + } } return (0); } diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 1c46fea9..b4b3c578 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:26:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:03:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 2665128d..32679242 100644 --- a/42sh/src/exec/mark_process_status.c +++ b/42sh/src/exec/mark_process_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:32:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:02:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,9 @@ int mark_process_status(pid_t pid, int status) t_list *plist; t_process *p; - DG("PMS pid=%i,s=%i", pid, status); if (pid > 1) { + DG("MPS pid=%i,s=%i", pid, status); if ((plist = job_getprocess(pid))) { p = plist->content; diff --git a/42sh/src/job-control/add_new_job.c b/42sh/src/job-control/add_new_job.c index 4343cb0d..3e345d1d 100644 --- a/42sh/src/job-control/add_new_job.c +++ b/42sh/src/job-control/add_new_job.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:51:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 18:54:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,5 @@ int add_new_job(t_job *job) 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 = jobc->first_job->content; return (0); } diff --git a/42sh/src/job-control/job_getprocess.c b/42sh/src/job-control/job_getprocess.c index a5d421c3..52bb8229 100644 --- a/42sh/src/job-control/job_getprocess.c +++ b/42sh/src/job-control/job_getprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 15:07:30 by jhalford #+# #+# */ -/* Updated: 2017/01/31 15:07:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 19:03:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 9c94db11..2ffe9c8a 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ -/* Updated: 2017/01/31 13:44:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 18:53:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_update_status.c b/42sh/src/job-control/job_update_status.c index 6ab2df78..5e314792 100644 --- a/42sh/src/job-control/job_update_status.c +++ b/42sh/src/job-control/job_update_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:56:11 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:37:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 18:56:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ void job_update_status(void) int status; pid_t pid; - pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); - while (!mark_process_status(pid, status)) - pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG); + do + pid = waitpid (WAIT_ANY, &status, WUNTRACED|WNOHANG); + while (!mark_process_status (pid, status)); } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index eb5a1546..6a1c380a 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/03 18:38:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 18:54:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,18 +18,6 @@ int job_wait(int id) int status; DG("job wait [%i]", id); - /* if (job_is_stopped(id)) */ - /* return (0); */ - /* job_update_status(); */ - /* DG("after update status"); */ - /* pid = waitpid(WAIT_ANY, &status, WUNTRACED); */ - /* while (!process_mark_status(pid, status) */ - /* && !job_is_completed(id) */ - /* && !job_is_stopped(id)) */ - /* { */ - - /* pid = waitpid(WAIT_ANY, &status, WUNTRACED); */ - /* } */ do pid = waitpid(WAIT_ANY, &status, WUNTRACED); while (!mark_process_status(pid, status) diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 50b18485..71411673 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/03 18:52:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 18:57:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,21 +16,28 @@ int put_job_in_foreground(t_job *j, int cont) { t_jobc *jobc; - jobc = &data_singleton()->jobc; - tcsetpgrp(STDIN, j->pgid); - tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); - if (cont) + if (SH_HAS_JOBC(data_singleton()->opts)) { - tcsetattr(STDIN, TCSADRAIN, &j->tmodes); - if (kill(-j->pgid, SIGCONT) < 0) - DG("kill(SIGCONT) failed"); + jobc = &data_singleton()->jobc; + + tcsetpgrp(STDIN, j->pgid); + tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); + if (cont) + { + tcsetattr(STDIN, TCSADRAIN, &j->tmodes); + if (kill(-j->pgid, SIGCONT) < 0) + DG("kill(SIGCONT) failed"); + } + job_wait(j->id); + job_remove(j->id); + + tcsetpgrp(STDIN, jobc->shell_pgid); + + tcgetattr(STDIN, &j->tmodes); + tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); + tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); } - job_wait(j->id); - job_remove(j->id); - - tcsetpgrp(STDIN, jobc->shell_pgid); - - tcgetattr(STDIN, &j->tmodes); - tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); + else + job_wait(j->id); return (0); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 1aa6c777..591cc8c0 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/03 17:39:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/03 18:55:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 9f6b966d..f79cb83a 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/03 18:33:40 by wescande ### ########.fr */ +/* Updated: 2017/03/03 19:05:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -97,7 +97,10 @@ int get_input_fd() return (fd); } else if ((file = shell_get_avdata())) - return (open(file, O_RDONLY)); + { + if (fd = open(file, O_RDONLY)) + return (fd); + } else return (STDIN); } @@ -108,13 +111,13 @@ int main(int ac, char **av) setlocale(LC_ALL, ""); shell_init(ac, av); - DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s", - SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); if ((fd = get_input_fd()) < 0) { ft_printf("{red}%s: No such file or directory\n{eoc}", SHELL_NAME); return (1); } + DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s, fd=[%i]", + SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd); while (handle_instruction(fd) == 0) { // lexer_clean;