Skip to content

Commit

Permalink
Merge branch 'context_switch'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/job_control/context_switch.c
  • Loading branch information
Hoommus committed Jul 10, 2019
2 parents 48d3d99 + fe723a7 commit 870dfe8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 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
46 changes: 32 additions & 14 deletions src/job_control/context_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,38 @@
/* By: vtarasiu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down

0 comments on commit 870dfe8

Please sign in to comment.