Skip to content

Commit

Permalink
fix(Microkernels): Update status of pipe failures
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Dec 5, 2021
1 parent cada22f commit a9a6854
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions rust/kernel-micro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,31 @@ impl KernelTrait for MicroKernel {

// Send code to the kernel
tracing::debug!("Sending on stdin");
stdin
if let Err(error) = stdin
.write_all([&code.replace("\n", "\\n"), "\n"].concat().as_bytes())
.await?;
stdin.flush().await?;
.await
{
self.status = KernelStatus::Failed;
bail!("When writing code to kernel: {}", error)
}
if let Err(error) = stdin.flush().await {
self.status = KernelStatus::Failed;
bail!("When flushing code to kernel: {}", error)
}

// Capture outputs separating them as we go
let mut output = String::new();
let mut outputs = Vec::new();
while let Some(line) = stdout.lines().next_line().await? {
loop {
let line = match stdout.lines().next_line().await {
Ok(Some(line)) => line,
Ok(None) => break,
Err(error) => {
self.status = KernelStatus::Failed;
bail!("When receiving outputs from kernel: {}", error)
}
};

tracing::debug!("Received on stdout: {}", line);
if let Some(line) = line.strip_suffix(RES_SEP) {
output.push_str(line);
Expand Down Expand Up @@ -306,8 +322,17 @@ impl KernelTrait for MicroKernel {
// Capture messages separating them as we go
let mut message = String::new();
let mut messages = Vec::new();
while let Some(line) = stderr.lines().next_line().await? {
tracing::debug!("Received on sterr: {}", line);
loop {
let line = match stderr.lines().next_line().await {
Ok(Some(line)) => line,
Ok(None) => break,
Err(error) => {
self.status = KernelStatus::Failed;
bail!("When receiving messages from kernel: {}", error)
}
};

tracing::debug!("Received on stderr: {}", line);
if let Some(line) = line.strip_suffix(RES_SEP) {
message.push_str(line);
if !message.is_empty() {
Expand Down

0 comments on commit a9a6854

Please sign in to comment.