Fixed issue with pipeline I/O in command substitutions
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
expand::{expand_aliases, glob_to_regex},
|
expand::{expand_aliases, glob_to_regex},
|
||||||
jobs::{ChildProc, JobStack, dispatch_job},
|
jobs::{ChildProc, JobStack, dispatch_job},
|
||||||
libsh::error::{ShErr, ShErrKind, ShResult, ShResultExt},
|
libsh::{error::{ShErr, ShErrKind, ShResult, ShResultExt}, utils::RedirVecUtils},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
procio::{IoMode, IoStack},
|
procio::{IoMode, IoStack},
|
||||||
state::{self, ShFunc, VarFlags, read_logic, read_shopts, write_jobs, write_logic, write_vars},
|
state::{self, ShFunc, VarFlags, read_logic, read_shopts, write_jobs, write_logic, write_vars},
|
||||||
@@ -667,6 +667,7 @@ impl Dispatcher {
|
|||||||
};
|
};
|
||||||
self.job_stack.new_job();
|
self.job_stack.new_job();
|
||||||
let fork_builtin = cmds.len() > 1; // If there's more than one command, we need to fork builtins
|
let fork_builtin = cmds.len() > 1; // If there's more than one command, we need to fork builtins
|
||||||
|
let (mut in_redirs, mut out_redirs) = self.io_stack.pop_frame().redirs.split_by_channel();
|
||||||
|
|
||||||
// Zip the commands and their respective pipes into an iterator
|
// Zip the commands and their respective pipes into an iterator
|
||||||
let pipes_and_cmds = get_pipe_stack(cmds.len()).into_iter().zip(cmds);
|
let pipes_and_cmds = get_pipe_stack(cmds.len()).into_iter().zip(cmds);
|
||||||
@@ -674,14 +675,23 @@ impl Dispatcher {
|
|||||||
for ((rpipe, wpipe), mut cmd) in pipes_and_cmds {
|
for ((rpipe, wpipe), mut cmd) in pipes_and_cmds {
|
||||||
if let Some(pipe) = rpipe {
|
if let Some(pipe) = rpipe {
|
||||||
self.io_stack.push_to_frame(pipe);
|
self.io_stack.push_to_frame(pipe);
|
||||||
}
|
} else {
|
||||||
|
for redir in std::mem::take(&mut in_redirs) {
|
||||||
|
self.io_stack.push_to_frame(redir);
|
||||||
|
}
|
||||||
|
}
|
||||||
if let Some(pipe) = wpipe {
|
if let Some(pipe) = wpipe {
|
||||||
self.io_stack.push_to_frame(pipe);
|
self.io_stack.push_to_frame(pipe);
|
||||||
}
|
} else {
|
||||||
|
for redir in std::mem::take(&mut out_redirs) {
|
||||||
|
self.io_stack.push_to_frame(redir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if fork_builtin {
|
if fork_builtin {
|
||||||
cmd.flags |= NdFlags::FORK_BUILTINS;
|
cmd.flags |= NdFlags::FORK_BUILTINS;
|
||||||
}
|
}
|
||||||
|
log::debug!("current io_frame stack: {:#?}", self.io_stack.curr_frame());
|
||||||
self.dispatch_node(cmd)?;
|
self.dispatch_node(cmd)?;
|
||||||
}
|
}
|
||||||
let job = self.job_stack.finalize_job().unwrap();
|
let job = self.job_stack.finalize_job().unwrap();
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ pub struct IoGroup(RawFd, RawFd, RawFd);
|
|||||||
/// Each stack frame represents the redirections of a single command
|
/// Each stack frame represents the redirections of a single command
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
pub struct IoFrame {
|
pub struct IoFrame {
|
||||||
redirs: Vec<Redir>,
|
pub redirs: Vec<Redir>,
|
||||||
saved_io: Option<IoGroup>,
|
saved_io: Option<IoGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user