diff --git a/42sh/Makefile b/42sh/Makefile index 6dedd814..4caa3e26 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -196,6 +196,7 @@ job_control/job_run.c\ job_control/job_update_id.c\ job_control/job_update_status.c\ job_control/job_wait.c\ +job_control/jobc_destroy.c\ job_control/mark_job_as_running.c\ job_control/pprint_brace.c\ job_control/pprint_case.c\ diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index ddf9e390..6d9a8b19 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/24 16:17:40 by gwojda ### ########.fr */ +/* Updated: 2017/03/27 03:11:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,8 @@ struct s_jobc struct termios shell_tmodes; }; +int jobc_destroy(t_jobc *jobc); + t_list *job_getprocess(pid_t pid); int job_addprocess(t_process *p); void job_update_id(void); diff --git a/42sh/src/exec/exec_destroy.c b/42sh/src/exec/exec_destroy.c index e6e2b525..f1d7c764 100644 --- a/42sh/src/exec/exec_destroy.c +++ b/42sh/src/exec/exec_destroy.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* exec_reset.c :+: :+: :+: */ +/* exec_destroy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/27 00:33:31 by jhalford ### ########.fr */ +/* Created: 2017/03/27 03:09:58 by jhalford #+# #+# */ +/* Updated: 2017/03/27 03:10:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,14 +14,8 @@ int exec_destroy(t_exec *exec) { - t_jobc *jobc; - int i; - if (!exec) return (0); - jobc = &data_singleton()->jobc; ft_lstdel(&exec->op_stack, ft_lst_cfree); - ft_lstdel(&jobc->first_job, job_free); - i = -1; return (0); } diff --git a/42sh/src/exec/mark_process_status.c b/42sh/src/exec/mark_process_status.c index 15f1f223..d31a996a 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/24 17:28:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:08:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,6 +35,6 @@ int mark_process_status(pid_t pid, int status) } return (0); } - SH_ERR("No child process %d", pid); + SH_ERR("No child process %i", pid); return (1); } diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 10c979ac..e241ba40 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/03/25 00:58:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:18:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ int redirect_greatand(t_redir *redir) if (fdold > 9) return (bad_fd(fdold)); if (fd_is_valid(fdold, O_WRONLY | O_RDWR)) - fd_replace(fdold, fdnew); + dup2(fdold, fdnew); else return (bad_fd(fdold)); return (0); diff --git a/42sh/src/exec/redirect_lessand.c b/42sh/src/exec/redirect_lessand.c index 0f4f5928..1be9e62c 100644 --- a/42sh/src/exec/redirect_lessand.c +++ b/42sh/src/exec/redirect_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:11:18 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:33:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:18:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,7 +32,7 @@ int redirect_lessand(t_redir *redir) if (fdold > 9) return (bad_fd(fdold)); if (fd_is_valid(fdold, O_RDONLY | O_RDWR)) - fd_replace(fdold, fdnew); + dup2(fdold, fdnew); else return (bad_fd(fdold)); return (0); diff --git a/42sh/src/job_control/job_update_status.c b/42sh/src/job_control/job_update_status.c index 8e89d64e..8b00a02b 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/20 14:36:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:17:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,8 +21,7 @@ void job_update_status(void) { 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); + SH_ERR("waitpid(): %s", strerror(errno)); if (pid <= 1 || mark_process_status(pid, status)) break ; } diff --git a/42sh/src/job_control/jobc_destroy.c b/42sh/src/job_control/jobc_destroy.c new file mode 100644 index 00000000..2f86df98 --- /dev/null +++ b/42sh/src/job_control/jobc_destroy.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* jobc_destroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/27 03:09:41 by jhalford #+# #+# */ +/* Updated: 2017/03/27 03:10:55 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int jobc_destroy(t_jobc *jobc) +{ + if (jobc) + ft_lstdel(&jobc->first_job, job_free); + return (0); +} diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index fcebafba..11ca50b9 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ -/* Updated: 2017/03/27 00:36:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/27 03:11:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,7 @@ void data_exit(void) lexer_destroy(&data->lexer); parser_destroy(&data->parser); exec_destroy(&data->exec); + jobc_destroy(&data->jobc); i = -1; while (++i < 10) ft_lstdel(&data->exec.fd_save[i], ft_lst_cfree);