update: fixed error on pipe+redirection
This commit is contained in:
parent
1dfb7f7ef7
commit
baa9af918f
9 changed files with 34 additions and 37 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:31:28 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/10 18:54:14 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:16:18 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -56,7 +56,6 @@ t_error _run_other(t_ast_node self, t_state *state, int *out)
|
|||
*out = subshell_res.exit;
|
||||
}
|
||||
state->last_exit = *out;
|
||||
printf("state->last_exit = %i\n", state->last_exit);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/18 21:51:46 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:19:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ put_string_fd(lstate.output_fd, "^C\n"), line_refresh_line(&lstate), ERROR);
|
|||
}
|
||||
}
|
||||
line_edit_stop(&lstate);
|
||||
if (line == NULL || str_compare(delim, line))
|
||||
if (line == NULL || (str_compare(delim, line) && (str_free(line), 1)))
|
||||
break ;
|
||||
(put_string_fd(write, line), put_char_fd(write, '\n'), str_free(line));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:24:49 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/10 18:56:40 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:16:01 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -117,7 +117,6 @@ t_error _handle_builtin(t_spawn_info info, t_state *state, t_cmd_pipe cmd_pipe,
|
|||
return (ERROR);
|
||||
if (_setup_binfo(&info, &binfo, out))
|
||||
return (ERROR);
|
||||
printf("last_exit = %i\n", state->last_exit);
|
||||
_run_builtin(&binfo, actual_func, cmd_pipe, out);
|
||||
if (binfo.stdin)
|
||||
close_fd(binfo.stdin);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:38:38 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/10 18:58:52 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:16:10 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -54,7 +54,6 @@ t_error _run_expansion_special_var(t_ast_expansion *self, t_state *state,
|
|||
if (name == '?')
|
||||
{
|
||||
*out = (t_expansion_result){.exists = true, .value = NULL};
|
||||
printf("state->last_exit in exp = %i \n", state->last_exit);
|
||||
if (i32_to_str(state->last_exit, &out->value)) // TODO: fix this shit
|
||||
return (ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/02 18:41:16 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/10 17:25:40 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 21:33:34 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -67,8 +67,6 @@ t_error ts_apply_passes(t_vec_token ts, t_vec_token *out)
|
|||
if ((g_ts_passes[i].fn)(ts, &next))
|
||||
return (me_eprintf("failed on %s token pass\n", \
|
||||
g_ts_passes[i].name), ERROR);
|
||||
else
|
||||
me_printf("Applied '%s' pass\n", g_ts_passes[i].name);
|
||||
ts = next;
|
||||
i++;
|
||||
}
|
||||
|
|
@ -94,8 +92,6 @@ t_error ts_dq_apply_passes(t_vec_token ts, t_vec_token *out)
|
|||
if ((g_ts_dq_passes[i].fn)(ts, &next))
|
||||
return (me_eprintf(\
|
||||
"failed on '%s' dq token pass\n", g_ts_dq_passes[i].name), ERROR);
|
||||
else
|
||||
me_printf("Applied '%s' dq_pass\n", g_ts_dq_passes[i].name);
|
||||
ts = next;
|
||||
i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/09 12:44:53 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/10 17:48:57 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 15:12:36 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,7 +34,7 @@ static t_error _create_ast_redir(enum e_token ty, t_ast_node *out)
|
|||
ret = ast_alloc(AST_HEREDOC_REDIRECTION);
|
||||
ret->data.heredoc_redirection.op = AST_REDIR_HEREDOC;
|
||||
}
|
||||
else if (ty == TOK_DRCARRET || ty == TOK_LCARRET || ty == TOK_DRCARRET)
|
||||
else if (ty == TOK_RCARRET || ty == TOK_LCARRET || ty == TOK_DRCARRET)
|
||||
ret = ast_alloc(AST_FILE_REDIRECTION);
|
||||
else
|
||||
return (ERROR);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/07 11:08:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/04 14:28:13 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:15:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/11 11:47:20 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:19:32 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fcntl.h"
|
||||
#include "me/fs/fs.h"
|
||||
#include "me/mem/mem.h"
|
||||
#include "me/os/os.h"
|
||||
|
|
@ -29,6 +30,7 @@ t_error handle_redirections(t_spawn_info *info, t_process *process);
|
|||
|
||||
t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
||||
{
|
||||
(void)(process);
|
||||
if (info.forked_free)
|
||||
info.forked_free(info.forked_free_args);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
|
|
@ -36,12 +38,12 @@ t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
|||
dup2(info.stdin.fd.fd->fd, 0);
|
||||
dup2(info.stdout.fd.fd->fd, 1);
|
||||
dup2(info.stderr.fd.fd->fd, 2);
|
||||
close_fd(process->stdin);
|
||||
close_fd(process->stdout);
|
||||
close_fd(process->stderr);
|
||||
close_fd(info.stdin.fd.fd);
|
||||
close_fd(info.stdout.fd.fd);
|
||||
close_fd(info.stderr.fd.fd);
|
||||
if (info.stdin.fd.fd->fd != 0)
|
||||
close_fd(info.stdin.fd.fd);
|
||||
if (info.stdout.fd.fd->fd != 1)
|
||||
close_fd(info.stdout.fd.fd);
|
||||
if (info.stderr.fd.fd->fd != 2)
|
||||
close_fd(info.stderr.fd.fd);
|
||||
vec_str_push(&info.arguments, NULL);
|
||||
vec_str_push(&info.environement, NULL);
|
||||
execve(info.binary_path, info.arguments.buffer, info.environement.buffer);
|
||||
|
|
@ -62,7 +64,6 @@ t_error in_path(t_spawn_info *info, t_process *process, t_const_str path_raw,
|
|||
{
|
||||
string_clear(s);
|
||||
me_printf_str(s, "%s/%s", path.buffer[idx++], info->binary_path);
|
||||
printf("testing %s\n", s->buf);
|
||||
if (access(s->buf, X_OK) == 0)
|
||||
return (vec_str_free(path), NO_ERROR);
|
||||
}
|
||||
|
|
@ -105,9 +106,12 @@ static void _process_cleanup(t_spawn_info info, t_process *process, \
|
|||
close_fd(process->stdout);
|
||||
if (cleanup_process && process->stderr)
|
||||
close_fd(process->stderr);
|
||||
close_fd(info.stdin.fd.fd);
|
||||
close_fd(info.stdout.fd.fd);
|
||||
close_fd(info.stderr.fd.fd);
|
||||
if (info.stdin.fd.fd->fd != 0)
|
||||
close_fd(info.stdin.fd.fd);
|
||||
if (info.stdout.fd.fd->fd != 1)
|
||||
close_fd(info.stdout.fd.fd);
|
||||
if (info.stderr.fd.fd->fd != 2)
|
||||
close_fd(info.stderr.fd.fd);
|
||||
vec_str_free(info.arguments);
|
||||
vec_str_free(info.environement);
|
||||
mem_free(info.binary_path);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/04 22:27:00 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/06 15:28:26 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/11 22:10:05 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,18 +19,18 @@ t_error _handle_redirections_inherited(t_spawn_info *info, t_process *process)
|
|||
(void)(process);
|
||||
if (info->stdin.tag == R_INHERITED)
|
||||
{
|
||||
info->stdin = fd(dup_fd(get_stdin()));
|
||||
process->stdin = dup_fd(get_stdin());
|
||||
info->stdin = fd(get_stdin());
|
||||
process->stdin = NULL;
|
||||
}
|
||||
if (info->stdout.tag == R_INHERITED)
|
||||
{
|
||||
info->stdout = fd(dup_fd(get_stdout()));
|
||||
process->stdout = dup_fd(get_stdout());
|
||||
info->stdout = fd(get_stdout());
|
||||
process->stdout = NULL;
|
||||
}
|
||||
if (info->stderr.tag == R_INHERITED)
|
||||
{
|
||||
info->stderr = fd(dup_fd(get_stderr()));
|
||||
process->stderr = dup_fd(get_stderr());
|
||||
info->stderr = fd(get_stderr());
|
||||
process->stderr = NULL;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
@ -40,17 +40,17 @@ t_error _handle_redirections_fds(t_spawn_info *info, t_process *process)
|
|||
if (info->stdin.tag == R_FD)
|
||||
{
|
||||
info->stdin = fd(dup_fd(info->stdin.fd.fd));
|
||||
process->stdin = dup_fd(info->stdin.fd.fd);
|
||||
process->stdin = NULL;
|
||||
}
|
||||
if (info->stdout.tag == R_FD)
|
||||
{
|
||||
info->stdout = fd(dup_fd(info->stdout.fd.fd));
|
||||
process->stdout = dup_fd(info->stdout.fd.fd);
|
||||
process->stdout = NULL;
|
||||
}
|
||||
if (info->stderr.tag == R_FD)
|
||||
{
|
||||
info->stderr = fd(dup_fd(info->stderr.fd.fd));
|
||||
process->stderr = dup_fd(info->stderr.fd.fd);
|
||||
process->stderr = NULL;
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue