Remove may_exit member of env
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Tue, 27 Aug 2024 15:02:44 +0000 (17:02 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Tue, 27 Aug 2024 15:02:44 +0000 (17:02 +0200)
This was implemented to mimic the behaviour of piped exit.
But bash just runs piped commands in separate processes which leads to
piped builtins not having effect on the current session.
So I think it will be more pure without this check and if the bash
behaviour is needed, piping may be delegated to forked processes.

inc/minishell_structs.h
src/builtins/exit.c
src/execution.c

index 20b2085c07351f3880a8a231e03a5c3f134c11d6..5c9f5ba8cf1c18639d120fca44a841df9ea12501 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/26 09:08:46 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/27 15:03:52 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/27 16:59:59 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -31,7 +31,6 @@ typedef struct s_execution_env
        int             stdin_fd;
        int             stdout_fd;
        int             ret_val;
-       int             may_exit;
        int             exit;
        int             last_was_builtin;
        int             last_builtin_ret_val;
index 7a978a239ae0a5e145136b5fe6b9b7c680a5d10d..149397bc89bd57288ef5ccefd97026e48650deff 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/27 14:49:17 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/27 15:05:25 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/27 17:00:31 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -32,8 +32,7 @@ int   is_numeric(const char *str)
 
 int    execute_exit(int argc, char **argv, t_execution_env *env)
 {
-       if (env->may_exit)
-               env->exit = 1;
+       env->exit = 1;
        if (argc == 1)
                return (0);
        if (argc > 2)
index b8db20e2b4649a522354b1863d0bd73203f4b1e2..9a07f8248c0dbe7ccd382ee46f84f93127808630 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/07/21 08:57:54 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/27 16:32:09 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/27 16:59:59 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -1008,10 +1008,8 @@ int      ex_pipeline(t_parse_tree_node *pipeline, t_execution_env *env, int depth)
 
        if (pipeline->children.size == 1)
        {
-               env->may_exit = (depth == 0);
                if (ex_command(ft_vec_access(&pipeline->children, 0), env))
                        return (1);
-               env->may_exit = 0;
        }
        else
        {