diff options
-rw-r--r-- | src/command.rs | 17 | ||||
-rw-r--r-- | src/state/history/mod.rs | 7 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/command.rs b/src/command.rs index 92d9b39..604f138 100644 --- a/src/command.rs +++ b/src/command.rs @@ -12,9 +12,11 @@ pub struct Env { } impl Env { - pub fn new() -> Self { + pub fn new(code: i32) -> Self { Self { - latest_status: async_std::process::ExitStatus::from_raw(0), + latest_status: async_std::process::ExitStatus::from_raw( + code << 8, + ), } } @@ -128,8 +130,8 @@ impl Child { } pub async fn run() -> anyhow::Result<i32> { - let pipeline = read_pipeline().await?; - let env: Env = Env::new(); // todo + let (code, pipeline) = read_data().await?; + let env: Env = Env::new(code); let mut cmds: Vec<_> = pipeline.exes().iter().map(Command::new).collect(); for i in 0..(cmds.len() - 1) { let (r, w) = pipe()?; @@ -191,15 +193,18 @@ pub async fn run() -> anyhow::Result<i32> { Ok(final_status.code().unwrap()) } -async fn read_pipeline() -> anyhow::Result<crate::parse::Pipeline> { +async fn read_data() -> anyhow::Result<(i32, crate::parse::Pipeline)> { // Safety: this code is only called by crate::history::run_pipeline, which // passes data through on fd 3, and which will not spawn this process // unless the pipe was successfully opened on that fd let mut fd3 = unsafe { async_std::fs::File::from_raw_fd(3) }; + let mut be_bytes = [0; 4]; + fd3.read_exact(&mut be_bytes).await?; + let code = i32::from_be_bytes(be_bytes); let mut pipeline = String::new(); fd3.read_to_string(&mut pipeline).await?; let ast = crate::parse::Pipeline::parse(&pipeline)?; - Ok(ast) + Ok((code, ast)) } fn pipe() -> anyhow::Result<(std::fs::File, std::fs::File)> { diff --git a/src/state/history/mod.rs b/src/state/history/mod.rs index 3ff342c..7423727 100644 --- a/src/state/history/mod.rs +++ b/src/state/history/mod.rs @@ -99,7 +99,7 @@ impl History { run_commands( ast.clone(), async_std::sync::Arc::clone(&entry), - crate::command::Env::new(), + crate::command::Env::new(0), input_r, resize_r, event_w, @@ -575,10 +575,13 @@ async fn run_pipeline( nix::unistd::close(r).unwrap(); let mut w = unsafe { async_std::fs::File::from_raw_fd(w) }; + // TODO: actual serialization + w.write_all(&env.latest_status().code().unwrap_or(1).to_be_bytes()) + .await + .unwrap(); w.write_all(pipeline.input_string().as_bytes()) .await .unwrap(); - // todo: write contents of env also drop(w); let status = child.status_no_drop().await.unwrap(); |