-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_execute.c
45 lines (43 loc) · 959 Bytes
/
_execute.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
#include "shell.h"
/**
* _excute - function that excute commands
* that's not part of builtins
*
* @command: command to be executed
* Return: Nothing(void)
*/
void _excute(command_t *command)
{
int pid, status, err;
pid = fork();
if (pid < 0)
{
perror((char *)_global_states(GET_SHELL_NAME, NULL));
_status_management(UPDATE_STATUS, 1);
return;
}
if (!pid)
{
execve(command->name, command->arguments, __environ);
err = errno;
if (errno == EACCES)
{
_fprint(2, "%s: %d: %s: Permission denied\n",
(char *)_global_states(GET_SHELL_NAME, NULL),
*((int *)_global_states(GET_LINE_NUMBER, NULL)),
command->name);
err = 126;
}
else
perror(_global_states(GET_SHELL_NAME, NULL));
_free_command(command);
free(_global_states(GET_LINE, NULL));
_enviroment_management(CLEAR_ENV, NULL, NULL);
_exit(err);
}
else
{
waitpid(pid, &status, 0);
_status_management(UPDATE_STATUS, WEXITSTATUS(status));
}
}