Updated to fully support heredocs with no fd leaks

This commit is contained in:
Maieul BOYER 2024-09-04 17:06:29 +00:00
parent 980cae5597
commit 8146ed2176
4 changed files with 16 additions and 5 deletions

View file

@ -10,6 +10,7 @@
/* */
/* ************************************************************************** */
#include "me/fs/fs.h"
#include "me/mem/mem.h"
#include "me/os/os.h"
#include "me/printf/printf.h"
@ -42,7 +43,7 @@ t_error spawn_process_exec(t_spawn_info info, t_process *process)
close_fd(info.stdout.fd.fd);
close_fd(info.stderr.fd.fd);
vec_str_push(&info.arguments, NULL);
vec_str_push(&info.environement, NULL);
vec_str_push(&info.environement, NULL);
execve(info.binary_path, info.arguments.buffer, info.environement.buffer);
return (ERROR);
}

View file

@ -37,20 +37,28 @@ t_error _handle_redirections_inherited(t_spawn_info *info, t_process *process)
t_error _handle_redirections_fds(t_spawn_info *info, t_process *process)
{
t_fd *tmp;
if (info->stdin.tag == R_FD)
{
tmp = info->stdin.fd.fd;
info->stdin = fd(dup_fd(info->stdin.fd.fd));
process->stdin = dup_fd(info->stdin.fd.fd);
close_fd(tmp);
}
if (info->stdout.tag == R_FD)
{
tmp = info->stdin.fd.fd;
info->stdout = fd(dup_fd(info->stdout.fd.fd));
process->stdout = dup_fd(info->stdout.fd.fd);
close_fd(tmp);
}
if (info->stderr.tag == R_FD)
{
tmp = info->stdin.fd.fd;
info->stderr = fd(dup_fd(info->stderr.fd.fd));
process->stderr = dup_fd(info->stderr.fd.fd);
close_fd(tmp);
}
return (NO_ERROR);
}