diff --git a/42sh/.gitignore b/42sh/.gitignore index 43b2b5b2..23a58579 100644 --- a/42sh/.gitignore +++ b/42sh/.gitignore @@ -2,4 +2,5 @@ minishell 21sh 42sh out +debug *.dSYM diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 335cc0a4..eb6b08f2 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:02:25 by sbenning #+# #+# */ -/* Updated: 2017/01/10 17:01:47 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:59:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index 0c7a7813..271b8312 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: 2017/01/10 13:12:41 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:59:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index fd5c78c4..f3426bc8 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/10 13:16:45 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:47:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/job_wait.c b/42sh/src/job-control/job_wait.c index 9a892b03..8e3f6bca 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/08 16:00:23 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:58:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,12 @@ int job_wait(int id) pid_t pid; int status; + DG("job wait"); if (job_is_stopped(id) || job_is_completed(id)) return (0); + DG("waitpid now"); pid = waitpid(WAIT_ANY, &status, WUNTRACED); + DG("waitpid done"); while (!process_mark_status(pid, status) && !job_is_stopped(id) && !job_is_completed(id)) diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index b4df9de0..f49216e4 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/10 17:07:29 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:47:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/sigchld_handler.c b/42sh/src/job-control/sigchld_handler.c index 210f52a2..11800df5 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/10 12:33:18 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:59:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,6 @@ void sigchld_handler(int signo) /* DG("got SIGCHLD"); */ /* if (do_job_notification()) */ /* ft_putstr(SHELL_PROMPT); */ - if (data_singleton()->mode != MODE_EXEC) - job_update_status(); + /* if (data_singleton()->mode != MODE_EXEC) */ + /* job_update_status(); */ } diff --git a/42sh/src/job-control/sigint_handler.c b/42sh/src/job-control/sigint_handler.c index f15da9d3..de5ec7dd 100644 --- a/42sh/src/job-control/sigint_handler.c +++ b/42sh/src/job-control/sigint_handler.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/10 15:14:47 by jhalford #+# #+# */ -/* Updated: 2017/01/09 16:16:20 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:24:06 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,5 +15,5 @@ void sigint_handler(int signo) { (void)signo; - DG("got SIGINT"); + DG("got SIGINT in process %i", getpid()); } diff --git a/42sh/src/job-control/sigtstp_handler.c b/42sh/src/job-control/sigtstp_handler.c index ce6a84ce..93b796f4 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: 2017/01/10 16:49:33 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 18:02:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,5 +19,4 @@ void sigtstp_handler(int signo) (void)signo; jobc = &data_singleton()->jobc; DG("got SIGTSTP in process %i", getpid()); - kill(jobc->shell_pgid, SIGCONT); } diff --git a/42sh/src/line-editing/curs_clear.c b/42sh/src/line-editing/curs_clear.c index af2f6b03..cb3d0694 100644 --- a/42sh/src/line-editing/curs_clear.c +++ b/42sh/src/line-editing/curs_clear.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 17:28:50 by sbenning #+# #+# */ -/* Updated: 2016/12/09 16:51:33 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 17:20:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/curs_setup.c b/42sh/src/line-editing/curs_setup.c index 411b9abf..c8a0184a 100644 --- a/42sh/src/line-editing/curs_setup.c +++ b/42sh/src/line-editing/curs_setup.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 16:36:43 by sbenning #+# #+# */ -/* Updated: 2016/12/09 16:46:01 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 18:03:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/curs_term_setup.c b/42sh/src/line-editing/curs_term_setup.c index 53aeb0b0..38e7f992 100644 --- a/42sh/src/line-editing/curs_term_setup.c +++ b/42sh/src/line-editing/curs_term_setup.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 16:50:26 by sbenning #+# #+# */ -/* Updated: 2017/01/10 11:54:47 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 18:04:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,7 @@ int curs_term_setup(void) if (tcgetattr(0, single) < 0) return (-1); term = *single; - term.c_lflag &= ~(ECHO | ICANON); + term.c_lflag &= ~(ECHO | ICANON | ISIG); term.c_cc[VTIME] = 0; term.c_cc[VMIN] = 1; if (tcsetattr(0, TCSADRAIN, &term) < 0) @@ -51,8 +51,11 @@ int curs_term_setup(void) int curs_term_cleanup(void) { struct termios *single; + struct termios term; single = curs_term(); + term = *single; + term.c_lflag |= ECHO | ICANON | ISIG; if (tcsetattr(0, TCSADRAIN, single) < 0) return (-1); return (0); diff --git a/42sh/src/line-editing/rl_clear_function.c b/42sh/src/line-editing/rl_clear_function.c index 190b05c1..6782b79c 100644 --- a/42sh/src/line-editing/rl_clear_function.c +++ b/42sh/src/line-editing/rl_clear_function.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/09 13:34:29 by sbenning #+# #+# */ -/* Updated: 2016/12/09 13:50:20 by sbenning ### ########.fr */ +/* Updated: 2017/01/10 17:46:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/rl_set_termios.c b/42sh/src/line-editing/rl_set_termios.c deleted file mode 100644 index 3aacb524..00000000 --- a/42sh/src/line-editing/rl_set_termios.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* rl_set_termios.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/10 17:00:16 by jhalford #+# #+# */ -/* Updated: 2017/01/10 17:02:50 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int rl_set_termios(int input_mode) -{ - struct termios term; - - if (tcgetattr(0, &term) == -1) - { - DG("tcgetattr failed, errno=%i", errno); - return (-1); - } - if (input_mode) - term.c_lflag &= ~(ICANON) & ~(ISIG) & ~(ECHO); - else - term.c_lflag |= ICANON | ISIG | ECHO; - term.c_cc[VMIN] = 1; - term.c_cc[VTIME] = 0; - if (tcsetattr(0, TCSADRAIN, &term) == -1) - return (-1); - return (0); -} diff --git a/42sh/src/line-editing/rl_setup.c b/42sh/src/line-editing/rl_setup.c index 3f76ca34..d878f42c 100644 --- a/42sh/src/line-editing/rl_setup.c +++ b/42sh/src/line-editing/rl_setup.c @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 18:07:47 by sbenning #+# #+# */ -/* Updated: 2017/01/10 17:06:13 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 18:02:59 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ int rl_setup(t_line *line) { - rl_set_termios(1); do_job_notification(); + data_singleton()->mode = MODE_INPUT; ft_bzero(line, sizeof(t_line)); if (curs_setup(&line->curs) < 0) return (-1); @@ -26,7 +26,7 @@ int rl_setup(t_line *line) int rl_cleanup(t_line *line) { - rl_set_termios(0); + data_singleton()->mode = MODE_EXEC; if (curs_cleanup(&line->curs) < 0) return (-1); if (rl_merge_line(line) < 0) diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index 3031469b..2ef606fe 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: 2017/01/10 17:05:44 by jhalford ### ########.fr */ +/* Updated: 2017/01/10 17:10:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ void shell_init(void) kill(-*shell_pgid, SIGTTIN); signal(SIGINT, sigint_handler); signal(SIGQUIT, SIG_IGN); - signal(SIGTSTP, SIG_IGN); + signal(SIGTSTP, sigtstp_handler); signal(SIGTTIN, sigttin_handler); signal(SIGTTOU, sigttou_handler); signal(SIGCHLD, sigchld_handler);