update: still smth to fix

This commit is contained in:
Maieul BOYER 2024-10-13 18:01:30 +02:00
parent d97efa87a7
commit 7e16ea3fe0
No known key found for this signature in database
4 changed files with 16 additions and 12 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
/* Updated: 2024/10/13 17:32:14 by maiboyer ### ########.fr */
/* Updated: 2024/10/13 17:59:35 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -62,6 +62,7 @@ t_error _spawn_cmd_and_run_end(\
struct s_ffree_state ffree;
int status;
status = 0;
ffree = (struct s_ffree_state){.state = state, .cmd_pipe = cmd_pipe};
info.forked_free_args = &ffree;
info.forked_free = (void (*)(void *))_ffree_func;
@ -71,7 +72,7 @@ t_error _spawn_cmd_and_run_end(\
return (close_fd(cmd_pipe.input), out->exit = 127, ERROR);
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
return (out->exit = -1, NO_ERROR);
if (waitpid(out->process.pid, &status, 0) == -1 && errno != ESRCH)
if (waitpid(out->process.pid, &status, 0) == -1 && errno != ECHILD)
return (ERROR);
if (WIFEXITED(status))
out->exit = WEXITSTATUS(status);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/14 12:32:37 by maiboyer #+# #+# */
/* Updated: 2024/10/13 13:58:31 by maiboyer ### ########.fr */
/* Updated: 2024/10/13 18:01:06 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
#include "me/vec/vec_ast.h"
#include "me/vec/vec_pid.h"
#include <errno.h>
#include <stdio.h>
#include <sys/wait.h>
t_usize _pipeline_set_vars(\
@ -47,9 +48,11 @@ void _wait_pipeline(t_vec_pid pids, t_state *state, t_pipeline_result *out)
if (pids.len != 0)
{
waitpid_status = 0;
while (waitpid(pids.buffer[pids.len - 1], &waitpid_status, 0) < 0 \
&& errno != ESRCH)
;
&& errno != ECHILD)
if (errno == ECHILD)
waitpid_status = 0;
while (waitpid(-1, NULL, 0) != -1)
;
if (WIFEXITED(waitpid_status))