diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-18 17:37:43 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-18 17:37:43 +0200 |
commit | 0872d876f187a30b63062f77c17b8e78296b0557 (patch) | |
tree | 1a85d6c9629335592a6d1bb8a5dda5214cde27be | |
parent | Updated TODO (diff) | |
download | 42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.gz 42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.bz2 42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.xz 42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.tar.zst 42-minishell-0872d876f187a30b63062f77c17b8e78296b0557.zip |
Handled execve fail
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | TODO.org | 1 | ||||
-rw-r--r-- | src/d_define.h | 6 | ||||
-rw-r--r-- | src/e_externs.c | 23 | ||||
-rw-r--r-- | src/e_externs_next.c | 2 | ||||
-rw-r--r-- | src/f_exec.c | 27 | ||||
-rw-r--r-- | src/f_exec.h | 20 | ||||
-rw-r--r-- | src/f_fail.h | 1 |
8 files changed, 71 insertions, 10 deletions
@@ -35,6 +35,7 @@ SRCS_NAME += f_alloc SRCS_NAME += f_chdir SRCS_NAME += f_com SRCS_NAME += f_errno +SRCS_NAME += f_exec SRCS_NAME += f_fail SRCS_NAME += f_file SRCS_NAME += f_redir @@ -15,6 +15,7 @@ * Stuff to add ** DONE [#A] builtins to pipes ** DONE [#A] Proper ~ subst +** TODO [#A] quotes ** DONE [#B] && || ** TODO [#B] & ** TODO [#B] $_ diff --git a/src/d_define.h b/src/d_define.h index d38cb10..2f819c9 100644 --- a/src/d_define.h +++ b/src/d_define.h @@ -19,9 +19,9 @@ ** ====== CLASSICS ====== */ -#define FT_PS_ONE "minishell ~> " -#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type" -#define FT_HISTFILE "minishell_history" +#define FT_PS_ONE "minishell ~> " +#define FT_BUILTINS "echo|cd|pwd|export|unset|env|exit|type" +#define FT_MSH_VERSION "0.1" /* ** ====== OPTIONS ====== diff --git a/src/e_externs.c b/src/e_externs.c index 5128bc8..ce0d41d 100644 --- a/src/e_externs.c +++ b/src/e_externs.c @@ -12,9 +12,11 @@ #include <sys/wait.h> #include <libft.h> -#include <stdlib.h> #include <stdint.h> +#include <stdlib.h> +#include <string.h> #include <unistd.h> +#include <errno.h> #include "b_export_next.h" #include "e_externs_next.h" @@ -30,8 +32,14 @@ static void t_msh *msh) { dup_redirs(ptr, msh); - execve(fullpath, ptr->argv, msh->envp); - /* TODO: handle execve failed */ + if (execve(fullpath, ptr->argv, msh->envp) == -1) + { + f_exec(fullpath); + ft_memdel((void*)&fullpath); + s_line_clear(&msh->curr); + s_destroy(msh); + exit(errno); + } } static void @@ -50,8 +58,8 @@ static void static void exec_path(const char fullpath[], - t_com *ptr, - t_msh *msh) + t_com *ptr, + t_msh *msh) { pid_t pid; int32_t status; @@ -83,7 +91,10 @@ void if (ft_ischarset("./", ptr->bin[0]) == TRUE) { - exec_path(ptr->bin, ptr, msh); + if ((fullpath = ft_strdup(ptr->bin)) == NULL) + return ; + exec_path(fullpath, ptr, msh); + ft_memdel((void*)&fullpath); return ; } else if ((envpath = get_env_path(msh)) != NULL) diff --git a/src/e_externs_next.c b/src/e_externs_next.c index c1e248f..ed3ee84 100644 --- a/src/e_externs_next.c +++ b/src/e_externs_next.c @@ -92,7 +92,7 @@ char envline += 1; if (*envline != '\0') { - if (!(envpath = ft_split(envline, ':'))) + if ((envpath = ft_split(envline, ':')) == NULL) { f_alloc_and_destroy_msh(msh); } diff --git a/src/f_exec.c b/src/f_exec.c new file mode 100644 index 0000000..3587700 --- /dev/null +++ b/src/f_exec.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* f_exec.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <string.h> +#include <errno.h> +#include <unistd.h> + +#include "s_struct.h" + +void + f_exec(const char fullpath[]) +{ + ft_dprintf(STDERR_FILENO, + "minishell: %s: %s\n", + fullpath, + strerror(errno)); +} diff --git a/src/f_exec.h b/src/f_exec.h new file mode 100644 index 0000000..17f3484 --- /dev/null +++ b/src/f_exec.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* f_exec.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef F_EXEC_H +#define F_EXEC_H + +#include "s_struct.h" + +void f_exec(const char fullpath[]); + +#endif diff --git a/src/f_fail.h b/src/f_fail.h index dfb46e3..2e432e2 100644 --- a/src/f_fail.h +++ b/src/f_fail.h @@ -17,6 +17,7 @@ #include "f_alloc.h" #include "f_chdir.h" #include "f_errno.h" +#include "f_exec.h" #include "f_file.h" #include "f_redir.h" #include "f_shlvl.h" |