-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88206f1
commit 72c3ea0
Showing
9 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "redirect_stdio" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
a653rs = { workspace = true, features = ["macros"] } | ||
a653rs-linux.workspace = true | ||
log.workspace = true | ||
nix.workspace = true | ||
anyhow.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
major_frame: 1s | ||
partitions: | ||
- id: 0 | ||
name: partition_0 | ||
duration: 1s | ||
offset: 0ms | ||
period: 1s | ||
image: ./target/x86_64-unknown-linux-musl/release/redirect_stdio | ||
mounts: | ||
- [ /tmp/redirect_stdio/stdout, /stdout ] | ||
- [ /tmp/redirect_stdio/stderr, /stderr ] | ||
- [ /tmp/redirect_stdio/stdin, /stdin ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::fs::OpenOptions; | ||
use std::os::fd::AsRawFd; | ||
use std::path::Path; | ||
|
||
use a653rs::partition; | ||
use a653rs::prelude::PartitionExt; | ||
use a653rs_linux::partition::ApexLogger; | ||
use anyhow::Result; | ||
use log::LevelFilter; | ||
|
||
fn replace_stdio<T: AsRawFd, U: AsRef<Path>>(stdio: T, new: U, write: bool) -> Result<()> { | ||
let new = OpenOptions::new() | ||
.write(write) | ||
.read(!write) | ||
.truncate(write) | ||
.open(new)?; | ||
nix::unistd::dup2(new.as_raw_fd(), stdio.as_raw_fd())?; | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
replace_stdio(std::io::stdin(), "/stdin", false).unwrap(); | ||
replace_stdio(std::io::stdout(), "/stdout", true).unwrap(); | ||
replace_stdio(std::io::stderr(), "/stderr", true).unwrap(); | ||
|
||
ApexLogger::install_panic_hook(); | ||
ApexLogger::install_logger(LevelFilter::Trace).unwrap(); | ||
|
||
redirect_stdio::Partition.run() | ||
} | ||
|
||
#[partition(a653rs_linux::partition::ApexLinuxPartition)] | ||
mod redirect_stdio { | ||
use log::info; | ||
use std::{io::BufRead, time::Duration}; | ||
|
||
#[start(cold)] | ||
fn cold_start(mut ctx: start::Context) { | ||
// create and start an aperiodic process | ||
ctx.create_process_0().unwrap().start().unwrap(); | ||
} | ||
|
||
// do the same as a cold_start | ||
#[start(warm)] | ||
fn warm_start(ctx: start::Context) { | ||
cold_start(ctx); | ||
} | ||
|
||
// this aperiodic process opens /dev/random and reads some random bytes from it | ||
#[aperiodic( | ||
time_capacity = "Infinite", | ||
stack_size = "8KB", | ||
base_priority = 1, | ||
deadline = "Soft" | ||
)] | ||
fn process_0(_: process_0::Context) { | ||
info!("started process_0"); | ||
|
||
println!("Start reading stdin to stdout"); | ||
let stdin = std::io::stdin(); | ||
for line in stdin.lock().lines() { | ||
println!("{}", line.unwrap()) | ||
} | ||
println!("Finished reading stdin to stdout"); | ||
|
||
eprintln!("Error was encountered: None"); | ||
eprintln!("But it was printed to stderr"); | ||
|
||
// TODO wait for https://github.com/DLR-FT/a653rs/issues/22 to be fixed | ||
// Hypervisor::set_partition_mode(OperatingMode::Idle); | ||
loop { | ||
std::thread::sleep(Duration::from_secs(10)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters