Let environment be inhereted by child processes
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 1 Aug 2024 13:05:00 +0000 (15:05 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 1 Aug 2024 13:05:00 +0000 (15:05 +0200)
By implementing add_exported function.

src/execution.c

index 72be3b30ce1b60941649e3a179c9029cb2ef52c7..c52308548603ba1856c6187b3d1169ad47185541 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/07/21 08:57:54 by ljiriste          #+#    #+#             */
-/*   Updated: 2024/08/01 14:28:28 by ljiriste         ###   ########.fr       */
+/*   Updated: 2024/08/01 15:04:10 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -643,6 +643,8 @@ char        *find_exe(const char *exe_name, const t_execution_env *env)
        char            *res;
 
        path = get_env_var_value(env, "PATH");
+       if (!path)
+               return (NULL);
        paths = ft_split(path, ":");
        if (!paths)
                return (NULL);
@@ -676,6 +678,19 @@ int        dup_redirections(__attribute__((unused)) const t_vec *redirections)
 
 int    add_exported(__attribute__((unused)) t_vec *assignments, __attribute__((unused)) const t_execution_env *env)
 {
+       size_t  i;
+       char    *var;
+       const t_vec     *exported;
+
+       exported = &env->vars->exported;
+       i = 0;
+       while (i < exported->size)
+       {
+               var = ft_strdup(*(char *const *)ft_vec_caccess(exported, i));
+               if (ft_vec_append(assignments, &var) != success)        // Should exported be overwritten?
+                       return (1);
+               ++i;
+       }
        return (0);
 }