From 1bf5d8358689c27b4eb5ab202bba9daca2c03374 Mon Sep 17 00:00:00 2001 From: yosyo Date: Wed, 14 Aug 2024 08:11:04 +0200 Subject: [PATCH] =?UTF-8?q?=E3=80=8C=F0=9F=94=A8=E3=80=8D=20fix:=20fixed?= =?UTF-8?q?=20=20being=20treated=20as=20a=20folder,=20and=20some=20exit=20?= =?UTF-8?q?codes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/ft_export.c | 2 +- src/builtins/ft_export_utils.c | 17 +++++++++-------- src/exec/exec_cmd.c | 4 ++-- src/exec/exec_split_cmd.c | 10 +++++++--- src/exec/utils_exec.c | 13 ++++++++++--- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/builtins/ft_export.c b/src/builtins/ft_export.c index e4a1851..05c59ab 100644 --- a/src/builtins/ft_export.c +++ b/src/builtins/ft_export.c @@ -6,7 +6,7 @@ /* By: mmoussou argv + 1, env_t, cmd->outfile); + ft_export(cmd->argv + 1, env_t, STDOUT_FILENO); if (i == 3) ft_unset(&(cmd->argv)[1], env_t); if (i == 7) diff --git a/src/exec/exec_split_cmd.c b/src/exec/exec_split_cmd.c index a7619c3..fc8d952 100644 --- a/src/exec/exec_split_cmd.c +++ b/src/exec/exec_split_cmd.c @@ -6,7 +6,7 @@ /* By: mmoussou cmd, input)) { + if (exec.status == -1) + get_exit_code(127); if (exec.status == -1) printf("minishell : command not found: %s\n", input); free(input); - return (get_exit_code(127)); + return (-1); } free(input); fork_pid = fork(); @@ -64,10 +66,12 @@ int exec_single_cmd(t_cmd *cmd, char **env, t_env *env_t, int pipe_fd[2]) exec.status = switch_cmd_path(cmd, env_t); if (exec.status == -1 || !input || check_file(cmd->cmd, input)) { + if (exec.status == -1) + get_exit_code(127); if (exec.status == -1) printf("minishell : command not found: %s\n", input); free(input); - return (get_exit_code(127)); + return (-1); } free(input); exec.status = exec_single_cmd_execution(cmd, env, env_t, exec); diff --git a/src/exec/utils_exec.c b/src/exec/utils_exec.c index 416892e..10aeb89 100644 --- a/src/exec/utils_exec.c +++ b/src/exec/utils_exec.c @@ -6,7 +6,7 @@ /* By: mmoussou cmd)) + if (is_in_builtins(cmd->cmd) || !cmd->cmd || !cmd->cmd[0]) return (0); if (cmd->cmd[0] == '.' && cmd->cmd[1] == '/') cmd->cmd = get_cmd_local_path(cmd->cmd, env); @@ -100,16 +100,23 @@ int check_file(char *cmd, char *input) if (is_in_builtins(cmd)) return (0); status = stat(cmd, &entry); - if (status) + if (status || !cmd || !*cmd) { + get_exit_code(127); printf("minishell : command not found: %s\n", input); return (1); } if (!S_ISDIR(entry.st_mode) && !access(cmd, X_OK)) return (0); if (S_ISDIR(entry.st_mode)) + { + get_exit_code(126); printf("minishell : %s is a directory.\n", input); + } else + { + get_exit_code(127); printf("minishell : command not found: %s\n", input); + } return (1); }