Commit 773484af authored by abenoit's avatar abenoit
Browse files

error return handling

parent 805d63a5
......@@ -100,7 +100,7 @@ int handle_execution(t_xe *xe, int fd_in, int proc);
** free utils
*/
void print_tokens(t_list *tokens); // temp
void print_tokens(t_list *tokens); // temp
void free_token(void *content);
void free_command(void *content);
void free_commands(t_list **commands);
......@@ -110,6 +110,7 @@ void free_commands(t_list **commands);
*/
void putstr_stderr(const char *str);
int ft_error(int ret, t_xe *xe);
int ft_exit(enum e_retcode retcode, t_xe *xe);
#endif
......@@ -103,6 +103,7 @@ static int launch_ext(char **args, t_xe *xe)
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
waitpid(pid, &xe->stat_loc, 0); // return value? error?
xe->stat_loc = xe->stat_loc / 256;
signal_handler();
}
return (ret);
......
......@@ -73,11 +73,10 @@ static int err_output(int err_code)
}
else if (err_code < HOME_NOT_SET)
perror(err_msg(err_code - 3));
write(1, "exit\n", 7);
exit(EXIT_FAILURE);
return (SUCCESS);
}
int ft_exit(enum e_retcode ret, t_xe *xe)
int ft_error(int ret, t_xe *xe)
{
if (ret >= SQUOTE_MISSING)// temp
return (parsing_error(ret - 9, xe));
......@@ -87,6 +86,12 @@ int ft_exit(enum e_retcode ret, t_xe *xe)
err_output(ret);
else
putstr_stderr("ERROR CODE ERROR");// temp
return (SUCCESS);
}
int ft_exit(enum e_retcode ret, t_xe *xe)
{
ft_error(ret, xe);
free_str_array(xe->exported); // besoin de free?
free_str_array(xe->env); // besoin de free?
free(xe);
......
......@@ -53,9 +53,11 @@ static int main_loop(t_xe *xe)
if (ret == SUCCESS)
{
if ((ret = check_syntax(line)) != SUCCESS)
return (ret); // necessitates SUCCESS to avoid exiting but needs further error management
return (ft_error(ret, xe));
ret = handle_execution(xe, STDIN_FILENO, 0);
//printf("ret = %d\n", ret);
if (ret != SUCCESS)
return (ft_error(ret, xe));
free(line);
}
return (ret);
......@@ -127,7 +129,7 @@ int main(int argc, char **argv, char **env_source)
ret = exec_env_init(xe, env_source);
if (ret != SUCCESS)
return (ft_exit(ret, xe));
while (ret != CLEAN_EXIT)
while (ret != CLEAN_EXIT && ret != FAILURE)
ret = main_loop(xe);
}
return (ft_exit(ret, xe));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment