diff options
| author | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-23 21:26:56 +0200 |
|---|---|---|
| committer | Ákos Kőrösi <korakos99@gmail.com> | 2026-05-23 21:26:56 +0200 |
| commit | 0a9d100af08a2068968264c11013c410330e6ef5 (patch) | |
| tree | 4865cfbe9190546b3ced97f074ba247357b9e229 /src | |
| parent | 8b660b1ca5c72ca4f2e5cfea282d619ed683446c (diff) | |
change signatures for Channel
Diffstat (limited to 'src')
| -rw-r--r-- | src/exec.c | 24 | ||||
| -rw-r--r-- | src/main.c | 2 |
2 files changed, 15 insertions, 11 deletions
@@ -10,7 +10,7 @@ #include "utils.h" #include "stages.h" -void execute_command_pipeline(Pipeline pipeline, int stdin_fd, int stdout_fd, bool wait_here, int* pgid, ShellState* shstate); +void execute_command_pipeline(Pipeline pipeline, Channel read_cha, Channel write_cha, bool wait_here, int* pgid, ShellState* shstate); DECLARE_MAYBE(StrPair, MaybeStrPair) @@ -151,8 +151,9 @@ ExecutableCommand process_pl_command(PlCommand pl_cmd, int* pgid, ShellState* sh break; case ARG_PS_IN: pipe(ps_pipe_fds); - execute_command_pipeline(*(Pipeline*)arg.as.sub_pipeline, STDIN_FILENO, ps_pipe_fds[1], false, pgid, shstate); - close(ps_pipe_fds[1]); + Channel write_cha = {.fd = ps_pipe_fds[1], .parent_proc_closable = true, .child_proc_closable = true}; + execute_command_pipeline(*(Pipeline*)arg.as.sub_pipeline, STDIN_CHA, write_cha, false, pgid, shstate); + //close(ps_pipe_fds[1]); char pname[64]; snprintf(pname, sizeof(pname), "/dev/fd/%d", ps_pipe_fds[0]); push_to_IntVec(&parent_open_fds, ps_pipe_fds[0]); @@ -164,9 +165,10 @@ ExecutableCommand process_pl_command(PlCommand pl_cmd, int* pgid, ShellState* sh // TODO: don't do fcntl? fcntl(ps_pipe_fds[1], F_SETFD, FD_CLOEXEC); - execute_command_pipeline(*(Pipeline*)arg.as.sub_pipeline, ps_pipe_fds[0], STDOUT_FILENO, false, pgid, shstate); + Channel read_cha = {.fd = ps_pipe_fds[0], .parent_proc_closable = true, .child_proc_closable = true}; + execute_command_pipeline(*(Pipeline*)arg.as.sub_pipeline, read_cha, STDOUT_CHA, false, pgid, shstate); + //close(ps_pipe_fds[0]); fcntl(ps_pipe_fds[1], F_SETFD, 0); - close(ps_pipe_fds[0]); char name[64]; snprintf(name, sizeof(name), "/dev/fd/%d", ps_pipe_fds[1]); push_to_IntVec(&parent_open_fds, ps_pipe_fds[1]); @@ -227,9 +229,9 @@ ExecutableCommand process_pl_command(PlCommand pl_cmd, int* pgid, ShellState* sh } -void execute_command_pipeline(Pipeline pipeline, int stdin_fd, int stdout_fd, bool wait_here, int* pgid, ShellState* shstate) { +void execute_command_pipeline(Pipeline pipeline, Channel read_cha, Channel write_cha, bool wait_here, int* pgid, ShellState* shstate) { - Channel trunk_read_cha = {.fd = stdin_fd, .parent_proc_closable = false, .child_proc_closable = false}; // TODO: change the signature to expect (arbitrary) Channel-s + Channel trunk_read_cha = read_cha; for (int i = 0; i < pipeline.count; i++) { PlCommand cmd = *get_from_Pipeline(&pipeline, i); @@ -237,7 +239,7 @@ void execute_command_pipeline(Pipeline pipeline, int stdin_fd, int stdout_fd, bo exec_cmd.read_cha = trunk_read_cha; - exec_cmd.write_cha = (Channel){.fd = stdout_fd, .parent_proc_closable = false, .child_proc_closable = false}; + exec_cmd.write_cha = write_cha; if (cmd.conn == CONN_PIPE) { int pipe_fds[2]; @@ -268,7 +270,7 @@ void execute_command_pipeline(Pipeline pipeline, int stdin_fd, int stdout_fd, bo void execute_pipeline_tree(Pipeline root_pl, ShellState* shstate, int stdin_fd, int stdout_fd) { int pgid = -1; - signal(SIGTTIN, SIG_IGN); - signal(SIGTTOU, SIG_IGN); - execute_command_pipeline(root_pl, stdin_fd, stdout_fd, true, &pgid, shstate); + Channel read_cha = {.fd = stdin_fd, .parent_proc_closable = false, .child_proc_closable = false}; + Channel write_cha = {.fd = stdout_fd, .parent_proc_closable = false, .child_proc_closable = false}; + execute_command_pipeline(root_pl, read_cha, write_cha, true, &pgid, shstate); } @@ -19,6 +19,8 @@ void execute_string_line(char *line, ShellState *shstate) { int main() { + signal(SIGTTIN, SIG_IGN); + signal(SIGTTOU, SIG_IGN); ShellState shstate = {.shell_vars = make_KeyValMap(256), .aliases = make_KeyValMap(256)}; source_script(RCFILENAME, &shstate); char* line; |
