summaryrefslogtreecommitdiff
path: root/redes/exec.c
diff options
context:
space:
mode:
authorÁkos Kőrösi <korakos99@gmail.com>2026-05-20 23:59:56 +0200
committerÁkos Kőrösi <korakos99@gmail.com>2026-05-20 23:59:56 +0200
commita5a26f986b6d34269c17f45a98625979da3b7136 (patch)
treeb10a5d17c2261952a662b7393edda91bb1ee3b96 /redes/exec.c
parente7169456fb85d481a703432dc472cd5fc25f849e (diff)
work on redesign
Diffstat (limited to 'redes/exec.c')
-rw-r--r--redes/exec.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/redes/exec.c b/redes/exec.c
index f7928af..437dfbe 100644
--- a/redes/exec.c
+++ b/redes/exec.c
@@ -1,4 +1,6 @@
#include <unistd.h>
+#include <fcntl.h>
+
#include "syntax.h"
@@ -56,12 +58,12 @@ ExecutableCommand process_pl_command(PlCommand pl_cmd) {
FdRedirectVec fd_redirs = make_FdRedirectVec(256);
IntVec open_fds = make_IntVec(256);
- for (int j = 0; j < pl_cmd.redirects.count, j++) {
+ 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:
+ case REDIR_READ:
fd = open(redir.as.filename, O_RDONLY, 0644);
push_to_IntVec(&open_fds, fd);
fd_redir = (FdRedirect){.to = fd, .redirected = STDIN_FILENO};
@@ -80,7 +82,7 @@ ExecutableCommand process_pl_command(PlCommand pl_cmd) {
exit(67);
}
push_to_FdRedirectVec(&fd_redirs, fd_redir);
- }
+}
char** args = malloc(sizeof(char*) * (arg_vec.count + 1));
for (int i = 0; i < arg_vec.count; i++) {
@@ -92,14 +94,14 @@ ExecutableCommand process_pl_command(PlCommand pl_cmd) {
}
-void execute_command_pipeline(PlCommand* pipeline) {
+void execute_command_pipeline(Pipeline pipeline) {
int trunk_fd = STDIN_FILENO;
int pgid = -1;
size_t i = 0;
- Connector last_conn;
- do {
- PlCommand cmd = pipeline[i];
+
+ for (int i = 0; i < pipeline.count; i++) {
+ PlCommand cmd = *get_from_Pipeline(&pipeline, i);
ExecutableCommand exec_cmd = process_pl_command(cmd);
exec_cmd.stdin_fd = trunk_fd;
exec_cmd.stdout_fd = STDOUT_FILENO;
@@ -115,13 +117,16 @@ void execute_command_pipeline(PlCommand* pipeline) {
execute_cmd(exec_cmd, &pgid);
for (int j = 0; j < exec_cmd.open_fds.count; j++) {
- int fd = *get_from_IntVec(exec_cmd.open_fds.count, j);
+ int fd = *get_from_IntVec(&exec_cmd.open_fds, j);
close(fd);
}
-
- } while (last_conn != CONN_EOL);
+ }
tcsetpgrp(STDIN_FILENO, pgid);
while (waitpid(-pgid, NULL, 0) > 0);
tcsetpgrp(STDIN_FILENO, getpgrp());
}
+
+void execute_pipeline_tree(PipelineTree pltree) {
+ execute_command_pipeline(*pltree.root);
+}