Fixed functions not properly forking a new process when executed in a pipeline
This commit is contained in:
@@ -359,10 +359,12 @@ impl Dispatcher {
|
||||
|
||||
let func_name = argv.remove(0).span.as_str().to_string();
|
||||
let argv = prepare_argv(argv)?;
|
||||
let result = if let Some(func) = read_logic(|l| l.get_func(&func_name)) {
|
||||
let result = if let Some(ref mut func_body) = read_logic(|l| l.get_func(&func_name)) {
|
||||
let _guard = ScopeGuard::exclusive_scope(Some(argv));
|
||||
|
||||
if let Err(e) = self.exec_brc_grp((*func).clone()) {
|
||||
func_body.body_mut().flags = func.flags;
|
||||
|
||||
if let Err(e) = self.exec_brc_grp(func_body.body().clone()) {
|
||||
match e.kind() {
|
||||
ShErrKind::FuncReturn(code) => {
|
||||
state::set_status(*code);
|
||||
@@ -385,7 +387,6 @@ impl Dispatcher {
|
||||
result
|
||||
}
|
||||
fn exec_brc_grp(&mut self, brc_grp: Node) -> ShResult<()> {
|
||||
let blame = brc_grp.get_span().clone();
|
||||
let NdRule::BraceGrp { body } = brc_grp.class else {
|
||||
unreachable!()
|
||||
};
|
||||
@@ -411,7 +412,7 @@ impl Dispatcher {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
brc_grp_logic(self).try_blame(blame)
|
||||
brc_grp_logic(self)
|
||||
}
|
||||
}
|
||||
fn exec_case(&mut self, case_stmt: Node) -> ShResult<()> {
|
||||
|
||||
19
src/state.rs
19
src/state.rs
@@ -271,11 +271,9 @@ thread_local! {
|
||||
|
||||
/// A shell function
|
||||
///
|
||||
/// Consists of the BraceGrp Node and the stored ParsedSrc that the node refers
|
||||
/// to The Node must be stored with the ParsedSrc because the tokens of the node
|
||||
/// Consists of the BraceGrp Node and the stored ParsedSrc that the node refers to.
|
||||
/// The Node must be stored with the ParsedSrc because the tokens of the node
|
||||
/// contain an Arc<String> Which refers to the String held in ParsedSrc
|
||||
///
|
||||
/// Can be dereferenced to pull out the wrapped Node
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ShFunc(Node);
|
||||
|
||||
@@ -294,13 +292,12 @@ impl ShFunc {
|
||||
let ConjunctNode { cmd, operator: _ } = conjunct_node;
|
||||
*cmd
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for ShFunc {
|
||||
type Target = Node;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
pub fn body(&self) -> &Node {
|
||||
&self.0
|
||||
}
|
||||
pub fn body_mut(&mut self) -> &mut Node {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// The logic table for the shell
|
||||
|
||||
@@ -59,12 +59,10 @@ fn unclosed_squote() {
|
||||
fn unclosed_brc_grp() {
|
||||
let input = "{ foo bar";
|
||||
let tokens = LexStream::new(Arc::new(input.into()), LexFlags::empty())
|
||||
.map(|tk| tk.unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
.collect::<ShResult<Vec<_>>>();
|
||||
|
||||
let node = ParseStream::new(tokens).next().unwrap();
|
||||
let Err(err) = node else {
|
||||
panic!();
|
||||
let Err(err) = tokens else {
|
||||
panic!("Expected an error, got {:?}", tokens);
|
||||
};
|
||||
|
||||
let err_fmt = format!("{err}");
|
||||
|
||||
Reference in New Issue
Block a user