mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Compare commits
3 commits
74f013e5c6
...
52e109d0b5
| Author | SHA1 | Date | |
|---|---|---|---|
| 52e109d0b5 | |||
| 77015ce27e | |||
| 2fc47345f0 |
4 changed files with 31 additions and 5 deletions
1
Makefile
1
Makefile
|
|
@ -100,6 +100,7 @@ all: $(NAME)
|
|||
$(NAME): $(minishell_objs) $(LIBFT)
|
||||
$(CC) $(CFLAGS) -o $@ $(minishell_objs) $(LINCLUDE) $(LDLIBS)
|
||||
|
||||
$(LIBFT): CFLAGS+=-DBUFFER_SIZE=1
|
||||
$(LIBFT):
|
||||
+$(MAKE) -C $(LIBFTDIR)
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
|
||||
/* Updated: 2025/04/01 16:37:31 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/01 18:08:02 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,6 +17,8 @@
|
|||
#include "../../env/env_convert.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
#include "../../subst/path_split.h"
|
||||
|
||||
static char **argv_from_wordlist(t_wordlist *wordlist)
|
||||
{
|
||||
|
|
@ -39,6 +41,24 @@ static void command_not_found(t_simple_cmd *cmd)
|
|||
cmd->words->word->word);
|
||||
}
|
||||
|
||||
static void ft_execve(char *exe, char **argv, char **envp)
|
||||
{
|
||||
execve(exe, argv, envp);
|
||||
ft_dprintf(STDERR_FILENO, "minishell: %s: ", argv[0]);
|
||||
perror(NULL);
|
||||
free(exe);
|
||||
path_split_destroy(argv);
|
||||
path_split_destroy(envp);
|
||||
}
|
||||
|
||||
static void execute_subprocess(char *exe, t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
ft_execve(exe, argv_from_wordlist(cmd->words), envp_from_env(app->env));
|
||||
simple_cmd_destroy(cmd);
|
||||
env_destroy(app->env);
|
||||
exit(127);
|
||||
}
|
||||
|
||||
void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
char *exe;
|
||||
|
|
@ -56,7 +76,7 @@ void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
|||
}
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
execve(exe, argv_from_wordlist(cmd->words), envp_from_env(app->env));
|
||||
execute_subprocess(exe, cmd, app);
|
||||
free(exe);
|
||||
waitpid(pid, NULL, 0);
|
||||
return ;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */
|
||||
/* Updated: 2025/03/27 18:39:23 by khais ### ########.fr */
|
||||
/* Updated: 2025/04/01 18:38:35 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -77,8 +77,6 @@ static char *select_path(char *filepath, char **oldpath, char **path,
|
|||
else
|
||||
return (free(*oldpath), path_split_destroy(path), filepath);
|
||||
}
|
||||
if (*oldpath != filepath)
|
||||
free(filepath);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
7
test.sh
7
test.sh
|
|
@ -335,6 +335,13 @@ status=1
|
|||
hello=hi
|
||||
EOF
|
||||
|
||||
when_run <<EOF "empty command is not found"
|
||||
""
|
||||
EOF
|
||||
expecting <<EOF
|
||||
minishell: : command not found
|
||||
EOF
|
||||
|
||||
when_run <<EOF "quoted parentheses are not operators"
|
||||
echo unclosed '('
|
||||
EOF
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue