From d44691a5b0d93b357687a2d733049bbaf7a172a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 18 Apr 2025 09:17:22 +0200 Subject: [PATCH] fix(exec): running a command with an absolute path which does not exist now gives correct error Before, it gave "Is a directory" error, but now it correctly gives "No such file or directory". --- src/executing/simple_cmd/subprocess.c | 12 ++++++------ test.sh | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/executing/simple_cmd/subprocess.c b/src/executing/simple_cmd/subprocess.c index 5ad5aa7..9f33cf8 100644 --- a/src/executing/simple_cmd/subprocess.c +++ b/src/executing/simple_cmd/subprocess.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/04/02 18:19:23 by khais #+# #+# */ -/* Updated: 2025/04/17 11:10:16 by khais ### ########.fr */ +/* Updated: 2025/04/18 09:23:00 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -42,7 +42,7 @@ static bool ft_is_directory(char *path) errno = 0; retvalue = true; dir = opendir(path); - if (errno == ENOTDIR) + if (errno == ENOTDIR || errno == ENOENT) retvalue = false; if (dir != NULL) closedir(dir); @@ -52,9 +52,11 @@ static bool ft_is_directory(char *path) static int ft_execve(char *exe, char **argv, char **envp) { int retvalue; + int olderrno; retvalue = 127; execve(exe, argv, envp); + olderrno = errno; if (ft_is_directory(exe)) { ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0], @@ -62,10 +64,8 @@ static int ft_execve(char *exe, char **argv, char **envp) retvalue = 126; } else - { - ft_dprintf(STDERR_FILENO, "minishell: %s: ", argv[0]); - ft_perror(NULL); - } + ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0], + strerror(olderrno)); free(exe); path_split_destroy(argv); path_split_destroy(envp); diff --git a/test.sh b/test.sh index 3718eca..1a00408 100755 --- a/test.sh +++ b/test.sh @@ -714,4 +714,22 @@ minishell: : command not found not printed EOF +when_run <