Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yabtaour
GitHub Repository: yabtaour/Minishell-42
Path: blob/main/execution/execution_utils.c
1407 views
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* execution_utils.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: ssabbaji <[email protected]> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2022/10/02 10:39:20 by ssabbaji #+# #+# */
9
/* Updated: 2022/10/03 15:29:52 by ssabbaji ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
13
#include "../minishell.h"
14
15
int ft_statushandling(int status)
16
{
17
if (WIFSIGNALED(status))
18
{
19
if (WTERMSIG(status) == 3)
20
write(2, "Quit: 3\n", 8);
21
if (WTERMSIG(status) == 2)
22
write(2, "\n", 1);
23
return (128 + WTERMSIG(status));
24
}
25
else if (WIFEXITED(status))
26
return (WEXITSTATUS(status));
27
return (1);
28
}
29
30
int terminate_pid(pid_t lastchild)
31
{
32
int status;
33
34
waitpid(lastchild, &status, 0);
35
while (wait(NULL) != -1)
36
;
37
return (ft_statushandling(status));
38
}
39
40
int check_path(t_env *lst_env)
41
{
42
while (lst_env && lst_env->name)
43
{
44
if (!ft_strcmp(lst_env->name, "PATH"))
45
return (1);
46
lst_env = lst_env->next;
47
}
48
return (0);
49
}
50
51