From 527a6247652569f38d1003413f98969ed0284edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Thu, 24 Apr 2025 14:01:20 +0200 Subject: [PATCH] fix(exec): return code 126 when command is found but permission denied --- src/executing/simple_cmd/subprocess.c | 8 +++----- test.sh | 11 +++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/executing/simple_cmd/subprocess.c b/src/executing/simple_cmd/subprocess.c index 9f33cf8..4e9f2e5 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/18 09:23:00 by khais ### ########.fr */ +/* Updated: 2025/04/24 17:40:01 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,6 @@ #include "../../parser/simple_cmd/simple_cmd.h" #include "../../subst/path_split.h" #include -#include "../../ft_errno.h" #include #include @@ -57,12 +56,11 @@ static int ft_execve(char *exe, char **argv, char **envp) retvalue = 127; execve(exe, argv, envp); olderrno = errno; + if (olderrno == EACCES) + retvalue = 126; if (ft_is_directory(exe)) - { ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0], strerror(EISDIR)); - retvalue = 126; - } else ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0], strerror(olderrno)); diff --git a/test.sh b/test.sh index ce79110..c2c3f32 100755 --- a/test.sh +++ b/test.sh @@ -1010,4 +1010,15 @@ boubou 0 EOF +when_run <