mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
fix(waitpid): remove spurious call & handle errors
This commit is contained in:
parent
505a96eeef
commit
255a1382da
2 changed files with 11 additions and 4 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/04 19:55:22 by khais #+# #+# */
|
/* Created: 2025/04/04 19:55:22 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/04 19:55:59 by khais ### ########.fr */
|
/* Updated: 2025/04/28 12:29:50 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,12 +14,18 @@
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
void do_waitpid(t_minishell *app, int pid)
|
void do_waitpid(t_minishell *app, int pid)
|
||||||
{
|
{
|
||||||
int wstatus;
|
int wstatus;
|
||||||
|
|
||||||
waitpid(pid, &wstatus, 0);
|
wstatus = 0;
|
||||||
|
if (waitpid(pid, &wstatus, 0) == -1)
|
||||||
|
{
|
||||||
|
app->last_return_value = 255;
|
||||||
|
perror("waitpid");
|
||||||
|
}
|
||||||
if (WIFEXITED(wstatus))
|
if (WIFEXITED(wstatus))
|
||||||
app->last_return_value = WEXITSTATUS(wstatus);
|
app->last_return_value = WEXITSTATUS(wstatus);
|
||||||
if (WIFSIGNALED(wstatus))
|
if (WIFSIGNALED(wstatus))
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/04 19:50:42 by khais #+# #+# */
|
/* Created: 2025/04/04 19:50:42 by khais #+# #+# */
|
||||||
/* Updated: 2025/04/16 16:45:28 by khais ### ########.fr */
|
/* Updated: 2025/04/28 12:29:34 by khais ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -22,6 +22,7 @@ void group_cmd_execute(t_group_cmd *cmd, t_minishell *app, bool should_exit)
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
cmd_execute(cmd->cmd, app, true);
|
cmd_execute(cmd->cmd, app, true);
|
||||||
|
else
|
||||||
do_waitpid(app, pid);
|
do_waitpid(app, pid);
|
||||||
if (should_exit)
|
if (should_exit)
|
||||||
exit(app->last_return_value);
|
exit(app->last_return_value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue