-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrphandle.c
More file actions
59 lines (51 loc) · 1010 Bytes
/
rphandle.c
File metadata and controls
59 lines (51 loc) · 1010 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
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <string.h>
#include <sys/utsname.h>
#include <pwd.h>
#include "builtin.h"
#include "helper.h"
int main_rphandle(char * commands)
{
pid_t pid;
int i, status, input, filedescriptors[2], n = 0;
input = 0;
char * temp = NULL, * pipeCommands[1000], ** args;
while(commands)
{
temp = strsep(&commands, "|");
if(temp != NULL)
{
if(strlen(temp) > 0)
{
pipeCommands[n++] = temp;
}
}
}
if(n > 0)
n--;
for (i = 0; i < n; i++)
{
pipe(filedescriptors);
args = main_delim_split(pipeCommands[i]);
args = main_redirect(args);
main_rpexec(input, args, filedescriptors[1]);
free(args);
close(filedescriptors[1]);
input = filedescriptors[0];
}
if(input != 0)
{
dup2(input, 0);
}
args = main_delim_split(pipeCommands[n]);
args = main_redirect(args);
status = main_execute(args);
free(args);
return status;
}