mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix(exec): return code 126 when command is found but permission denied
This commit is contained in:
parent
9d37d07589
commit
527a624765
2 changed files with 14 additions and 5 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/02 18:19:23 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 "../../parser/simple_cmd/simple_cmd.h"
|
||||||
#include "../../subst/path_split.h"
|
#include "../../subst/path_split.h"
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include "../../ft_errno.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
@ -57,12 +56,11 @@ static int ft_execve(char *exe, char **argv, char **envp)
|
||||||
retvalue = 127;
|
retvalue = 127;
|
||||||
execve(exe, argv, envp);
|
execve(exe, argv, envp);
|
||||||
olderrno = errno;
|
olderrno = errno;
|
||||||
|
if (olderrno == EACCES)
|
||||||
|
retvalue = 126;
|
||||||
if (ft_is_directory(exe))
|
if (ft_is_directory(exe))
|
||||||
{
|
|
||||||
ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0],
|
ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0],
|
||||||
strerror(EISDIR));
|
strerror(EISDIR));
|
||||||
retvalue = 126;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0],
|
ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0],
|
||||||
strerror(olderrno));
|
strerror(olderrno));
|
||||||
|
|
|
||||||
11
test.sh
11
test.sh
|
|
@ -1010,4 +1010,15 @@ boubou
|
||||||
0
|
0
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "PATH unset with command in current dir"
|
||||||
|
touch cat
|
||||||
|
unset PATH
|
||||||
|
cat
|
||||||
|
echo \$?
|
||||||
|
EOF
|
||||||
|
expecting <<EOF
|
||||||
|
minishell: cat: Permission denied
|
||||||
|
126
|
||||||
|
EOF
|
||||||
|
|
||||||
finalize
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue