-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuting.c
More file actions
54 lines (52 loc) · 1.12 KB
/
executing.c
File metadata and controls
54 lines (52 loc) · 1.12 KB
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
54
#include "simple_shell.h"
/**
* exec_cmd - executes an input command
* @arr: pointer to array of inputs commands
* @env: double pointer to envoiron var
* @v: arg vector
* @l: input from user
* @new_l: input without \n
* @cmdn: no. of input cmds
* Return: -1 failure, 0 success
*/
int exec_cmd(char **arr, char **env, char **v, char *l, char *new_l, int cmdn)
{
pid_t our_pid;
char *cant;
int signal;
struct stat statuses;
if (arr == NULL || *arr == NULL || v == NULL || *v == NULL)
return (-1);
if (env == NULL || *env == NULL)
return (-1);
if (inbuilts(arr, env, l, new_l, cmdn) == 0)
return (0);
our_pid = fork();
if (our_pid == -1)
{
write(STDOUT_FILENO, "forking error", 13);
return (-1);
}
if (our_pid == 0)
{
if (arr[0][0] == '/')
{
if (stat(arr[0], &statuses) == -1)
error_hand(v, arr, cmdn, l, new_l);
if (access(arr[0], X_OK) == -1)
error_hand(v, arr, cmdn, l, new_l);
execve(arr[0], arr, NULL);
}
else
{
cant = pathhand(arr[0], env);
if (cant == NULL)
error_hand(v, arr, cmdn, l, new_l);
else
execve(cant, arr, NULL);
}
}
else
wait(&signal);
return (0);
}