-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_execution.c
53 lines (49 loc) · 1.44 KB
/
handle_execution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* handle_execution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: almelo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/25 15:54:04 by almelo #+# #+# */
/* Updated: 2023/03/04 11:57:22 by almelo ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
//static void deep_free(char **envp)
//{
// size_t i;
//
// i = 0;
// while (envp[i])
// {
// free(envp[i]);
// i++;
// }
// free(envp);
//}
void handle_execution(t_tokenl *token_lst, t_envl *env_lst)
{
char **argv;
char **envp;
char *pathname;
pid_t pid;
argv = get_next_argv(token_lst);
envp = list_to_envp(env_lst);
pathname = get_pathname(argv, env_lst);
pid = fork();
if (pid == 0)
{
if (pathname)
{
if (execve(pathname, argv, envp) == -1)
exit(0);
}
else
exit(0);
}
else
wait(&pid);
//free(argv);
//deep_free(envp);
}