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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#include <unistd.h>
#include "syntax.h"
void exec_cmd(ExecutableCommand cmd, int* pgid) {
pid_t pid = fork();
if (pid == 0) {
if (*pgid == -1) {
setpgid(0, 0);
} else {
setpgid(0, *pgid);
}
dup2(cmd.stdin_fd, STDIN_FILENO);
dup2(cmd.stdout_fd, STDOUT_FILENO);
for (int i = 0; i < cmd.open_fds.count; i++) {
FdRedirect fd_rd = *get_from_FdRedirectVec(&cmd.redirects, i);
dup2(fd_rd.to, fd_rd.redirected);
}
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGTSTP, SIG_DFL);
signal(SIGTTIN, SIG_DFL);
signal(SIGTTOU, SIG_DFL);
execvp(cmd.args[0], cmd.args);
exit(67);
}
if (*pgid == -1) {
setpgid(pid, pid);
*pgid = pid;
} else {
setpgid(pid, *pgid);
}
}
ExecutableCommand process_pl_command(PlCommand pl_cmd) {
StrVec arg_vec = make_StrVec(256);
for (int i = 0; i < pl_cmd.args.count; i++) {
Arg arg = *get_from_ArgVec(&pl_cmd.args, i);
switch (arg.kind) {
case ARG_LIT:
push_to_StrVec(&arg_vec, arg.as.lit_str);
break;
default:
exit(67);
}
}
FdRedirectVec fd_redirs = make_FdRedirectVec(256);
for (int j = 0; j < pl_cmd.redirects.count, j++) {
Redirect redir = *get_from_RedirectVec(&pl_cmd.redirects, j);
FdRedirect fd_redir;
int fd;
switch (redir.kind) {
case REDIR_FILE_IN:
fd =
}
}
}
void execute_command_pipeline(PlCommand* pipeline) {
int trunk_fd = STDIN_FILENO;
int pgid = -1;
size_t i = 0;
Connector last_conn;
do {
PlCommand cmd = pipeline[i];
} while (last_conn != CONN_EOL);
}
|