🚧 Basic ProcessHandler works!
This commit is contained in:
parent
7d3cacf839
commit
8bf6567a91
3 changed files with 54 additions and 0 deletions
|
|
@ -10,6 +10,8 @@ publish = false
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-signals = "0.4"
|
async-signals = "0.4"
|
||||||
color-eyre = "0.6"
|
color-eyre = "0.6"
|
||||||
|
futures-util = "0.3.21"
|
||||||
|
libc = "0.2"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
tokio-util = "0.7"
|
tokio-util = "0.7"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
|
|
||||||
31
src/comp.rs
Normal file
31
src/comp.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use crate::process::{ProcessEvent, ProcessHandler};
|
||||||
|
use tokio::sync::mpsc::unbounded_channel;
|
||||||
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
|
pub async fn run_compositor(token: CancellationToken) {
|
||||||
|
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
|
||||||
|
ProcessHandler::new(tx, &token).run("cosmic-comp", vec![]);
|
||||||
|
let span = info_span!("cosmic-comp");
|
||||||
|
let _enter = span.enter();
|
||||||
|
while let Some(event) = rx.recv().await {
|
||||||
|
match event {
|
||||||
|
ProcessEvent::Started => {
|
||||||
|
info!("started");
|
||||||
|
}
|
||||||
|
ProcessEvent::Stdout(line) => {
|
||||||
|
info!("{}", line);
|
||||||
|
}
|
||||||
|
ProcessEvent::Stderr(line) => {
|
||||||
|
error!("{}", line);
|
||||||
|
}
|
||||||
|
ProcessEvent::Ended(Some(status)) => {
|
||||||
|
error!("exited with status {}", status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ProcessEvent::Ended(None) => {
|
||||||
|
error!("exited");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/main.rs
21
src/main.rs
|
|
@ -2,9 +2,13 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate tracing;
|
extern crate tracing;
|
||||||
|
|
||||||
|
mod comp;
|
||||||
mod process;
|
mod process;
|
||||||
|
|
||||||
|
use async_signals::Signals;
|
||||||
use color_eyre::{eyre::WrapErr, Result};
|
use color_eyre::{eyre::WrapErr, Result};
|
||||||
|
use futures_util::StreamExt;
|
||||||
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::metadata::LevelFilter;
|
use tracing::metadata::LevelFilter;
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
|
|
||||||
|
|
@ -24,5 +28,22 @@ async fn main() -> Result<()> {
|
||||||
|
|
||||||
info!("Starting cosmic-session");
|
info!("Starting cosmic-session");
|
||||||
|
|
||||||
|
let token = CancellationToken::new();
|
||||||
|
|
||||||
|
tokio::spawn(comp::run_compositor(token.child_token()));
|
||||||
|
|
||||||
|
let mut signals = Signals::new(vec![libc::SIGTERM, libc::SIGINT]).unwrap();
|
||||||
|
while let Some(signal) = signals.next().await {
|
||||||
|
match signal {
|
||||||
|
libc::SIGTERM | libc::SIGINT => {
|
||||||
|
info!("received request to terminate");
|
||||||
|
token.cancel();
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(5)).await;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_ => unreachable!("received unhandled signal {}", signal),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue