mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
refactor(do_waitpid): put into own file for easier acces from other modules
This commit is contained in:
parent
f9f8a804a3
commit
425722801b
4 changed files with 54 additions and 17 deletions
31
src/executing/common/do_waitpid.c
Normal file
31
src/executing/common/do_waitpid.c
Normal 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)");
|
||||
}
|
||||
}
|
||||
20
src/executing/common/do_waitpid.h
Normal file
20
src/executing/common/do_waitpid.h
Normal 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
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue