diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index c56fd5a4..e54018ed 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:49:35 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:34:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,5 +24,6 @@ int builtin_exit(const char *path, char *const argv[], char *const envp[]); int builtin_setenv(const char *path, char *const argv[], char *const envp[]); int builtin_unsetenv(const char *path, char *const argv[], char *const envp[]); int builtin_jobs(const char *path, char *const av[], char *const envp[]); +int builtin_fg(const char *path, char *const av[], char *const envp[]); #endif diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 2f5f338b..09861590 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/01/02 18:10:15 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 16:10:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 98b0c21c..513ceff3 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/01/02 18:10:03 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 16:10:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,6 +58,8 @@ int job_is_stopped(int id); int job_is_completed(int id); void job_remove(int id); void job_free(void *content, size_t content_size); +void job_kill_all(void); +void mark_job_as_running (t_job *j); int process_mark_status(pid_t pid, int status); int put_job_in_foreground(t_job *job, int cont); diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index e112ae6d..e1bfea6f 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2016/12/13 17:51:07 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 16:10:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,7 @@ # include # include # include +# include enum e_mode diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index af3a7799..9fd927a8 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2016/12/13 18:00:26 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 16:00:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,28 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) { - int status; + int status; + static int notified = 0; + t_jobc *jobc; + t_list *jlist; + (void)envp; (void)path; + jobc = &data_singleton()->jobc; + jlist = jobc->first_job; + if (jlist && !notified) + { + notified = 1; + ft_dprintf(2, "{red}%s: you have live jobs (running or suspended).{eoc}\n", SHELL_NAME); + return (0); + } if (av[1]) status = ft_atoi(av[1]); else - status = ft_atoi(ft_getenv((char**)envp, "?")); + { + /* status = ft_atoi(ft_getenv(data_singleton()->env, "?")); */ + status = 0; + } exit(status); return (0); } diff --git a/42sh/src/builtin/is_builtin.c b/42sh/src/builtin/is_builtin.c index 80963e91..f0f653a5 100644 --- a/42sh/src/builtin/is_builtin.c +++ b/42sh/src/builtin/is_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:48:23 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:30:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ t_stof g_builtin[] = { {"env", &builtin_env}, {"exit", &builtin_exit}, {"jobs", &builtin_jobs}, + {"fg", &builtin_fg}, {NULL, NULL}, }; diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index 73248fcf..5998f3b4 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/01/02 19:10:01 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:24:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index 5ec96f8a..f9af2ebe 100644 --- a/42sh/src/exec/exec_pipe.c +++ b/42sh/src/exec/exec_pipe.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */ -/* Updated: 2016/12/13 17:15:22 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 11:03:05 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 33c2dbe3..a553c73f 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: 2016/12/15 15:18:21 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 11:03:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 1ac985b2..6bafdc78 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/01/03 18:01:30 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:23:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,13 +32,19 @@ int launch_process(t_process *p) if (p->attributes & (PROCESS_BINARY | PROCESS_SCRIPT) && access(p->path, X_OK) == -1) { - ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, p->av[0]); + ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->av[0]); return (-1); } pid = fork(); if (pid == 0) { process_setgroup(p); + signal(SIGINT, SIG_DFL); + signal(SIGQUIT, SIG_DFL); + signal(SIGTSTP, sigtstp_handler); + signal(SIGTTIN, SIG_DFL); + signal(SIGTTOU, SIG_DFL); + signal(SIGCHLD, SIG_DFL); process_redirect(p); (*p->execf)(p->path, p->av, data_singleton()->env); exit(42); diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index 88be05e4..9a947b2f 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/01/03 18:04:09 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:23:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,13 @@ int process_setgroup(t_process *p) if (job->pgid == 0) job->pgid = pid; DG("job->pgid=%i", job->pgid); - setpgid(pid, job->pgid); + if (setpgid(pid, job->pgid)) + ft_dprintf(2, "{red}setpgid failed{eoc}\n"); if (JOB_IS_FG(job->attributes)) - tcsetpgrp(STDIN_FILENO, job->pgid); + { + signal(SIGTTOU, SIG_IGN); + tcsetpgrp(STDIN, job->pgid); + signal(SIGTTOU, SIG_DFL); + } return (0); } diff --git a/42sh/src/exec/set_exitstatus.c b/42sh/src/exec/set_exitstatus.c index eb22a1ee..584abdcc 100644 --- a/42sh/src/exec/set_exitstatus.c +++ b/42sh/src/exec/set_exitstatus.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2016/12/12 17:54:19 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:58:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/builtin_fg.c b/42sh/src/job-control/builtin_fg.c new file mode 100644 index 00000000..d538d039 --- /dev/null +++ b/42sh/src/job-control/builtin_fg.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* builtin_fg.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ +/* Updated: 2017/01/08 15:21:23 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "job_control.h" + +int builtin_fg(const char *path, char *const av[], char *const envp[]) +{ + t_jobc *jobc; + t_job *job; + + (void)path; + (void)envp; + (void)av; + jobc = &data_singleton()->jobc; + job = jobc->first_job->content; + if (job) + { + mark_job_as_running(job); + put_job_in_foreground(job, 1); + } + return (0); +} diff --git a/42sh/src/job-control/builtin_jobs.c b/42sh/src/job-control/builtin_jobs.c index 7571f0e9..b0c45498 100644 --- a/42sh/src/job-control/builtin_jobs.c +++ b/42sh/src/job-control/builtin_jobs.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 17:43:01 by jhalford #+# #+# */ -/* Updated: 2017/01/03 18:13:47 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:33:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/do_job_notification.c b/42sh/src/job-control/do_job_notification.c index c902b1ec..80db0521 100644 --- a/42sh/src/job-control/do_job_notification.c +++ b/42sh/src/job-control/do_job_notification.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */ -/* Updated: 2017/01/02 18:21:20 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:00:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,8 +36,8 @@ int do_job_notification(void) else if (job_is_stopped(j->id) && !(j->attributes & JOB_NOTIFIED)) { ret = 1; - job_notify_change(j->id, 8); - j->attributes &= JOB_NOTIFIED; + job_notify_change(j->id, -1); + j->attributes |= JOB_NOTIFIED; } jlist = jlist->next; } diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index b3d24661..2dd27595 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/01/03 18:16:00 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:41:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ int job_addprocess(t_process *p) { job_update_id(); job->id = jobc->current_id; + job->pgid = p->pid; ft_lstadd(&jobc->first_job, ft_lstnew(job, sizeof(*job))); DG("added new job [%i]", job->id); } diff --git a/42sh/src/job-control/job_is_completed.c b/42sh/src/job-control/job_is_completed.c index 7bd9dc0f..4fba4555 100644 --- a/42sh/src/job-control/job_is_completed.c +++ b/42sh/src/job-control/job_is_completed.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:10:20 by jhalford #+# #+# */ -/* Updated: 2017/01/03 18:12:26 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:04:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_is_stopped.c b/42sh/src/job-control/job_is_stopped.c index d707dbb3..e3bddaa1 100644 --- a/42sh/src/job-control/job_is_stopped.c +++ b/42sh/src/job-control/job_is_stopped.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:06:45 by jhalford #+# #+# */ -/* Updated: 2016/12/15 12:42:02 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:39:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_kill_all.c b/42sh/src/job-control/job_kill_all.c new file mode 100644 index 00000000..11f343a7 --- /dev/null +++ b/42sh/src/job-control/job_kill_all.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* job_kill_all.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/08 15:36:56 by jhalford #+# #+# */ +/* Updated: 2017/01/08 15:44:07 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "job_control.h" + +void job_kill_all(void) +{ + t_jobc *jobc; + t_list *jlist; + t_job *job; + + jobc = &data_singleton()->jobc; + jlist = jobc->first_job; + while (jlist) + { + job = jlist->content; + kill(-job->pgid, SIGKILL); + jlist = jlist->next; + } +} diff --git a/42sh/src/job-control/job_notify_change.c b/42sh/src/job-control/job_notify_change.c index 3865dfd7..a86561a2 100644 --- a/42sh/src/job-control/job_notify_change.c +++ b/42sh/src/job-control/job_notify_change.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 15:04:03 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:45:36 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 13:52:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,8 @@ void job_notify_change(int id, int status) { t_job *job; t_jobc *jobc; + t_list *plist; + t_process *p; char rank; rank = ' '; @@ -30,13 +32,27 @@ void job_notify_change(int id, int status) rank = '-'; } ft_printf("{mag}[%i] %c ", id, rank); - if (status == 0) - ft_printf("{gre}done{mag}"); - else if (status == 8) + job = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; + if (status == -1) ft_printf("{red}stopped{mag}"); - else if (status == 9) - ft_printf("{red}killed{mag}"); else - ft_printf("exit %i", status); - ft_printf("\t 'process command goes here'{eoc}\n"); + { + plist = job->first_process; + p = ft_lstlast(job->first_process)->content; + if (p->status == 0) + ft_printf("{gre}done{mag}"); + else + ft_printf("{red}exit %i{mag}", p->status); + } + ft_printf("\t "); + plist = job->first_process; + while (plist) + { + p = plist->content; + ft_sstrprint(p->av, ' '); + if (plist->next) + ft_printf(" |"); + plist = plist->next; + } + ft_printf("{eoc}\n"); } diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 86cf4ee2..697cc018 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/02 18:15:03 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:04:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,13 +17,18 @@ void job_remove(int id) t_jobc *jobc; jobc = &data_singleton()->jobc; - DG("job_remove"); - if (id < data_singleton()->jobc.current_id) + if (job_is_completed(id)) { - data_singleton()->jobc.current_id = id; - DG("ID_UPDATE(downgrade):%i", id); + DG("job_remove"); + if (id < data_singleton()->jobc.current_id) + { + data_singleton()->jobc.current_id = id; + DG("ID_UPDATE(downgrade):%i", id); + } + else + DG("ID_UPDATE(no downgrade): %i/%i", id, data_singleton()->jobc.current_id); + ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free); } else - DG("ID_UPDATE(no downgrade): %i/%i", id, data_singleton()->jobc.current_id); - ft_lst_delif(&jobc->first_job, &id, job_cmp_id, job_free); + DG("job_remove failed (not completed)"); } diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 6b5f77de..9a892b03 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/01/02 17:32:43 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 16:00:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,5 @@ int job_wait(int id) pid = waitpid(WAIT_ANY, &status, WUNTRACED); DG("waitpid done"); } - DG("stopped: %i", job_is_stopped(id)); - DG("completed: %i", job_is_completed(id)); return (0); } diff --git a/42sh/src/job-control/mark_job_as_running.c b/42sh/src/job-control/mark_job_as_running.c new file mode 100644 index 00000000..4a1c679e --- /dev/null +++ b/42sh/src/job-control/mark_job_as_running.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mark_job_as_running.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */ +/* Updated: 2017/01/08 14:53:34 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "job_control.h" + +void mark_job_as_running (t_job *j) +{ + t_list *plist; + t_process *p; + + plist = j->first_process; + while (plist) + { + p = plist->content; + p->attributes &= ~PROCESS_STOPPED; + plist = plist->next; + } + j->attributes &= ~JOB_NOTIFIED; +} diff --git a/42sh/src/job-control/process_mark_status.c b/42sh/src/job-control/process_mark_status.c index 85e709e6..1ea54e4b 100644 --- a/42sh/src/job-control/process_mark_status.c +++ b/42sh/src/job-control/process_mark_status.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/01/03 18:01:15 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:55:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,15 +18,17 @@ int process_mark_status(pid_t pid, int status) if (pid > 1) { - DG("marking: pid=%i, status=%i", pid, status); if ((p = job_getprocess(pid))) { - DG("found process pid=%i", pid); p->status = status; if (WIFSTOPPED(status)) + { + DG("marking: pid=%i, status=%i (stopped)", pid, status); p->attributes |= PROCESS_STOPPED; + } else { + DG("marking: pid=%i, status=%i (completed)", pid, status); p->attributes |= PROCESS_COMPLETED; if (WIFSIGNALED(status)) ft_printf("{mag}%d: Terminated by signal %d.\n{eoc}", diff --git a/42sh/src/job-control/put_job_in_background.c b/42sh/src/job-control/put_job_in_background.c index 38542ffc..a23dee5e 100644 --- a/42sh/src/job-control/put_job_in_background.c +++ b/42sh/src/job-control/put_job_in_background.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 15:03:29 by jhalford #+# #+# */ -/* Updated: 2016/12/15 17:53:24 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 13:24:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index a7a9185d..ede7df10 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/01/02 18:15:09 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:33:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,26 +17,32 @@ int put_job_in_foreground(t_job *job, int cont) t_jobc *jobc; jobc = &data_singleton()->jobc; - /* Put the job into the foreground. */ - tcsetpgrp(STDIN_FILENO, job->pgid); - /* Send the job a continue signal, if necessary. */ + /* Put the job into the foreground. */ + signal(SIGTTOU, SIG_IGN); + if (tcsetpgrp(STDIN, job->pgid) == -1) + DG("couldn't put process in control. errno=%i, pgid=%i", errno, job->pgid); + else + DG("pgid %i is now in control.", job->pgid); + signal(SIGTTOU, sigttou_handler); + /* Send the job a continue signal, if necessary. */ if (cont) { - tcsetattr (STDIN_FILENO, TCSADRAIN, &job->tmodes); + tcsetattr (STDIN, TCSANOW, &job->tmodes); if (kill(-job->pgid, SIGCONT) < 0) perror("kill (SIGCONT)"); } /* Wait for it to report. */ DG("gonna wait for job id=%i", job->id); - /* if (!(p->attributes & PROCESS_BUILTIN && p->fdout == STDOUT)) */ job_wait(job->id); job_remove(job->id); - /* Put the shell back in the foreground. */ - tcsetpgrp(STDIN_FILENO, jobc->shell_pgid); + /* Put the shell back in the foreground. */ + signal(SIGTTOU, SIG_IGN); + tcsetpgrp(STDIN, jobc->shell_pgid); + signal(SIGTTOU, sigttou_handler); - /* Restore the shell’s terminal modes. */ - tcgetattr(STDIN_FILENO, &job->tmodes); - tcsetattr(STDIN_FILENO, TCSADRAIN, &jobc->shell_tmodes); + /* Restore the shell’s terminal modes. */ + tcgetattr(STDIN, &job->tmodes); + tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); return (0); } diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index 4f587324..c750bba6 100644 --- a/42sh/src/job-control/sigchld_handler.c +++ b/42sh/src/job-control/sigchld_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 17:37:56 by jhalford #+# #+# */ -/* Updated: 2017/01/02 18:10:01 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 11:28:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,8 +18,9 @@ void sigchld_handler(int signo) (void)signo; data = data_singleton(); - DG("got asynchronous notification (SIGCHLD)"); + DG("got SIGCHLD"); /* if (do_job_notification()) */ /* ft_putstr(SHELL_PROMPT); */ - job_update_status(); + if (data_singleton()->mode != MODE_EXEC) + job_update_status(); } diff --git a/42sh/src/job-control/sigtstp_handler.c b/42sh/src/job-control/sigtstp_handler.c index 95814e84..5c02ec84 100644 --- a/42sh/src/job-control/sigtstp_handler.c +++ b/42sh/src/job-control/sigtstp_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:30:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigttou_handler.c b/42sh/src/job-control/sigttou_handler.c index a0d318d6..a999d1e1 100644 --- a/42sh/src/job-control/sigttou_handler.c +++ b/42sh/src/job-control/sigttou_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:53 by jhalford #+# #+# */ -/* Updated: 2016/12/10 18:20:57 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 13:24:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_key_ctrl_d.c b/42sh/src/line-editing/ft_key_ctrl_d.c index 1b586098..037f084b 100644 --- a/42sh/src/line-editing/ft_key_ctrl_d.c +++ b/42sh/src/line-editing/ft_key_ctrl_d.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:44:24 by jhalford #+# #+# */ -/* Updated: 2016/12/12 17:40:27 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:56:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,7 @@ int ft_key_ctrl_d(t_data *data, char *buf) (void)data; (void)buf; ft_putendl("exit"); - exit(0); + builtin_exit("exit", (char *[]){"exit", NULL}, data_singleton()->env); + ft_prompt(); + return (0); } diff --git a/42sh/src/line-editing/ft_prompt.c b/42sh/src/line-editing/ft_prompt.c index 548fb4fe..5f37d810 100644 --- a/42sh/src/line-editing/ft_prompt.c +++ b/42sh/src/line-editing/ft_prompt.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 14:22:34 by jhalford #+# #+# */ -/* Updated: 2017/01/02 18:19:24 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 16:00:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/ft_set_termios.c b/42sh/src/line-editing/ft_set_termios.c index 04fa8453..b0277f51 100644 --- a/42sh/src/line-editing/ft_set_termios.c +++ b/42sh/src/line-editing/ft_set_termios.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:14:09 by jhalford #+# #+# */ -/* Updated: 2016/12/12 17:35:27 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:26:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/input_init.c b/42sh/src/line-editing/input_init.c index 84ce1af7..6ef69843 100644 --- a/42sh/src/line-editing/input_init.c +++ b/42sh/src/line-editing/input_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 13:35:03 by jhalford #+# #+# */ -/* Updated: 2016/12/12 17:35:15 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:27:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/sigint_handler.c b/42sh/src/line-editing/sigint_handler.c index 123c4d41..7d45df67 100644 --- a/42sh/src/line-editing/sigint_handler.c +++ b/42sh/src/line-editing/sigint_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */ -/* Updated: 2016/12/10 15:31:56 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:12:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,13 +14,6 @@ void sigint_handler(int signo) { - t_job *job; - (void)signo; - job = &data_singleton()->exec.job; - DG("got SIGINT; job->pgid=%i", job->pgid); - if (job->pgid) - kill(job->pgid, SIGINT); - if (kill(job->pgid, 0) == 0) - ft_putchar('\n'); + DG("got SIGINT"); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 9443e93a..e6911ed2 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: 2016/12/13 13:38:33 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 14:26:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_exit.c b/42sh/src/main/shell_exit.c index 3d12fa63..882a3f31 100644 --- a/42sh/src/main/shell_exit.c +++ b/42sh/src/main/shell_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:37:04 by jhalford #+# #+# */ -/* Updated: 2016/12/12 17:51:20 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:55:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,9 @@ extern char *BC; void shell_exit(void) { - DG("cleanup. char * UP at %p", UP); - DG("cleanup. char * BC at %p", BC); + /* DG("cleanup. char * UP at %p", UP); */ + /* DG("cleanup. char * BC at %p", BC); */ data_exit(); + /* job_kill_all(); */ tcsetattr(0, TCSANOW, &data_singleton()->jobc.shell_tmodes); } diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 10d4e773..70a149ef 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2016/12/13 15:14:35 by jhalford ### ########.fr */ +/* Updated: 2017/01/08 15:11:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,13 +19,13 @@ void shell_init(void) shell_pgid = &data_singleton()->jobc.shell_pgid; data_init(); atexit(&shell_exit); - if (isatty(STDIN_FILENO)) + if (isatty(STDIN)) { - while (tcgetpgrp(STDIN_FILENO) != (*shell_pgid = getpgrp())) + while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp())) kill(-*shell_pgid, SIGTTIN); signal(SIGINT, sigint_handler); signal(SIGQUIT, SIG_IGN); - signal(SIGTSTP, sigtstp_handler); + signal(SIGTSTP, SIG_IGN); signal(SIGTTIN, sigttin_handler); signal(SIGTTOU, sigttou_handler); signal(SIGCHLD, sigchld_handler); @@ -35,7 +35,7 @@ void shell_init(void) ft_dprintf(2, "Couldnt put the shell in it's own process group"); exit (1); } - tcsetpgrp(STDIN_FILENO, *shell_pgid); - tcgetattr(STDIN_FILENO, &data_singleton()->jobc.shell_tmodes); + tcsetpgrp(STDIN, *shell_pgid); + tcgetattr(STDIN, &data_singleton()->jobc.shell_tmodes); } }