parent
b30f503cad
commit
0a6654f707
6 changed files with 27 additions and 6 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue