mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-16 03:46:50 +01:00
「🔨」 fix(exec/exec_cmd): fixed sigpipe leaks when forked :D
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
/* Created: 2024/04/29 13:20:22 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/08/13 16:35:17 by mmoussou ### ########.fr */
|
/* Updated: 2024/08/13 18:39:43 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -43,6 +43,9 @@ void ft_arrcpy(int *dst, int *src, int n);
|
|||||||
|
|
||||||
int close_cmd(t_cmd *cmd);
|
int close_cmd(t_cmd *cmd);
|
||||||
|
|
||||||
|
char **get_env_arr(char **env);
|
||||||
|
void sig_p(int code);
|
||||||
|
|
||||||
void exec_cmd(t_cmd *cmd, char **env, t_env *env_t);
|
void exec_cmd(t_cmd *cmd, char **env, t_env *env_t);
|
||||||
void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec);
|
void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec);
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/15 12:28:36 by adjoly #+# #+# */
|
/* Created: 2024/07/15 12:28:36 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/08/11 11:58:17 by adjoly ### ########.fr */
|
/* Updated: 2024/08/13 17:30:02 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/15 21:03:31 by mmoussou #+# #+# */
|
/* Created: 2024/07/15 21:03:31 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/08/13 17:06:23 by mmoussou ### ########.fr */
|
/* Updated: 2024/08/13 18:39:22 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -50,8 +50,6 @@ void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
|
|||||||
exec.status = dup2(cmd->infile, STDIN_FILENO);
|
exec.status = dup2(cmd->infile, STDIN_FILENO);
|
||||||
if (cmd->infile != STDIN_FILENO)
|
if (cmd->infile != STDIN_FILENO)
|
||||||
close(cmd->infile);
|
close(cmd->infile);
|
||||||
if (exec.status == -1)
|
|
||||||
exit(-1);
|
|
||||||
exec.status = dup2(cmd->outfile, STDOUT_FILENO);
|
exec.status = dup2(cmd->outfile, STDOUT_FILENO);
|
||||||
if (cmd->outfile != STDOUT_FILENO)
|
if (cmd->outfile != STDOUT_FILENO)
|
||||||
close(cmd->outfile);
|
close(cmd->outfile);
|
||||||
@ -65,9 +63,10 @@ void __fork_single_cmd(t_cmd *cmd, char **env, t_env *env_t, t_exec exec)
|
|||||||
close(STDOUT_FILENO);
|
close(STDOUT_FILENO);
|
||||||
i = 2;
|
i = 2;
|
||||||
while (i++ < 1023)
|
while (i++ < 1023)
|
||||||
{
|
|
||||||
close(i);
|
close(i);
|
||||||
}
|
get_env_arr(env);
|
||||||
|
if (is_in_builtins(cmd->cmd))
|
||||||
|
signal(SIGPIPE, sig_p);
|
||||||
exec_cmd(cmd, env, env_t);
|
exec_cmd(cmd, env, env_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
/* Created: 2024/06/01 14:55:06 by mmoussou #+# #+# */
|
||||||
/* Updated: 2024/08/13 16:54:52 by mmoussou ### ########.fr */
|
/* Updated: 2024/08/13 18:38:18 by mmoussou ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
33
src/exec/sigpipe.c
Normal file
33
src/exec/sigpipe.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sigpipe.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/08/13 18:23:24 by mmoussou #+# #+# */
|
||||||
|
/* Updated: 2024/08/13 18:40:19 by mmoussou ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
#include "builtins.h"
|
||||||
|
|
||||||
|
char **get_env_arr(char **env)
|
||||||
|
{
|
||||||
|
static char **ret;
|
||||||
|
|
||||||
|
if (env)
|
||||||
|
ret = env;
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sig_p(int code)
|
||||||
|
{
|
||||||
|
t_env **env;
|
||||||
|
|
||||||
|
(void) code;
|
||||||
|
env = get_env(NULL);
|
||||||
|
free_exit(*env, get_env_arr(NULL));
|
||||||
|
exit(141);
|
||||||
|
}
|
Reference in New Issue
Block a user