diff --git a/Makefile b/Makefile index 3c2ce87..30be65b 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ LIB_NAME = libftprintf.a SHELL_SRC = main.c init.c memory.c auxilia.c \ service_routines.c args_parsing.c string_hash.c \ shell_environ.c shell_environ_tools.c shell_environ_vector.c \ - shell_environ_memory.c \ + shell_environ_memory.c init_term.c \ syscall_wrappers.c \ auxiliary_main.c init_hashtable.c init_term.c diff --git a/src/job_control/context_switch.c b/src/job_control/context_switch.c index 257fa28..a50866e 100644 --- a/src/job_control/context_switch.c +++ b/src/job_control/context_switch.c @@ -6,12 +6,38 @@ /* By: vtarasiu +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/10 12:09:35 by vtarasiu #+# #+# */ -/* Updated: 2019/07/10 18:05:09 by vtarasiu ### ########.fr */ +/* Updated: 2019/07/09 00:19:41 by vtarasiu ### ########.fr */ /* */ /* ************************************************************************** */ #include "twenty_one_sh.h" +/* +** TODO: make environ context switches more intelligent - make diffs possible +*/ + +void context_deep_free(t_context **context) +{ + struct s_fd_lst *list; + struct s_fd_lst *swap; + + if (context == NULL || *context == NULL) + return ; + environ_deallocate_vector((*context)->environ); + list = (*context)->fd_list; + while (list) + { + swap = list->next; + if (list->current > 2) + close(list->current); + free(list->label); + free(list); + list = swap; + } + ft_memdel((void **)&((*context)->term_config)); + ft_memdel((void **)context); +} + /* ** If to_which is NULL, restores context from backup with pretty much the same ** algorithm @@ -69,18 +95,6 @@ static void duplicate_environ(t_context *new_context, } } -struct s_fd_lst *get_tmp_node(struct s_fd_lst *list, bool with_dup) -{ - struct s_fd_lst *tmp; - - tmp = ft_memalloc(sizeof(struct s_fd_lst)); - if (list->label) - tmp->label = ft_strdup("cloned"); - tmp->original = list->original; - tmp->current = with_dup ? dup(list->current) : list->current; - return (tmp); -} - static void duplicate_fds(t_context *new, const t_context *context, bool with_dup) { @@ -94,7 +108,11 @@ static void duplicate_fds(t_context *new, const t_context *context, { if (list->current >= 0) { - tmp = get_tmp_node(list, with_dup); + tmp = ft_memalloc(sizeof(struct s_fd_lst)); + if (list->label) + tmp->label = ft_strdup("cloned"); + tmp->original = list->original; + tmp->current = with_dup ? dup(list->current) : list->current; if (!new->fd_list) { new->fd_list = tmp;