Commit a992e4f9 authored by abenoit's avatar abenoit
Browse files

child exit no exit msg

parent b23cfe55
......@@ -12,7 +12,7 @@
enum e_exec_errcode
{
HOME_NOT_SET = 7,
HOME_NOT_SET = 8,
NO_SUCH_FILE
};
......
......@@ -49,6 +49,7 @@
enum e_retcode
{
CLEAN_EXIT = 2,
CHILD_EXIT,
ARG_ERR,
MALLOC_ERR,
WRITE_ERR,
......
......@@ -31,7 +31,7 @@ enum e_state
enum e_parsing_error
{
SQUOTE_MISSING = 9,
SQUOTE_MISSING = 10,
DQUOTE_MISSING,
ESCAPE_NL,
REDIR_PATH_INVALID,
......
......@@ -65,16 +65,13 @@ static int child_task(char **path, char **args, t_xe *xe)
perror("External function error:");
dir_index = search_exec(path, args[0]);
if (dir_index == NOT_FOUND)
{
free_str_array(path);
return (NO_SUCH_FILE); // other error code
}
cmd = ft_strjoin(path[dir_index], "/");
cmd = ft_strjoin(cmd, args[0]);
if (execve(cmd, args, xe->env) == ERROR)
perror("External function error:");
free(cmd); // does not free if execve succeeds
return (CLEAN_EXIT);
return (CHILD_EXIT);
}
static int launch_ext(char **args, t_xe *xe)
......@@ -95,7 +92,6 @@ static int launch_ext(char **args, t_xe *xe)
free(tmp);
if (path == NULL)
return (M_ERROR);
// free_str_array(path);
pid = fork();
if (pid == 0)
{
......
......@@ -39,7 +39,7 @@ int exec_error(int err_code, t_xe *xe)
(void)err_msg;
ft_putstr_fd("minishell: command error: ", STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - 7], STDERR_FILENO);
ft_putstr_fd(err_msg[err_code - 8], STDERR_FILENO);
ft_putchar_fd('\n', STDERR_FILENO);
// have to set stat_loc as well !!!
if (err_code == HOME_NOT_SET)
......@@ -47,7 +47,7 @@ int exec_error(int err_code, t_xe *xe)
if (err_code == NO_SUCH_FILE)
xe->stat_loc = 127;
if (xe->child == 1)
return (CLEAN_EXIT);
return (CHILD_EXIT);
else
return (SUCCESS);
}
......@@ -68,23 +68,33 @@ static int err_output(int err_code)
putstr_stderr("Error\n");
if (err_code == ARG_ERR)
{
putstr_stderr(err_msg(err_code - 3));
putstr_stderr(err_msg(err_code - 4));
putstr_stderr("\n");
}
else if (err_code < HOME_NOT_SET)
perror(err_msg(err_code - 3));
perror(err_msg(err_code - 4));
return (SUCCESS);
}
int clean_and_exit(int ret, t_xe *xe)
{
free_str_array(xe->exported); // besoin de free?
free_str_array(xe->env); // besoin de free?
free(xe);
if (ret != CHILD_EXIT)
write(1, "exit\n", 5);
exit(EXIT_SUCCESS);
}
int ft_error(int ret, t_xe *xe)
{
if (ret == CLEAN_EXIT)
return (ft_exit(ret, xe));
if (ret == CLEAN_EXIT || ret == CHILD_EXIT)
return (clean_and_exit(ret, xe));
else if (ret >= SQUOTE_MISSING)// temp
return (parsing_error(ret - 9, xe));
return (parsing_error(ret - 10, xe));
else if (ret >= HOME_NOT_SET)
return (exec_error(ret, xe));
else if (ret > CLEAN_EXIT)
else if (ret > CHILD_EXIT)
err_output(ret);
else
putstr_stderr("ERROR CODE ERROR");// temp
......@@ -94,9 +104,5 @@ int ft_error(int ret, t_xe *xe)
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);
write(1, "exit\n", 5);
exit(EXIT_SUCCESS);
return (clean_and_exit(ret, xe));
}
......@@ -129,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 && ret != FAILURE)
while (ret != CLEAN_EXIT && ret != FAILURE && ret != CHILD_EXIT)
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