mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
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".
This commit is contained in:
parent
655ff36351
commit
d44691a5b0
2 changed files with 24 additions and 6 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/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;
|
errno = 0;
|
||||||
retvalue = true;
|
retvalue = true;
|
||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (errno == ENOTDIR)
|
if (errno == ENOTDIR || errno == ENOENT)
|
||||||
retvalue = false;
|
retvalue = false;
|
||||||
if (dir != NULL)
|
if (dir != NULL)
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
@ -52,9 +52,11 @@ static bool ft_is_directory(char *path)
|
||||||
static int ft_execve(char *exe, char **argv, char **envp)
|
static int ft_execve(char *exe, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
int retvalue;
|
int retvalue;
|
||||||
|
int olderrno;
|
||||||
|
|
||||||
retvalue = 127;
|
retvalue = 127;
|
||||||
execve(exe, argv, envp);
|
execve(exe, argv, envp);
|
||||||
|
olderrno = errno;
|
||||||
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],
|
||||||
|
|
@ -62,10 +64,8 @@ static int ft_execve(char *exe, char **argv, char **envp)
|
||||||
retvalue = 126;
|
retvalue = 126;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
ft_dprintf(STDERR_FILENO, "minishell: %s: %s\n", argv[0],
|
||||||
ft_dprintf(STDERR_FILENO, "minishell: %s: ", argv[0]);
|
strerror(olderrno));
|
||||||
ft_perror(NULL);
|
|
||||||
}
|
|
||||||
free(exe);
|
free(exe);
|
||||||
path_split_destroy(argv);
|
path_split_destroy(argv);
|
||||||
path_split_destroy(envp);
|
path_split_destroy(envp);
|
||||||
|
|
|
||||||
18
test.sh
18
test.sh
|
|
@ -714,4 +714,22 @@ minishell: : command not found
|
||||||
not printed
|
not printed
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "absolute path to command which does not exist"
|
||||||
|
/cmd/does/not/exist
|
||||||
|
echo \$?
|
||||||
|
EOF
|
||||||
|
expecting <<EOF
|
||||||
|
minishell: /cmd/does/not/exist: No such file or directory
|
||||||
|
127
|
||||||
|
EOF
|
||||||
|
|
||||||
|
when_run <<EOF "?\$HOME"
|
||||||
|
?\$HOME
|
||||||
|
echo \$?
|
||||||
|
EOF
|
||||||
|
expecting <<EOF
|
||||||
|
minishell: ?/home/khais: No such file or directory
|
||||||
|
127
|
||||||
|
EOF
|
||||||
|
|
||||||
finalize
|
finalize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue