Skip to content

Commit

Permalink
Merge branch 'master' into github
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoommus committed Jul 14, 2019
2 parents 0b073e9 + 870dfe8 commit 12b468c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 23 additions & 1 deletion src/job_control/context_manipulations.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: vtarasiu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/12 16:10:06 by vtarasiu #+# #+# */
/* Updated: 2019/07/09 03:07:42 by vtarasiu ### ########.fr */
/* Updated: 2019/07/10 18:11:53 by vtarasiu ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -110,3 +110,25 @@ bool context_is_fd_present(const t_context *context, const int original)
}
return (false);
}

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);
}
14 changes: 8 additions & 6 deletions src/job_control/context_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* context_switch.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vtarasiu <[email protected]> +#+ +:+ +#+ */
/* By: vtarasiu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/10 12:09:35 by vtarasiu #+# #+# */
/* Updated: 2019/07/10 16:27:24 by vtarasiu ### ########.fr */
/* Updated: 2019/07/09 00:19:41 by vtarasiu ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -106,24 +106,26 @@ static void duplicate_fds(t_context *new, const t_context *context,
list = context->fd_list;
while (list)
{
if (list->current >= 0 && (tmp = ft_memalloc(sizeof(struct s_fd_lst))))
if (list->current >= 0)
{
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;
fcntl(list->current, F_SETFL, fcntl(list->current, F_GETFL) | O_CLOEXEC);
if (!new->fd_list)
{
new->fd_list = tmp;
new_list = tmp;
}
else
new->fd_list->next = tmp;
{
new_list->next = tmp;
new_list = new_list->next;
}
}
list = list->next;
}
new->fd_list = new_list;
}

/*
Expand Down

0 comments on commit 12b468c

Please sign in to comment.