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

@ -51,9 +51,10 @@ CFLAGS_ADDITIONAL += -O0
CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits -Wno-unused-command-line-argument CFLAGS_ADDITIONAL += -Wno-cpp -Wno-type-limits -Wno-unused-command-line-argument
CFLAGS_ADDITIONAL += -gcolumn-info -g3 CFLAGS_ADDITIONAL += -gcolumn-info -g3
CFLAGS_ADDITIONAL += '-DERROR=((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)' CFLAGS_ADDITIONAL += '-DERROR=((void)printf("ERROR HERE: " __FILE__ ":%d in %s\n", __LINE__, __func__), 1)'
#CFLAGS_ADDITIONAL += -O2 # CFLAGS_ADDITIONAL += -O2
# CFLAGS_ADDITIONAL += -fuse-ld=gold -Wl,--print-symbol-counts -Wl,/tmp/symbols_count.log # CFLAGS_ADDITIONAL += -fuse-ld=gold -Wl,--print-symbol-counts -Wl,/tmp/symbols_count.log
CFLAGS_ADDITIONAL += -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-O3 -Wl,--allow-multiple-definition # CFLAGS_ADDITIONAL += -fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,-O3 -Wl,--allow-multiple
# CFLAGS_ADDITIONAL += -I$(shell realpath ./includes) -I$(shell realpath ./output/include)
export CFLAGS_ADDITIONAL export CFLAGS_ADDITIONAL
export CC export CC

View file

@ -19,7 +19,7 @@
#define USG "Usage:\n - print_fd: print the opened file descritors informations" #define USG "Usage:\n - print_fd: print the opened file descritors informations"
static t_error _debug_fd(\ t_error _debug_fd(\
t_state *state, t_builtin_spawn_info info, t_i32 *exit_code) t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
{ {
const t_fd_array *fds = get_fd_arrays(); const t_fd_array *fds = get_fd_arrays();
@ -40,7 +40,8 @@ static t_error _debug_fd(\
fds->storage[i].slot.dir.ptr, fds->storage[i].slot.dir.name); fds->storage[i].slot.dir.ptr, fds->storage[i].slot.dir.name);
i++; i++;
} }
*exit_code = 0; if (exit_code != NULL)
*exit_code = 0;
return (NO_ERROR); return (NO_ERROR);
} }

View file

@ -10,6 +10,7 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "me/fs/fs.h"
#include "me/mem/mem.h" #include "me/mem/mem.h"
#include "me/os/os.h" #include "me/os/os.h"
#include "me/printf/printf.h" #include "me/printf/printf.h"

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_error _handle_redirections_fds(t_spawn_info *info, t_process *process)
{ {
t_fd *tmp;
if (info->stdin.tag == R_FD) if (info->stdin.tag == R_FD)
{ {
tmp = info->stdin.fd.fd;
info->stdin = fd(dup_fd(info->stdin.fd.fd)); info->stdin = fd(dup_fd(info->stdin.fd.fd));
process->stdin = dup_fd(info->stdin.fd.fd); process->stdin = dup_fd(info->stdin.fd.fd);
close_fd(tmp);
} }
if (info->stdout.tag == R_FD) if (info->stdout.tag == R_FD)
{ {
tmp = info->stdin.fd.fd;
info->stdout = fd(dup_fd(info->stdout.fd.fd)); info->stdout = fd(dup_fd(info->stdout.fd.fd));
process->stdout = dup_fd(info->stdout.fd.fd); process->stdout = dup_fd(info->stdout.fd.fd);
close_fd(tmp);
} }
if (info->stderr.tag == R_FD) if (info->stderr.tag == R_FD)
{ {
tmp = info->stdin.fd.fd;
info->stderr = fd(dup_fd(info->stderr.fd.fd)); info->stderr = fd(dup_fd(info->stderr.fd.fd));
process->stderr = dup_fd(info->stderr.fd.fd); process->stderr = dup_fd(info->stderr.fd.fd);
close_fd(tmp);
} }
return (NO_ERROR); return (NO_ERROR);
} }