diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 1bf1074b..b14e1d2d 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -140,6 +140,7 @@ struct s_exec }; int exec_reset(void); +int exec_destroy(void); int exec_pushfds(); int exec_popfds(); int process_fork(t_process *p); diff --git a/42sh/libft/src/sys/open_access.c b/42sh/libft/src/sys/open_access.c index 40811fe7..bc1ee88e 100644 --- a/42sh/libft/src/sys/open_access.c +++ b/42sh/libft/src/sys/open_access.c @@ -23,8 +23,6 @@ int open_access(char *file, t_flag a_flag, t_flag o_flag, t_flag o_perm) if (access(file, F_OK) == 0 && access(file, a_flag) != 0) return (-ERR_SET(E_SYS_NOPERM, file)); if ((fd = open(file, o_flag, o_perm)) < 0) - { exit(1); - } return (fd); } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index b9330b38..0e55431e 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -62,3 +62,19 @@ int exec_reset(void) jobc->current_id = 1; return (0); } + +int exec_destroy(void) +{ + int i; + t_jobc *jobc; + t_exec *exec; + + exec = &data_singleton()->exec; + jobc = &data_singleton()->jobc; + ft_lstdel(&exec->op_stack, ft_lst_cfree); + ft_lstdel(&jobc->first_job, job_free); + i = -1; + while (++i < 10) + ft_lstdel(&exec->fd_save[i], ft_lst_cfree); + return (0); +} diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index ac107417..5a0b711b 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -26,6 +26,7 @@ int process_fork(t_process *p) exit(1); process_setgroup(p, 0); process_setsig(); + exec_destroy(); exec_reset(); data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; diff --git a/42sh/src/main/data_exit.c b/42sh/src/main/data_exit.c index 753ea33f..d8911c0f 100644 --- a/42sh/src/main/data_exit.c +++ b/42sh/src/main/data_exit.c @@ -19,13 +19,13 @@ void data_exit(void) data = data_singleton(); ft_strdel(&data->line.input); ft_strdel(&data->binary); - exec_popfds(); + /* exec_popfds(); */ ft_sstrfree(data->env); ft_sstrfree(data->local_var); ft_sstrfree(data->argv); lexer_destroy(&data->lexer); parser_destroy(&data->parser); - ft_lstdel(&data->jobc.first_job, &job_free); + exec_destroy(); ft_lstdel(&data->lst_func, &tree_func_free); ft_save_termios(-1); ft_free_hash_table(); diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index dc2bd6b8..ec68356f 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -11,7 +11,9 @@ /* ************************************************************************** */ #include "minishell.h" -#define SHELL_USAGE "42sh [-c command | [<]script] [--no-jobcontrol]" +#define SHELL_USAGE1 "usage: 42sh [--no-jobcontrol]" +#define SHELL_USAGE2 " or 42sh -c command" +#define SHELL_USAGE3 " or 42sh script" static t_cliopts g_opts[] = { @@ -87,7 +89,10 @@ int shell_init(int ac, char **av, char **env) if (data_init(ac, av, env) < 0) return (-1); if (cliopts_get(av, g_opts, data)) - return (ft_perror(NULL) && SH_ERR("usage: %s", SHELL_USAGE)); + return (ft_perror(NULL) + && SH_ERR("%s", SHELL_USAGE1) + && SH_ERR("%s", SHELL_USAGE2) + && SH_ERR("%s", SHELL_USAGE3)); if (!isatty(STDIN) || *data->av_data) data->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC); if ((data->fd = get_input_fd(data, NULL)) < 0)