-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin.c
More file actions
48 lines (43 loc) · 907 Bytes
/
Copy pathbin.c
File metadata and controls
48 lines (43 loc) · 907 Bytes
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
#include "main.h"
int _bin(char *path, char **p, char *duplicate)
{
char initial_path[20] = "/bin/";
int k;
pid_t child;
int status, exit_status;
child = fork();
if (child == -1)
{
perror("Can't create a child process\n");
return(-1);
} else if (child == 0)
{
if ((k = execve(path, p, environ)) == -1)
{
perror("./shell");
exit(-1);
}
else
{
printf("k is: %d\n", k);
exit(0);
}
} else
{
wait(&status);
free(duplicate);
free(p);
p = NULL;
_strcpy(initial_path, "/bin/");
if (WIFEXITED(status))
{
exit_status = WEXITSTATUS(status);
if (exit_status == 0)
{
return 1;
}
return -1;
}
return -1;
}
}