refactor(do_waitpid): put into own file for easier acces from other modules

This commit is contained in:
Khaïs COLIN 2025-04-04 19:56:54 +02:00
parent f9f8a804a3
commit 425722801b
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 54 additions and 17 deletions

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* do_waitpid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/04 19:55:22 by khais #+# #+# */
/* Updated: 2025/04/04 19:55:59 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "do_waitpid.h"
#include "libft.h"
#include <signal.h>
#include <sys/wait.h>
void do_waitpid(t_minishell *app, int pid)
{
int wstatus;
waitpid(pid, &wstatus, 0);
if (WIFEXITED(wstatus))
app->last_return_value = WEXITSTATUS(wstatus);
if (WIFSIGNALED(wstatus))
{
app->last_return_value = 128 + WTERMSIG(wstatus);
if (WTERMSIG(wstatus) == SIGQUIT)
ft_dprintf(STDERR_FILENO, "Quit (core dumped)");
}
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* do_waitpid.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/04 19:54:53 by khais #+# #+# */
/* Updated: 2025/04/04 19:57:07 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef DO_WAITPID_H
# define DO_WAITPID_H
# include "../../minishell.h"
void do_waitpid(t_minishell *app, int pid);
#endif // DO_WAITPID_H

View file

@ -6,16 +6,16 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/27 16:21:56 by khais #+# #+# */
/* Updated: 2025/04/02 19:15:08 by khais ### ########.fr */
/* Updated: 2025/04/04 17:09:39 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "simple_cmd_execute.h"
#include "builtins.h"
#include "signal.h"
#include "subprocess.h"
#include "libft.h"
#include "../../subst/subst.h"
#include "../common/do_waitpid.h"
#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>
@ -27,21 +27,6 @@ static void command_not_found(t_simple_cmd *cmd)
cmd->words->word->word);
}
static void do_waitpid(t_minishell *app, int pid)
{
int wstatus;
waitpid(pid, &wstatus, 0);
if (WIFEXITED(wstatus))
app->last_return_value = WEXITSTATUS(wstatus);
if (WIFSIGNALED(wstatus))
{
app->last_return_value = 128 + WTERMSIG(wstatus);
if (WTERMSIG(wstatus) == SIGQUIT)
ft_dprintf(STDERR_FILENO, "Quit (core dumped)");
}
}
void simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
{
char *exe;