From 33f6c24b0e5e917e18646bebc970ccb7ed622028 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 20 Mar 2017 11:49:00 +0100 Subject: [PATCH 1/5] job control minor fixes --- 42sh/Makefile | 2 +- 42sh/includes/job_control.h | 6 +++--- 42sh/src/builtin/builtin_exit.c | 6 ++++-- 42sh/src/exec/exec_reset.c | 4 ++-- 42sh/src/exec/process_set.c | 2 +- 42sh/src/exec/redir_free.c | 2 +- 42sh/src/job_control/builtin_jobs.c | 2 +- 42sh/src/job_control/job_addprocess.c | 2 +- 42sh/src/job_control/job_free.c | 2 +- 42sh/src/job_control/{job_kill_all.c => job_hup_all.c} | 10 +++++----- 42sh/src/job_control/job_is_completed.c | 2 +- 42sh/src/job_control/job_is_stopped.c | 6 +++--- 42sh/src/job_control/job_remove.c | 2 +- 42sh/src/job_control/mark_job_as_running.c | 2 +- 42sh/src/job_control/process_format.c | 2 +- 42sh/src/job_control/process_free.c | 2 +- 42sh/src/main/shell_init.c | 2 +- 17 files changed, 29 insertions(+), 27 deletions(-) rename 42sh/src/job_control/{job_kill_all.c => job_hup_all.c} (78%) diff --git a/42sh/Makefile b/42sh/Makefile index 7d58c40b..846b7184 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -179,9 +179,9 @@ job_control/job_format_head.c\ job_control/job_free.c\ job_control/job_getprocess.c\ job_control/job_getrank.c\ +job_control/job_hup_all.c\ job_control/job_is_completed.c\ job_control/job_is_stopped.c\ -job_control/job_kill_all.c\ job_control/job_notify_change.c\ job_control/job_notify_new.c\ job_control/job_remove.c\ diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 08f66b66..78d034c5 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/17 23:10:35 by wescande ### ########.fr */ +/* Updated: 2017/03/20 11:38:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,7 @@ void job_run(t_job *job, int foreground); int job_wait(int id); void job_remove(int id); void job_free(void *content, size_t content_size); -void job_kill_all(void); +void job_hup_all(void); int put_job_in_foreground(t_job *job, int cont); int put_job_in_background(t_job *job, int cont); @@ -79,7 +79,7 @@ void process_format(t_list **p, int firstp, int opts); ** Mapping pour afficher les process */ void pprint(t_process *p); -int pprint_subshell(t_process *p); +int pprint_subshell(t_process *p);; int pprint_brace(t_process *p); int pprint_while(t_process *p); int pprint_if(t_process *p); diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index d38bd167..f64c4a15 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: 2017/03/18 15:41:42 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 11:37:51 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,8 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) if (SH_HAS_JOBC(data_singleton()->opts) && jlist && !notified) { notified = 1; - ft_dprintf(2, "{red}%s: you have live jobs (running or suspended).{eoc}\n", SHELL_NAME); + ft_dprintf(2, "%s: you have live jobs (running or suspended)\n", + data_singleton()->argv[0]); return (0); } if (av && av[1]) @@ -35,6 +36,7 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) status = ft_atoi(ft_getenv(data_singleton()->env, "?")); if (SH_IS_INTERACTIVE(data_singleton()->opts)) tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); + job_hup_all(); data_exit(); exit(status); return (0); diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index b83d6928..45e91663 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/20 08:51:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:35:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int exec_reset(void) exec->attrs = 0; exec->job.id = 0; exec->job.pgid = 0; - exec->job.attrs = 0; + exec->job.attrs = JOB_NOTIFIED; exec->job.first_process = NULL; tcgetattr(STDIN, &exec->job.tmodes); jobc->first_job = NULL; diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index b3f61ed8..69f451ff 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:57:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:38:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c index 09665cd9..0e04cec2 100644 --- a/42sh/src/exec/redir_free.c +++ b/42sh/src/exec/redir_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ -/* Updated: 2017/03/18 18:59:57 by ariard ### ########.fr */ +/* Updated: 2017/03/20 11:39:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/builtin_jobs.c b/42sh/src/job_control/builtin_jobs.c index 3031cde0..dbae9068 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/03/08 18:52:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:47:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_addprocess.c b/42sh/src/job_control/job_addprocess.c index 02181cb8..a72895c0 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/03/20 10:57:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:32:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_free.c b/42sh/src/job_control/job_free.c index 7046cfe7..027c1676 100644 --- a/42sh/src/job_control/job_free.c +++ b/42sh/src/job_control/job_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/01/09 13:22:16 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:39:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_kill_all.c b/42sh/src/job_control/job_hup_all.c similarity index 78% rename from 42sh/src/job_control/job_kill_all.c rename to 42sh/src/job_control/job_hup_all.c index ded01abd..0a4e238c 100644 --- a/42sh/src/job_control/job_kill_all.c +++ b/42sh/src/job_control/job_hup_all.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* job_kill_all.c :+: :+: :+: */ +/* job_hup_all.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/08 15:36:56 by jhalford #+# #+# */ -/* Updated: 2017/01/09 16:35:51 by jhalford ### ########.fr */ +/* Created: 2017/03/20 11:37:40 by jhalford #+# #+# */ +/* Updated: 2017/03/20 11:37:53 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void job_kill_all(void) +void job_hup_all(void) { t_jobc *jobc; t_list *jlist; @@ -23,7 +23,7 @@ void job_kill_all(void) while (jlist) { job = jlist->content; - kill(-job->pgid, SIGKILL); + kill(-job->pgid, SIGHUP); jlist = jlist->next; } } diff --git a/42sh/src/job_control/job_is_completed.c b/42sh/src/job_control/job_is_completed.c index 83bc6ecb..aa20bece 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/03/20 11:10:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:30:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/job_is_stopped.c b/42sh/src/job_control/job_is_stopped.c index 45c0cb64..8d342c0f 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: 2017/03/20 11:10:12 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:32:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,8 +25,8 @@ int job_is_stopped(int id) while (lst) { p = lst->content; - if (!(p->state == PROCESS_COMPLETED) - || !(p->state == PROCESS_SUSPENDED)) + if (!((p->state == PROCESS_COMPLETED) + || !(p->state == PROCESS_SUSPENDED))) return (0); lst = lst->next; } diff --git a/42sh/src/job_control/job_remove.c b/42sh/src/job_control/job_remove.c index 782aa632..e054c5c3 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/03/20 10:20:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:40:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/mark_job_as_running.c b/42sh/src/job_control/mark_job_as_running.c index eb4b8623..0cf46b23 100644 --- a/42sh/src/job_control/mark_job_as_running.c +++ b/42sh/src/job_control/mark_job_as_running.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:40:40 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:56:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:33:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/process_format.c b/42sh/src/job_control/process_format.c index d6e54143..7fce0c80 100644 --- a/42sh/src/job_control/process_format.c +++ b/42sh/src/job_control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:54:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:47:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/process_free.c b/42sh/src/job_control/process_free.c index 13e6aae7..29fab3f4 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/16 16:53:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:39:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index fcfb4611..5e1af3c5 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/03/20 11:30:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 11:30:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 28b2a059a54a73565fabbded0ca5a68e5b59df5a Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 20 Mar 2017 12:27:36 +0100 Subject: [PATCH 2/5] fix leak redir --- 42sh/includes/lexer.h | 7 +++---- 42sh/includes/parser.h | 5 ++--- 42sh/libft/src/lst/ft_lstmap.c | 6 ++++-- 42sh/libft/src/lst/ft_lstnew.c | 2 +- 42sh/libft/src/math/id.c | 12 ++++++++++++ 42sh/src/exec/process_set.c | 2 +- 42sh/src/exec/redir_copy.c | 2 +- 42sh/src/exec/redir_free.c | 2 +- 42sh/src/job_control/builtin_fg.c | 3 +-- 42sh/src/job_control/do_job_notification.c | 5 ++--- 42sh/src/job_control/job_update_status.c | 2 +- 11 files changed, 29 insertions(+), 19 deletions(-) diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index a0bc1ed1..d8961da0 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/19 17:13:05 by wescande ### ########.fr */ +/* Updated: 2017/03/20 11:51:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -63,9 +63,8 @@ struct s_rvwords int type; }; -extern t_rvwords g_rvwords[]; - -extern int (*g_lexer[])(t_list **alst, t_lexer *lexer); +/* extern t_rvwords g_rvwords[]; */ +/* extern int (*g_lexer[])(t_list **alst, t_lexer *lexer); */ int ft_post_tokenize(t_list **alst, char **str); diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 6bd7ac30..1fa276a9 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -94,8 +94,6 @@ struct s_treematch int (*add)(t_btree **ast, t_list **lst); }; -extern t_treematch g_treematch[]; - int build_tree(t_btree **ast, t_list **lst); int add_sep(t_btree **ast, t_list **lst); @@ -153,7 +151,8 @@ struct s_distrostree int (*add)(t_btree **ast, t_list **lst); }; -extern t_distrostree g_distrostree[]; +/* extern t_distrostree g_distrostree[]; */ +/* extern t_treematch g_treematch[]; */ struct s_redir { diff --git a/42sh/libft/src/lst/ft_lstmap.c b/42sh/libft/src/lst/ft_lstmap.c index 3b422790..3a36ef41 100644 --- a/42sh/libft/src/lst/ft_lstmap.c +++ b/42sh/libft/src/lst/ft_lstmap.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/03 14:57:21 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:03:14 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:25:42 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,9 @@ t_list *ft_lstmap(t_list *lst, void *(*f)(void *)) if (!lst) return (NULL); - elem = ft_lstnew((*f)(lst->content), lst->content_size); + if (!(elem = (t_list *)malloc(sizeof(*elem)))) + return (NULL); + elem->content = (*f)(lst->content); elem->next = ft_lstmap(lst->next, f); return (elem); } diff --git a/42sh/libft/src/lst/ft_lstnew.c b/42sh/libft/src/lst/ft_lstnew.c index e85e8c62..17a43d6f 100644 --- a/42sh/libft/src/lst/ft_lstnew.c +++ b/42sh/libft/src/lst/ft_lstnew.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 15:57:38 by jhalford #+# #+# */ -/* Updated: 2017/03/13 15:41:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:23:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/libft/src/math/id.c b/42sh/libft/src/math/id.c index 938cb5d1..e23a5831 100644 --- a/42sh/libft/src/math/id.c +++ b/42sh/libft/src/math/id.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* id.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 12:20:59 by jhalford #+# #+# */ +/* Updated: 2017/03/20 12:21:01 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "libft.h" void *id(void *data) diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index 69f451ff..b2ce7cfc 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:38:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:22:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_copy.c b/42sh/src/exec/redir_copy.c index 055efcd4..5dd758c9 100644 --- a/42sh/src/exec/redir_copy.c +++ b/42sh/src/exec/redir_copy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ -/* Updated: 2017/03/13 14:20:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:21:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c index 0e04cec2..2cc00e05 100644 --- a/42sh/src/exec/redir_free.c +++ b/42sh/src/exec/redir_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ -/* Updated: 2017/03/20 11:39:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:21:21 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job_control/builtin_fg.c b/42sh/src/job_control/builtin_fg.c index 0201de78..dfbe6104 100644 --- a/42sh/src/job_control/builtin_fg.c +++ b/42sh/src/job_control/builtin_fg.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:00:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:12:16 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,6 @@ int builtin_fg(const char *path, char *const av[], char *const envp[]) } else { - DG("rank:%i:%i", rank[0], rank[1]); if ((jlist = ft_lst_find(jobc->first_job, &rank[0], job_cmp_id))) job_run(jlist->content, 1); else if ((jlist = ft_lst_find(jobc->first_job, &rank[1], job_cmp_id))) diff --git a/42sh/src/job_control/do_job_notification.c b/42sh/src/job_control/do_job_notification.c index 8bec9af4..a86208a8 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/03/18 00:07:12 by wescande ### ########.fr */ +/* Updated: 2017/03/20 12:15:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,8 +27,7 @@ int do_job_notification(void) { j = jlist->content; jlist = jlist->next; - if (job_is_completed(j->id) - || (job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED))) + if ((job_is_stopped(j->id) && !(j->attrs & JOB_NOTIFIED))) { ret = 1; job_notify_change(j->id); diff --git a/42sh/src/job_control/job_update_status.c b/42sh/src/job_control/job_update_status.c index 7fca5ea1..c518decb 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/16 18:32:15 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:12:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 4ea510774d2da49ab5acedb68bb608f473031033 Mon Sep 17 00:00:00 2001 From: gwojda Date: Mon, 20 Mar 2017 12:57:06 +0100 Subject: [PATCH 3/5] fix leaks edition de ligne --- 42sh/src/line_editing/readline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index 4bb37745..068889a0 100644 --- a/42sh/src/line_editing/readline.c +++ b/42sh/src/line_editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/20 09:57:09 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:56:36 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ int readline(int has_prompt, char **input) ft_putchar('\n'); if (has_prompt) ret = ft_history_parsing(has_prompt, input); + ft_strdel(&data_singleton()->line.copy_tmp); if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1) return (-1); return (ret); From 5b5a4442e2ab803a69828729f605a3cef3ecb959 Mon Sep 17 00:00:00 2001 From: gwojda Date: Mon, 20 Mar 2017 14:18:26 +0100 Subject: [PATCH 4/5] norme --- 42sh/includes/builtin_read.h | 23 ++++++++++++----------- 42sh/includes/ft_curs.h | 6 +++--- 42sh/includes/ft_readline.h | 5 +---- 42sh/src/builtin/builtin_exit.c | 8 +++----- 42sh/src/history/surch_in_history.c | 15 +++++++-------- 42sh/src/line_editing/readline.c | 8 ++++++-- 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index c40d11e4..25f39efa 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* builtin_read.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ -/* Updated: 2017/03/15 19:13:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:36:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,17 +30,18 @@ typedef struct s_readopt t_readopt; struct s_read { - t_flag opts; - char **names; - char delim; - int nchars; - char *prompt; - int timeout; - int fd; - char *input; + t_flag opts; + char **names; + char delim; + int nchars; + char *prompt; + int timeout; + int fd; + char *input; }; -int builtin_read(const char *path, char *const av[], char *const envp[]); +int builtin_read(const char *path, char *const av[], + char *const envp[]); int bt_read_init(t_read *data, char **av); diff --git a/42sh/includes/ft_curs.h b/42sh/includes/ft_curs.h index 94b1a6bd..d411b2c5 100644 --- a/42sh/includes/ft_curs.h +++ b/42sh/includes/ft_curs.h @@ -6,7 +6,7 @@ /* By: sbenning +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/08 16:34:51 by sbenning #+# #+# */ -/* Updated: 2017/03/15 18:47:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 12:33:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ typedef struct s_curs t_curs; ** Cursor data : cursor's coordonate and windows size */ -struct s_curs +struct s_curs { int co; int li; @@ -79,6 +79,6 @@ void curs_write(t_curs *curs, char *str, size_t len); void curs_write_static(t_curs *curs, char *str, size_t len); void curs_video_write(t_curs *curs, char *str, size_t len); void curs_video_write_static( - t_curs *curs, char *str, size_t len); + t_curs *curs, char *str, size_t len); #endif diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 4282c854..9d78c82b 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/17 17:24:03 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 12:32:15 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,9 +57,6 @@ # define CORRUPT 1 -//# define STR data_singleton()->line.input -//# define POS data_singleton()->line.pos - # define ERROR_CNTL_R 1 typedef struct s_list_history diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index f64c4a15..2e56a7d5 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: 2017/03/20 11:37:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:17:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,10 +30,8 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) data_singleton()->argv[0]); return (0); } - if (av && av[1]) - status = ft_atoi(av[1]); - else - status = ft_atoi(ft_getenv(data_singleton()->env, "?")); + status = (av && av[1]) ? + ft_atoi(av[1]) : ft_atoi(ft_getenv(data_singleton()->env, "?")); if (SH_IS_INTERACTIVE(data_singleton()->opts)) tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); job_hup_all(); diff --git a/42sh/src/history/surch_in_history.c b/42sh/src/history/surch_in_history.c index 69c3a8a0..6c16b270 100644 --- a/42sh/src/history/surch_in_history.c +++ b/42sh/src/history/surch_in_history.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 10:43:16 by gwojda #+# #+# */ -/* Updated: 2017/03/18 14:29:15 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:09:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ static void ft_clear_prompt(size_t *pos, size_t srch_pos) ft_puttermcaps("cd"); } -static int ft_surch_and_realloc(char **str, char **str_srch, +static int search(char **str, char **str_srch, int ret, size_t *srch_pos) { if (!(*str_srch = ft_realloc_imput(*str_srch, ret, *srch_pos))) @@ -51,7 +51,7 @@ static void ft_give_new_prompt(char *str_srch, size_t srch_pos) } } -static void ft_modify_str(char *str_srch, size_t srch_pos, char **str, +static int ft_modify_str(char *str_srch, size_t srch_pos, char **str, size_t *pos) { ft_clear_prompt(pos, srch_pos); @@ -63,6 +63,7 @@ static void ft_modify_str(char *str_srch, size_t srch_pos, char **str, ft_get_next_str(*str, pos); } free(str_srch); + return (0); } int ft_surch_in_history(char **str, size_t *pos) @@ -79,9 +80,8 @@ int ft_surch_in_history(char **str, size_t *pos) ft_give_new_prompt(str_srch, srch_pos); ret = 0; read(0, &ret, sizeof(int)); - if (ft_isprint(ret) && - ft_surch_and_realloc(str, &str_srch, ret, &srch_pos) < 0) - return (-1); + if (ft_isprint(ret) && search(str, &str_srch, ret, &srch_pos) < 0) + return (-1); else if (!ft_isprint(ret) && ret == 127 && srch_pos) { --srch_pos; @@ -92,6 +92,5 @@ int ft_surch_in_history(char **str, size_t *pos) else if (ret != 127 && !ft_isprint(ret)) break ; } - ft_modify_str(str_srch, srch_pos, str, pos); - return (0); + return (ft_modify_str(str_srch, srch_pos, str, pos)); } diff --git a/42sh/src/line_editing/readline.c b/42sh/src/line_editing/readline.c index 068889a0..6205bbc9 100644 --- a/42sh/src/line_editing/readline.c +++ b/42sh/src/line_editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/20 12:56:36 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:16:03 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,11 @@ int readline(int has_prompt, char **input) if (!has_prompt) data_singleton()->line.prompt_size = 1; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) - return ((ret = get_next_line(data_singleton()->fd, input)) >= 0 ? !ret : ret); + { + if ((ret = get_next_line(data_singleton()->fd, input)) >= 0) + return (!ret); + return (ret); + } readline_init(has_prompt); ret = ft_read_stdin(input); if (ret < 0) From 3c39c485cb0603dca49f79d2c7bb953819e5a17f Mon Sep 17 00:00:00 2001 From: gwojda Date: Mon, 20 Mar 2017 14:39:20 +0100 Subject: [PATCH 5/5] norme builtin --- 42sh/src/builtin/bt_read_term.c | 8 +- 42sh/src/builtin/builtin_env.c | 13 +-- 42sh/src/builtin/builtin_export.c | 17 ++-- 42sh/src/builtin/builtin_math.c | 129 +++++++++++++++--------------- 42sh/src/builtin/builtin_read.c | 12 +-- 5 files changed, 89 insertions(+), 90 deletions(-) diff --git a/42sh/src/builtin/bt_read_term.c b/42sh/src/builtin/bt_read_term.c index 0ba68f65..2fb1d5f1 100644 --- a/42sh/src/builtin/bt_read_term.c +++ b/42sh/src/builtin/bt_read_term.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* bt_read_term.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */ -/* Updated: 2017/03/15 21:23:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:23:46 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ struct termios bt_read_term(int init) return (term); } -int bt_read_terminit(t_read *data) +int bt_read_terminit(t_read *data) { struct termios term; @@ -39,7 +39,7 @@ int bt_read_terminit(t_read *data) return (0); } -int bt_read_exit(t_read *data) +int bt_read_exit(t_read *data) { struct termios term; diff --git a/42sh/src/builtin/builtin_env.c b/42sh/src/builtin/builtin_env.c index b6fc4c3b..1d698316 100644 --- a/42sh/src/builtin/builtin_env.c +++ b/42sh/src/builtin/builtin_env.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:14:20 by jhalford #+# #+# */ -/* Updated: 2017/03/19 17:43:24 by wescande ### ########.fr */ +/* Updated: 2017/03/20 14:38:06 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static int env_usage(int arg_miss, char c) +static int env_usage(int arg_miss, char c) { if (arg_miss) ft_dprintf(2, "{red}env: option requires an argument -- u{eoc}\n"); @@ -22,7 +22,7 @@ static int env_usage(int arg_miss, char c) return (1); } -static void env_freeone(char **env, char *arg) +static void env_freeone(char **env, char *arg) { int i; char *tmp; @@ -45,7 +45,7 @@ static void env_freeone(char **env, char *arg) } } -static void env_replace(char ***custom_env, char *arg) +static void env_replace(char ***custom_env, char *arg) { char **arg_split; @@ -57,7 +57,7 @@ static void env_replace(char ***custom_env, char *arg) *custom_env = ft_sstradd(*custom_env, arg); } -static int env_treat_flag(char ***custom_env, char *const *arg[]) +static int env_treat_flag(char ***custom_env, char *const *arg[]) { while (*(++*arg)) { @@ -86,7 +86,8 @@ static int env_treat_flag(char ***custom_env, char *const *arg[]) return (0); } -int builtin_env(const char *path, char *const argv[], char *const envp[]) +int builtin_env(const char *path, char *const argv[], + char *const envp[]) { char **env; diff --git a/42sh/src/builtin/builtin_export.c b/42sh/src/builtin/builtin_export.c index 36772cf9..4f18d296 100644 --- a/42sh/src/builtin/builtin_export.c +++ b/42sh/src/builtin/builtin_export.c @@ -6,13 +6,13 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */ -/* Updated: 2017/03/18 11:46:32 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 14:37:26 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static t_cliopts export_opts[] = +static t_cliopts g_export_opts[] = { {'p', NULL, BT_EXPORT_LP, 0, NULL}, {0, NULL, 0, 0, NULL}, @@ -44,23 +44,20 @@ int builtin_export( (void)envp; (void)path; data.flag = 0; - if (cliopts_get((char**)av, export_opts, &data)) + if (cliopts_get((char**)av, g_export_opts, &data)) ft_perror(); if (data.flag & BT_EXPORT_LP) return (bt_export_print()); av = data.av_data; while (*av) { - if ((equal = ft_strchr(*av, '='))) - { + equal = ft_strchr(*av, '='); + if (equal) *equal = 0; - builtin_setenv("internal", (char*[]){"global", *av, equal + 1}, NULL); - } else - { equal = ft_getenv(data_singleton()->local_var, *av); - builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL); - } + equal ? equal++ : equal; + builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL); builtin_unsetenv("internal", (char*[]){"local", *av, NULL}, NULL); av++; } diff --git a/42sh/src/builtin/builtin_math.c b/42sh/src/builtin/builtin_math.c index 589b009a..e7711687 100644 --- a/42sh/src/builtin/builtin_math.c +++ b/42sh/src/builtin/builtin_math.c @@ -6,17 +6,17 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/17 18:54:00 by ariard #+# #+# */ -/* Updated: 2017/03/17 19:59:42 by ariard ### ########.fr */ +/* Updated: 2017/03/20 14:23:26 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -# define MATHERR_0 "math : invalid number of arguments\n" -# define MATHERR_1 "math : invalid variable name\n" -# define MATHERR_2 "math : invalid operator\n" -# define MATHERR_3 "math : invalid operand\n" -# define MATHERR_4 "math : division by 0\n" +#define MATHERR_0 "math : invalid number of arguments\n" +#define MATHERR_1 "math : invalid variable name\n" +#define MATHERR_2 "math : invalid operator\n" +#define MATHERR_3 "math : invalid operand\n" +#define MATHERR_4 "math : division by 0\n" static int error_msg(char *msg) { @@ -38,78 +38,79 @@ static int get_value(char *var, char **value) { char *temp; char *esc; - int ret; + int ret; esc = ft_strnew((ft_strlen(var) >> 3) + 1); ret = word_is_assignment((char *[]) {var, (esc + 1)}); ft_strdel(&esc); if (!ret) return (error_msg(MATHERR_1)); - temp = ft_sstrstr(data_singleton()->local_var, var); - if (temp) - { - temp += ft_strlenchr(temp, '=') + 1; - *value = ft_strdup(temp); - if (!(ft_stris(*value, &ft_isdigit))) - { - ft_strdel(value); - *value = ft_itoa(0); - } - } - else - *value = ft_itoa(0); - return (0); + temp = ft_sstrstr(data_singleton()->local_var, var); + if (temp) + { + temp += ft_strlenchr(temp, '=') + 1; + *value = ft_strdup(temp); + if (!(ft_stris(*value, &ft_isdigit))) + { + ft_strdel(value); + *value = ft_itoa(0); + } + } + else + *value = ft_itoa(0); + return (0); } static int do_math(char **value, char *operator, char *operand) { - long ope1; - long ope2; + long ope1; + long ope2; - ope1 = ft_atoi(*value); - if (operand) - ope2 = ft_atoi(operand); - else - ope2 = 0; - if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) - return (error_msg(MATHERR_4)); - else - { - ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; - ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; - ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; - ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; - ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; - } - ft_strdel(value); - *value = ft_itoa(ope1); - return (0); + ope1 = ft_atoi(*value); + if (operand) + ope2 = ft_atoi(operand); + else + ope2 = 0; + if ((operator[0] == '/' || operator[0] == '%') && ope2 == 0) + return (error_msg(MATHERR_4)); + else + { + ope1 = (operator[0] == '+') ? ope1 + ope2 : ope1; + ope1 = (operator[0] == '-') ? ope1 - ope2 : ope1; + ope1 = (operator[0] == '/') ? ope1 / ope2 : ope1; + ope1 = (operator[0] == '*') ? ope1 * ope2 : ope1; + ope1 = (operator[0] == '%') ? ope1 % ope2 : ope1; + } + ft_strdel(value); + *value = ft_itoa(ope1); + return (0); } int builtin_math(const char *path, char *const av[], char *const envp[]) { - char *var; - char *value; - char *operator; - char *operand; + char *var; + char *value; + char *operator; + char *operand; - (void)path; - (void)envp; - if (!av || !av[1] || !av[2] || !av[3] || av[4]) - return (error_msg(MATHERR_0)); - init_math(&var, &value, &operator, &operand); - var = av[1]; - if (get_value(var, &value) == -1) - return (-1); - operator = av[2]; - if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' - || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) - return (error_msg(MATHERR_2)); - operand = av[3]; - if (!ft_stris(operand, &ft_isdigit)) - return (error_msg(MATHERR_3)); - if (do_math(&value, operator, operand) == -1) - return (-1); - builtin_setenv("setenv", (char *[]){"local", var, value, 0}, data_singleton()->local_var); - return (0); + (void)path; + (void)envp; + if (!av || !av[1] || !av[2] || !av[3] || av[4]) + return (error_msg(MATHERR_0)); + init_math(&var, &value, &operator, &operand); + var = av[1]; + if (get_value(var, &value) == -1) + return (-1); + operator = av[2]; + if (!(ft_strlen(operator) == 1 && (operator[0] == '+' || operator[0] == '-' + || operator[0] == '/' || operator[0] == '*' || operator[0] == '%'))) + return (error_msg(MATHERR_2)); + operand = av[3]; + if (!ft_stris(operand, &ft_isdigit)) + return (error_msg(MATHERR_3)); + if (do_math(&value, operator, operand) == -1) + return (-1); + builtin_setenv("setenv", (char *[]){"local", var, value, 0}, + data_singleton()->local_var); + return (0); } diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index 5aac937f..3a71d816 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* builtin_read.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 08:31:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 14:24:19 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,13 +40,13 @@ int bt_read_init(t_read *data, char **av) data->timeout = 0; data->input = NULL; if ((cliopts_get(av, g_read_opts, data))) - return(ft_perror() ? 2 : 2); + return (ft_perror() ? 2 : 2); if (bt_read_terminit(data) < 0) return (-1); return (0); } -int bt_read_loop(t_read *data) +int bt_read_loop(t_read *data) { int i; int esc; @@ -74,7 +74,7 @@ int bt_read_loop(t_read *data) return (0); } -int bt_read_assign(t_read *data) +int bt_read_assign(t_read *data) { char *input; char **names; @@ -97,7 +97,7 @@ int bt_read_assign(t_read *data) return (0); } -int builtin_read(const char *path, char *const av[], char *const envp[]) +int builtin_read(const char *path, char *const av[], char *const envp[]) { t_read data; int ret;