Refactored internals for builtins inside of pipelines
This commit is contained in:
@@ -32,6 +32,7 @@ pub const ECHO_OPTS: [OptSpec; 4] = [
|
||||
];
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct EchoFlags: u32 {
|
||||
const NO_NEWLINE = 0b000001;
|
||||
const USE_STDERR = 0b000010;
|
||||
@@ -60,6 +61,7 @@ pub fn echo(node: Node, io_stack: &mut IoStack, job: &mut JobBldr) -> ShResult<(
|
||||
borrow_fd(STDOUT_FILENO)
|
||||
};
|
||||
|
||||
|
||||
let mut echo_output = prepare_echo_args(
|
||||
argv
|
||||
.into_iter()
|
||||
@@ -197,6 +199,7 @@ pub fn prepare_echo_args(
|
||||
prepared_args.push(prepared_arg);
|
||||
}
|
||||
|
||||
|
||||
Ok(prepared_args)
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -113,7 +113,13 @@ pub fn read_builtin(node: Node, _io_stack: &mut IoStack, job: &mut JobBldr) -> S
|
||||
input.push(buf[0]);
|
||||
}
|
||||
}
|
||||
Err(Errno::EINTR) => continue,
|
||||
Err(Errno::EINTR) => {
|
||||
if crate::signal::sigint_pending() {
|
||||
state::set_status(130);
|
||||
return Ok(String::new());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(ShErr::simple(
|
||||
ShErrKind::ExecFail,
|
||||
@@ -137,19 +143,32 @@ pub fn read_builtin(node: Node, _io_stack: &mut IoStack, job: &mut JobBldr) -> S
|
||||
let mut input: Vec<u8> = vec![];
|
||||
loop {
|
||||
let mut buf = [0u8; 1];
|
||||
log::info!("read: about to call read()");
|
||||
match read(STDIN_FILENO, &mut buf) {
|
||||
Ok(0) => {
|
||||
log::info!("read: got EOF");
|
||||
state::set_status(1);
|
||||
break; // EOF
|
||||
}
|
||||
Ok(_) => {
|
||||
Ok(n) => {
|
||||
log::info!("read: got {} bytes: {:?}", n, &buf[..1]);
|
||||
if buf[0] == read_opts.delim {
|
||||
state::set_status(0);
|
||||
break; // Delimiter reached, stop reading
|
||||
}
|
||||
input.push(buf[0]);
|
||||
}
|
||||
Err(Errno::EINTR) => continue,
|
||||
Err(Errno::EINTR) => {
|
||||
let pending = crate::signal::sigint_pending();
|
||||
log::info!("read: got EINTR, sigint_pending={}", pending);
|
||||
if pending {
|
||||
state::set_status(130);
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
log::info!("read: got error: {}", e);
|
||||
return Err(ShErr::simple(
|
||||
ShErrKind::ExecFail,
|
||||
format!("read: Failed to read from stdin: {e}"),
|
||||
@@ -202,7 +221,6 @@ pub fn read_builtin(node: Node, _io_stack: &mut IoStack, job: &mut JobBldr) -> S
|
||||
}
|
||||
}
|
||||
|
||||
state::set_status(0);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user