multiple fixes
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/02/10 22:22:06 by sede-san #+# #+# */
|
/* Created: 2026/02/10 22:22:06 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/12 02:55:36 by sede-san ### ########.fr */
|
/* Updated: 2026/02/14 06:58:05 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -29,3 +29,10 @@ void malloc_error(void)
|
|||||||
{
|
{
|
||||||
ft_eprintf("minishell: %s\n", strerror(ENOMEM));
|
ft_eprintf("minishell: %s\n", strerror(ENOMEM));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void command_not_found_error(
|
||||||
|
const char *command
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ft_eprintf("minishell: %s: command not found\n", command);
|
||||||
|
}
|
||||||
@@ -6,12 +6,13 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/02/11 00:00:00 by sede-san #+# #+# */
|
/* Created: 2026/02/11 00:00:00 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/14 01:34:37 by sede-san ### ########.fr */
|
/* Updated: 2026/02/14 13:12:58 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "executor.h"
|
#include "executor.h"
|
||||||
#include "builtins.h"
|
#include "builtins.h"
|
||||||
|
#include "errors.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static uint8_t resolve_execve_status(void)
|
static uint8_t resolve_execve_status(void)
|
||||||
@@ -60,10 +61,7 @@ static void execute_external_command(
|
|||||||
|
|
||||||
envp = get_envp(minishell);
|
envp = get_envp(minishell);
|
||||||
if (envp == NULL)
|
if (envp == NULL)
|
||||||
{
|
return (malloc_error(), exit(EXIT_FAILURE));
|
||||||
perror("get_envp");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
execve(command->path, command->argv, envp);
|
execve(command->path, command->argv, envp);
|
||||||
handle_execve_error(command, envp);
|
handle_execve_error(command, envp);
|
||||||
}
|
}
|
||||||
@@ -81,10 +79,7 @@ uint8_t executor_execute_command(
|
|||||||
free(command->path);
|
free(command->path);
|
||||||
command->path = executor_resolve_command_path(command, minishell);
|
command->path = executor_resolve_command_path(command, minishell);
|
||||||
if (command->path == NULL)
|
if (command->path == NULL)
|
||||||
{
|
return (command_not_found_error(command->argv[0]), 127);
|
||||||
ft_eprintf("minishell: %s: command not found\n", command->argv[0]);
|
|
||||||
return (127);
|
|
||||||
}
|
|
||||||
execute_external_command(command, minishell);
|
execute_external_command(command, minishell);
|
||||||
return (EXIT_FAILURE);
|
return (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/02/08 19:10:47 by sede-san #+# #+# */
|
/* Created: 2026/02/08 19:10:47 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/11 00:00:00 by sede-san ### ########.fr */
|
/* Updated: 2026/02/14 13:10:43 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/02/11 00:00:00 by sede-san #+# #+# */
|
/* Created: 2026/02/11 00:00:00 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/14 01:17:01 by sede-san ### ########.fr */
|
/* Updated: 2026/02/14 13:16:15 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ static char *resolve_path_from_env(
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
command_path = NULL;
|
command_path = NULL;
|
||||||
i = -1;
|
i = -1;
|
||||||
while (!command_path && path_env[++i] != NULL)
|
while (command_name[0] != 0 && !command_path && path_env[++i] != NULL)
|
||||||
{
|
{
|
||||||
command_path = ft_strnjoin(3, path_env[i], "/", command_name);
|
command_path = ft_strnjoin(3, path_env[i], "/", command_name);
|
||||||
if (command_path != NULL && access(command_path, X_OK) != EXIT_SUCCESS)
|
if (command_path != NULL && access(command_path, X_OK) != EXIT_SUCCESS)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/10/20 20:51:33 by sede-san #+# #+# */
|
/* Created: 2025/10/20 20:51:33 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/14 02:23:17 by sede-san ### ########.fr */
|
/* Updated: 2026/02/14 12:57:00 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2026/02/13 21:09:23 by sede-san #+# #+# */
|
/* Created: 2026/02/13 21:09:23 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/13 21:09:23 by sede-san ### ########.fr */
|
/* Updated: 2026/02/14 13:03:15 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ bool handle_eof(
|
|||||||
return (false);
|
return (false);
|
||||||
if (isatty(STDIN_FILENO))
|
if (isatty(STDIN_FILENO))
|
||||||
ft_putendl("exit");
|
ft_putendl("exit");
|
||||||
|
free(line);
|
||||||
minishell->exit = true;
|
minishell->exit = true;
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
/* By: sede-san <sede-san@student.42madrid.com +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/12/01 09:12:39 by sede-san #+# #+# */
|
/* Created: 2025/12/01 09:12:39 by sede-san #+# #+# */
|
||||||
/* Updated: 2026/02/14 01:32:42 by sede-san ### ########.fr */
|
/* Updated: 2026/02/14 13:30:34 by sede-san ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -59,19 +59,13 @@ void set_env(
|
|||||||
char *old_value;
|
char *old_value;
|
||||||
|
|
||||||
environment = minishell->variables.environment;
|
environment = minishell->variables.environment;
|
||||||
key = (char *)name;
|
if (name != NULL && !ft_hashmap_contains_key(environment, name))
|
||||||
if (key != NULL && !ft_hashmap_contains_key(environment, key))
|
|
||||||
{
|
{
|
||||||
key = ft_strdup(name);
|
key = ft_strdup(name);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
{
|
return (minishell->exit = true, malloc_error());
|
||||||
minishell->exit = true;
|
|
||||||
malloc_error();
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val = value;
|
if (value == NULL)
|
||||||
if (val == NULL)
|
|
||||||
val = ft_strdup("");
|
val = ft_strdup("");
|
||||||
else
|
else
|
||||||
val = ft_strdup(value);
|
val = ft_strdup(value);
|
||||||
@@ -79,9 +73,7 @@ void set_env(
|
|||||||
{
|
{
|
||||||
if (key != name)
|
if (key != name)
|
||||||
free(key);
|
free(key);
|
||||||
minishell->exit = true;
|
return (minishell->exit = true, malloc_error());
|
||||||
malloc_error();
|
|
||||||
return ;
|
|
||||||
}
|
}
|
||||||
old_value = ft_hashmap_put(environment, key, val);
|
old_value = ft_hashmap_put(environment, key, val);
|
||||||
if (old_value != NULL)
|
if (old_value != NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user