[PATCH 1/2] tools/xdg-desktop-portal-spectrum-host: set up log
This will let us see logs from zbus. Signed-off-by: Alyssa Ross <hi@alyssa.is> --- .../Cargo.lock | 76 +++++++++++++++++++ .../Cargo.toml | 8 +- .../src/main.rs | 5 ++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/tools/xdg-desktop-portal-spectrum-host/Cargo.lock b/tools/xdg-desktop-portal-spectrum-host/Cargo.lock index 75b5607..cb32e66 100644 --- a/tools/xdg-desktop-portal-spectrum-host/Cargo.lock +++ b/tools/xdg-desktop-portal-spectrum-host/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + [[package]] name = "async-broadcast" version = "0.7.2" @@ -475,6 +484,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.178" @@ -493,6 +508,15 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + [[package]] name = "memchr" version = "2.7.6" @@ -622,6 +646,23 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" + [[package]] name = "rustix" version = "1.1.2" @@ -682,6 +723,15 @@ dependencies = [ "syn", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.7" @@ -770,6 +820,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + [[package]] name = "tinystr" version = "0.8.2" @@ -841,6 +900,21 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tracing-subscriber" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" +dependencies = [ + "matchers", + "once_cell", + "regex-automata", + "sharded-slab", + "thread_local", + "tracing", + "tracing-core", +] + [[package]] name = "uds_windows" version = "1.1.0" @@ -1009,6 +1083,8 @@ dependencies = [ "landlock", "percent-encoding", "rustix", + "tracing", + "tracing-subscriber", "url", "zbus", ] diff --git a/tools/xdg-desktop-portal-spectrum-host/Cargo.toml b/tools/xdg-desktop-portal-spectrum-host/Cargo.toml index 23cadf0..5dc0d99 100644 --- a/tools/xdg-desktop-portal-spectrum-host/Cargo.toml +++ b/tools/xdg-desktop-portal-spectrum-host/Cargo.toml @@ -1,5 +1,5 @@ # SPDX-License-Identifier: CC0-1.0 -# SPDX-FileCopyrightText: 2024 Alyssa Ross <hi@alyssa.is> +# SPDX-FileCopyrightText: 2024-2025 Alyssa Ross <hi@alyssa.is> [package] name = "xdg-desktop-portal-spectrum-host" @@ -13,5 +13,11 @@ futures-lite = "2.3.0" landlock = "0.4.4" percent-encoding = "2.3.1" rustix = "1.0" +tracing = "0.1.43" url = "2.5.0" zbus = "5.1.1" + +[dependencies.tracing-subscriber] +version = "0.3.22" +default-features = false +features = ["env-filter", "fmt"] diff --git a/tools/xdg-desktop-portal-spectrum-host/src/main.rs b/tools/xdg-desktop-portal-spectrum-host/src/main.rs index a867219..40b14b4 100644 --- a/tools/xdg-desktop-portal-spectrum-host/src/main.rs +++ b/tools/xdg-desktop-portal-spectrum-host/src/main.rs @@ -23,6 +23,7 @@ use landlock::{ ABI, Access, AccessFs, AccessNet, CompatLevel, Compatible, Ruleset, RulesetAttr, RulesetError, Scope, }; +use tracing_subscriber::EnvFilter; use zbus::{AuthMechanism, Connection, MessageStream, connection}; use file_chooser::FileChooser; @@ -236,6 +237,10 @@ fn read_argv() { fn run() -> Result<(), String> { set_up_landlock().map_err(|e| format!("setting up landlock: {e}"))?; + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); + read_argv(); async_io::block_on(EXECUTOR.run(async { base-commit: 1a0d063dccf3465ffffda8312994d6066bc1a602 -- 2.52.0
Given we need this anyway for zbus, might as well use it. Signed-off-by: Alyssa Ross <hi@alyssa.is> --- .../src/file_chooser.rs | 6 ++--- .../src/main.rs | 22 ++++++------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs b/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs index 4eae5b9..17532db 100644 --- a/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs +++ b/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs @@ -8,12 +8,12 @@ use std::path::PathBuf; use std::sync::OnceLock; use percent_encoding::percent_decode; +use tracing::error; use url::Url; use zbus::zvariant::{Array, ObjectPath, OwnedValue, Value}; use zbus::{Connection, interface}; use crate::documents::share_file; -use crate::msg; const XDG_DESKTOP_PORTAL_RESPONSE_SUCCESS: u32 = 0; const XDG_DESKTOP_PORTAL_RESPONSE_CANCELLED: u32 = 1; @@ -50,7 +50,7 @@ impl FileChooser { Ok(Some(results)) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_SUCCESS, results)), Ok(None) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_CANCELLED, BTreeMap::new())), Err(e) => { - msg(&e); + error!("{e}"); Ok((XDG_DESKTOP_PORTAL_RESPONSE_OTHER, BTreeMap::new())) } } @@ -71,7 +71,7 @@ impl FileChooser { Ok(Some(results)) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_SUCCESS, results)), Ok(None) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_CANCELLED, BTreeMap::new())), Err(e) => { - msg(&e); + error!("{e}"); Ok((XDG_DESKTOP_PORTAL_RESPONSE_OTHER, BTreeMap::new())) } } diff --git a/tools/xdg-desktop-portal-spectrum-host/src/main.rs b/tools/xdg-desktop-portal-spectrum-host/src/main.rs index 40b14b4..f714aad 100644 --- a/tools/xdg-desktop-portal-spectrum-host/src/main.rs +++ b/tools/xdg-desktop-portal-spectrum-host/src/main.rs @@ -23,6 +23,7 @@ use landlock::{ ABI, Access, AccessFs, AccessNet, CompatLevel, Compatible, Ruleset, RulesetAttr, RulesetError, Scope, }; +use tracing::{error, info}; use tracing_subscriber::EnvFilter; use zbus::{AuthMechanism, Connection, MessageStream, connection}; @@ -158,7 +159,7 @@ async fn run_guest_connection(mut conn: Async<UnixStream>) -> Result<(), String> { let e = format!("sending setup response to guest: {e}"); if guest_dbus_conn_result.is_err() { - msg(&e); + error!("{e}"); } else { return Err(e); } @@ -167,7 +168,7 @@ async fn run_guest_connection(mut conn: Async<UnixStream>) -> Result<(), String> drop(conn); let guest_dbus_conn = guest_dbus_conn_result?; - msg("Created org.freedesktop.impl.portal.desktop.spectrum.host on guest bus"); + info!("Created org.freedesktop.impl.portal.desktop.spectrum.host on guest bus"); let mut guest_messages = MessageStream::from(guest_dbus_conn); loop { @@ -229,7 +230,7 @@ fn read_argv() { args.next(); if args.next().is_some() { - msg("too many arguments"); + error!("too many arguments"); exit(1); } } @@ -258,7 +259,7 @@ fn run() -> Result<(), String> { let (conn, _) = match stdin.accept().await { Ok(conn) => conn, Err(e) => { - msg(&format!("accepting connection from guest: {e}")); + error!("accepting connection from guest: {e}"); continue; } }; @@ -275,7 +276,7 @@ fn run() -> Result<(), String> { EXECUTOR .spawn(async move { if let Err(e) = run_guest_connection(conn).await { - msg(&format!("guest connection error: {e}")); + error!("guest connection error: {e}"); } }) .detach(); @@ -283,18 +284,9 @@ fn run() -> Result<(), String> { })) } -fn msg(e: &str) { - if let Some(prog) = args_os().next() - && let Some(prog) = PathBuf::from(prog).file_name() - { - eprint!("{}: ", prog.to_string_lossy()); - } - eprintln!("{e}"); -} - fn main() { if let Err(e) = run() { - msg(&e); + error!("{e}"); exit(1); } } -- 2.52.0
On 2/26/26 10:07, Alyssa Ross wrote:
Given we need this anyway for zbus, might as well use it.
Signed-off-by: Alyssa Ross <hi@alyssa.is> --- .../src/file_chooser.rs | 6 ++--- .../src/main.rs | 22 ++++++------------- 2 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs b/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs index 4eae5b9..17532db 100644 --- a/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs +++ b/tools/xdg-desktop-portal-spectrum-host/src/file_chooser.rs @@ -8,12 +8,12 @@ use std::path::PathBuf; use std::sync::OnceLock;
use percent_encoding::percent_decode; +use tracing::error; use url::Url; use zbus::zvariant::{Array, ObjectPath, OwnedValue, Value}; use zbus::{Connection, interface};
use crate::documents::share_file; -use crate::msg;
const XDG_DESKTOP_PORTAL_RESPONSE_SUCCESS: u32 = 0; const XDG_DESKTOP_PORTAL_RESPONSE_CANCELLED: u32 = 1; @@ -50,7 +50,7 @@ impl FileChooser { Ok(Some(results)) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_SUCCESS, results)), Ok(None) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_CANCELLED, BTreeMap::new())), Err(e) => { - msg(&e); + error!("{e}"); Ok((XDG_DESKTOP_PORTAL_RESPONSE_OTHER, BTreeMap::new())) } } @@ -71,7 +71,7 @@ impl FileChooser { Ok(Some(results)) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_SUCCESS, results)), Ok(None) => Ok((XDG_DESKTOP_PORTAL_RESPONSE_CANCELLED, BTreeMap::new())), Err(e) => { - msg(&e); + error!("{e}"); Ok((XDG_DESKTOP_PORTAL_RESPONSE_OTHER, BTreeMap::new())) } } diff --git a/tools/xdg-desktop-portal-spectrum-host/src/main.rs b/tools/xdg-desktop-portal-spectrum-host/src/main.rs index 40b14b4..f714aad 100644 --- a/tools/xdg-desktop-portal-spectrum-host/src/main.rs +++ b/tools/xdg-desktop-portal-spectrum-host/src/main.rs @@ -23,6 +23,7 @@ use landlock::{ ABI, Access, AccessFs, AccessNet, CompatLevel, Compatible, Ruleset, RulesetAttr, RulesetError, Scope, }; +use tracing::{error, info}; use tracing_subscriber::EnvFilter; use zbus::{AuthMechanism, Connection, MessageStream, connection};
@@ -158,7 +159,7 @@ async fn run_guest_connection(mut conn: Async<UnixStream>) -> Result<(), String> { let e = format!("sending setup response to guest: {e}"); if guest_dbus_conn_result.is_err() { - msg(&e); + error!("{e}"); } else { return Err(e); } @@ -167,7 +168,7 @@ async fn run_guest_connection(mut conn: Async<UnixStream>) -> Result<(), String> drop(conn); let guest_dbus_conn = guest_dbus_conn_result?;
- msg("Created org.freedesktop.impl.portal.desktop.spectrum.host on guest bus"); + info!("Created org.freedesktop.impl.portal.desktop.spectrum.host on guest bus");
let mut guest_messages = MessageStream::from(guest_dbus_conn); loop { @@ -229,7 +230,7 @@ fn read_argv() { args.next();
if args.next().is_some() { - msg("too many arguments"); + error!("too many arguments"); exit(1); } } @@ -258,7 +259,7 @@ fn run() -> Result<(), String> { let (conn, _) = match stdin.accept().await { Ok(conn) => conn, Err(e) => { - msg(&format!("accepting connection from guest: {e}")); + error!("accepting connection from guest: {e}"); continue; } }; @@ -275,7 +276,7 @@ fn run() -> Result<(), String> { EXECUTOR .spawn(async move { if let Err(e) = run_guest_connection(conn).await { - msg(&format!("guest connection error: {e}")); + error!("guest connection error: {e}"); } }) .detach(); @@ -283,18 +284,9 @@ fn run() -> Result<(), String> { })) }
-fn msg(e: &str) { - if let Some(prog) = args_os().next() - && let Some(prog) = PathBuf::from(prog).file_name() - { - eprint!("{}: ", prog.to_string_lossy()); - } - eprintln!("{e}"); -} - fn main() { if let Err(e) = run() { - msg(&e); + error!("{e}"); exit(1); } }
Acked-by: Demi Marie Obenour <demiobenour@gmail.com> -- Sincerely, Demi Marie Obenour (she/her/hers)
This patch has been committed as fe39e122d898f66e89ffa17d4f4209989ccb5358, which can be viewed online at https://spectrum-os.org/git/spectrum/commit/?id=fe39e122d898f66e89ffa17d4f42.... This is an automated message. Send comments/questions/requests to: Alyssa Ross <hi@alyssa.is>
This patch has been committed as 44ff1b179e7421e6db099cb847b91d8cc01ddfac, which can be viewed online at https://spectrum-os.org/git/spectrum/commit/?id=44ff1b179e7421e6db099cb847b9.... This is an automated message. Send comments/questions/requests to: Alyssa Ross <hi@alyssa.is>
participants (3)
-
Alyssa Ross -
Alyssa Ross -
Demi Marie Obenour