Merge pull request #11 from pop-os/log_jammy

Don't log output of cosmic-comp/cosmic-panel, log panics
This commit is contained in:
Victoria Brekenfeld 2023-01-16 09:37:09 +01:00 committed by GitHub
commit fa898f9228
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 80 deletions

11
Cargo.lock generated
View file

@ -232,6 +232,7 @@ dependencies = [
"futures-util",
"launch-pad",
"libc",
"log-panics",
"nix 0.25.0",
"scopeguard",
"sendfd",
@ -484,6 +485,16 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "log-panics"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68f9dd8546191c1850ecf67d22f5ff00a935b890d0e84713159a55495cc2ac5f"
dependencies = [
"backtrace",
"log",
]
[[package]]
name = "matchers"
version = "0.1.0"

View file

@ -13,6 +13,7 @@ color-eyre = "0.6"
futures-util = "0.3"
launch-pad = { git = "https://github.com/pop-os/launch-pad" }
libc = "0.2"
log-panics = { version = "2", features = ["with-backtrace"] }
nix = { version = "0.25", features = ["fs"], default-features = false }
scopeguard = "1"
sendfd = { version = "0.4", features = ["tokio"] }

View file

@ -14,7 +14,6 @@ use tokio::{
task::JoinHandle,
};
use tokio_util::sync::CancellationToken;
use tracing::Instrument;
use crate::process::mark_as_not_cloexec;
@ -191,65 +190,43 @@ pub fn run_compositor(
OwnedFd::from(std_stream)
};
mark_as_not_cloexec(&comp).expect("Failed to mark fd as not cloexec");
// Create a new span, marking the upcoming task as `cosmic-comp` with tracing.
let span = info_span!(parent: None, "cosmic-comp");
let _span = span.clone();
Ok(tokio::spawn(
async move {
// Create a new process handler for cosmic-comp, with our compositor socket's
// file descriptor as the `COSMIC_SESSION_SOCK` environment variable.
let stdout_span = span.clone();
let stderr_span = span.clone();
process_manager
.start_process(
Process::new()
.with_executable("cosmic-comp")
.with_env([("COSMIC_SESSION_SOCK", comp.as_raw_fd().to_string())])
.with_on_stdout(move |_, _, line| {
let stdout_span = stdout_span.clone();
async move {
info!("{}", line);
}
.instrument(stdout_span)
})
.with_on_stderr(move |_, _, line| {
let stderr_span = stderr_span.clone();
async move {
warn!("{}", line);
}
.instrument(stderr_span)
}),
)
.await
.expect("failed to launch compositor");
// Create a new state object for IPC purposes.
let mut ipc_state = IpcState {
env_tx: Some(env_tx),
..IpcState::default()
};
loop {
tokio::select! {
/*
exit = receive_event(&mut rx) => if exit.is_none() {
break;
},
*/
// Receive IPC messages from the process,
// exiting the loop if IPC errors.
result = receive_ipc(&mut ipc_state, &mut session_rx) => if let Err(err) = result {
error!("failed to receive IPC: {:?}", err);
break;
},
// Send any file descriptors we need to the compositor.
Some(socket) = socket_rx.recv() => {
send_fd(&mut session_tx, socket)
.await
.wrap_err("failed to send file descriptor to compositor")?;
}
Ok(tokio::spawn(async move {
// Create a new process handler for cosmic-comp, with our compositor socket's
// file descriptor as the `COSMIC_SESSION_SOCK` environment variable.
process_manager
.start_process(
Process::new()
.with_executable("cosmic-comp")
.with_env([("COSMIC_SESSION_SOCK", comp.as_raw_fd().to_string())]),
)
.await
.expect("failed to launch compositor");
// Create a new state object for IPC purposes.
let mut ipc_state = IpcState {
env_tx: Some(env_tx),
..IpcState::default()
};
loop {
tokio::select! {
/*
exit = receive_event(&mut rx) => if exit.is_none() {
break;
},
*/
// Receive IPC messages from the process,
// exiting the loop if IPC errors.
result = receive_ipc(&mut ipc_state, &mut session_rx) => if let Err(err) = result {
error!("failed to receive IPC: {:?}", err);
break;
},
// Send any file descriptors we need to the compositor.
Some(socket) = socket_rx.recv() => {
send_fd(&mut session_tx, socket)
.await
.wrap_err("failed to send file descriptor to compositor")?;
}
}
Result::<()>::Ok(())
}
.instrument(_span),
))
Result::<()>::Ok(())
}))
}

View file

@ -34,6 +34,7 @@ async fn main() -> Result<()> {
)
.try_init()
.wrap_err("failed to initialize logger")?;
log_panics::init();
info!("Starting cosmic-session");
@ -61,28 +62,11 @@ async fn main() -> Result<()> {
.collect::<Vec<_>>();
info!("got environmental variables: {:?}", env_vars);
let span = info_span!(parent: None, "cosmic-panel");
let stdout_span = span.clone();
let stderr_span = span.clone();
process_manager
.start(
Process::new()
.with_executable("cosmic-panel")
.with_env(env_vars.clone())
.with_on_stdout(move |_, _, line| {
let stdout_span = stdout_span.clone();
async move {
info!("{}", line);
}
.instrument(stdout_span)
})
.with_on_stderr(move |_, _, line| {
let stderr_span = stderr_span.clone();
async move {
warn!("{}", line);
}
.instrument(stderr_span)
}),
.with_env(env_vars.clone()),
)
.await
.expect("failed to start panel");
@ -173,9 +157,12 @@ async fn main() -> Result<()> {
let (exit_tx, exit_rx) = oneshot::channel();
let _ = ConnectionBuilder::session()?
.name("com.system76.CosmicSession")?
.serve_at("/com/system76/CosmicSession", service::SessionService {
exit_tx: Some(exit_tx),
})?
.serve_at(
"/com/system76/CosmicSession",
service::SessionService {
exit_tx: Some(exit_tx),
},
)?
.build()
.await?;