diff --git a/src/bin/steamos-manager.rs b/src/bin/steamos-manager.rs index b6d9303..75e7a60 100644 --- a/src/bin/steamos-manager.rs +++ b/src/bin/steamos-manager.rs @@ -8,7 +8,7 @@ use anyhow::Result; use clap::Parser; -use steamos_manager::{RootDaemon, UserDaemon}; +use steamos_manager::daemon; #[derive(Parser)] struct Args { @@ -21,8 +21,8 @@ struct Args { pub async fn main() -> Result<()> { let args = Args::parse(); if args.root { - RootDaemon().await + daemon::root().await } else { - UserDaemon().await + daemon::user().await } } diff --git a/src/bin/steamosctl.rs b/src/bin/steamosctl.rs index 043f7ff..8726729 100644 --- a/src/bin/steamosctl.rs +++ b/src/bin/steamosctl.rs @@ -10,7 +10,8 @@ use clap::{Parser, Subcommand}; use itertools::Itertools; use std::ops::Deref; use std::str::FromStr; -use steamos_manager::{ManagerProxy, WifiBackend}; +use steamos_manager::proxy::ManagerProxy; +use steamos_manager::wifi::WifiBackend; use zbus::fdo::PropertiesProxy; use zbus::names::InterfaceName; use zbus::{zvariant, Connection}; diff --git a/src/daemon.rs b/src/daemon/mod.rs similarity index 88% rename from src/daemon.rs rename to src/daemon/mod.rs index 4fcccd5..1c42947 100644 --- a/src/daemon.rs +++ b/src/daemon/mod.rs @@ -17,7 +17,13 @@ use zbus::connection::Connection; use crate::sls::{LogLayer, LogReceiver}; use crate::{reload, Service}; -pub struct Daemon { +mod root; +mod user; + +pub use root::daemon as root; +pub use user::daemon as user; + +pub(crate) struct Daemon { services: JoinSet>, token: CancellationToken, sigterm: Signal, @@ -25,7 +31,7 @@ pub struct Daemon { } impl Daemon { - pub async fn new LookupSpan<'a>>( + pub(crate) async fn new LookupSpan<'a>>( subscriber: S, connection: Connection, ) -> Result { @@ -51,13 +57,13 @@ impl Daemon { Ok(daemon) } - pub fn add_service(&mut self, service: S) { + pub(crate) fn add_service(&mut self, service: S) { let token = self.token.clone(); self.services .spawn(async move { service.start(token).await }); } - pub async fn run(&mut self) -> Result<()> { + pub(crate) async fn run(&mut self) -> Result<()> { ensure!( !self.services.is_empty(), "Can't run a daemon with no services attached." diff --git a/src/root.rs b/src/daemon/root.rs similarity index 93% rename from src/root.rs rename to src/daemon/root.rs index 525a8be..a950833 100644 --- a/src/root.rs +++ b/src/daemon/root.rs @@ -14,7 +14,7 @@ use zbus::ConnectionBuilder; use crate::daemon::Daemon; use crate::ds_inhibit::Inhibitor; -use crate::manager; +use crate::manager::root::SteamOSManager; use crate::sls::ftrace::Ftrace; async fn create_connection() -> Result { @@ -22,7 +22,7 @@ async fn create_connection() -> Result { .name("com.steampowered.SteamOSManager1")? .build() .await?; - let manager = manager::SteamOSManager::new(connection.clone()).await?; + let manager = SteamOSManager::new(connection.clone()).await?; connection .object_server() .at("/com/steampowered/SteamOSManager1", manager) diff --git a/src/user.rs b/src/daemon/user.rs similarity index 68% rename from src/user.rs rename to src/daemon/user.rs index f90a3c0..96e7c0d 100644 --- a/src/user.rs +++ b/src/daemon/user.rs @@ -13,19 +13,22 @@ use zbus::connection::Connection; use zbus::ConnectionBuilder; use crate::daemon::Daemon; -use crate::user_manager::SteamOSManagerUser; +use crate::manager::user::SteamOSManager; -async fn create_connection(system_conn: &Connection) -> Result { +async fn create_connections() -> Result<(Connection, Connection)> { + let system = Connection::system().await?; let connection = ConnectionBuilder::session()? .name("com.steampowered.SteamOSManager1")? .build() .await?; - let manager = SteamOSManagerUser::new(connection.clone(), system_conn).await?; + + let manager = SteamOSManager::new(connection.clone(), &system).await?; connection .object_server() .at("/com/steampowered/SteamOSManager1", manager) .await?; - Ok(connection) + + Ok((connection, system)) } pub async fn daemon() -> Result<()> { @@ -35,15 +38,7 @@ pub async fn daemon() -> Result<()> { let stdout_log = fmt::layer(); let subscriber = Registry::default().with(stdout_log); - let system = match Connection::system().await { - Ok(c) => c, - Err(e) => { - let _guard = tracing::subscriber::set_default(subscriber); - error!("Error connecting to DBus: {}", e); - bail!(e); - } - }; - let _session = match create_connection(&system).await { + let (_session, system) = match create_connections().await { Ok(c) => c, Err(e) => { let _guard = tracing::subscriber::set_default(subscriber); diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..70d4558 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,23 @@ +/* + * Copyright © 2023 Collabora Ltd. + * Copyright © 2024 Valve Software + * + * SPDX-License-Identifier: MIT + */ + +use zbus::fdo; + +pub fn to_zbus_fdo_error(error: S) -> fdo::Error { + fdo::Error::Failed(error.to_string()) +} + +pub fn to_zbus_error(error: S) -> zbus::Error { + zbus::Error::Failure(error.to_string()) +} + +pub fn zbus_to_zbus_fdo(error: zbus::Error) -> fdo::Error { + match error { + zbus::Error::FDO(error) => *error, + error => fdo::Error::Failed(error.to_string()), + } +} diff --git a/src/lib.rs b/src/lib.rs index 670bcc5..5eb2206 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,28 +15,22 @@ use tokio_util::sync::CancellationToken; use tracing::{info, warn}; mod cec; -mod daemon; mod ds_inhibit; +mod error; mod hardware; mod manager; mod power; mod process; -mod proxy; -mod root; mod sls; mod systemd; -mod user; -mod user_manager; -mod wifi; + +pub mod daemon; +pub mod proxy; +pub mod wifi; #[cfg(test)] mod testing; -pub use proxy::ManagerProxy; -pub use root::daemon as RootDaemon; -pub use user::daemon as UserDaemon; -pub use wifi::{WifiBackend, WifiDebugMode, WifiPowerManagement}; - const API_VERSION: u32 = 8; pub trait Service @@ -85,18 +79,18 @@ pub fn path>(path: S) -> PathBuf { .join(path.as_ref().trim_start_matches('/')) } -pub async fn write_synced>(path: P, bytes: &[u8]) -> Result<()> { +pub(crate) async fn write_synced>(path: P, bytes: &[u8]) -> Result<()> { let mut file = File::create(path.as_ref()).await?; file.write_all(bytes).await?; Ok(file.sync_data().await?) } -pub fn read_comm(pid: u32) -> Result { +pub(crate) fn read_comm(pid: u32) -> Result { let comm = std::fs::read_to_string(path(format!("/proc/{}/comm", pid)))?; Ok(comm.trim_end().to_string()) } -pub fn get_appid(pid: u32) -> Result> { +pub(crate) fn get_appid(pid: u32) -> Result> { let environ = std::fs::read_to_string(path(format!("/proc/{}/environ", pid)))?; for env_var in environ.split('\0') { let (key, value) = match env_var.split_once('=') { @@ -139,21 +133,6 @@ async fn reload() -> Result<()> { } } -pub fn to_zbus_fdo_error(error: S) -> zbus::fdo::Error { - zbus::fdo::Error::Failed(error.to_string()) -} - -pub fn to_zbus_error(error: S) -> zbus::Error { - zbus::Error::Failure(error.to_string()) -} - -pub fn zbus_to_zbus_fdo(error: zbus::Error) -> zbus::fdo::Error { - match error { - zbus::Error::FDO(error) => *error, - error => zbus::fdo::Error::Failed(error.to_string()), - } -} - #[cfg(test)] mod test { use crate::testing; diff --git a/src/manager/mod.rs b/src/manager/mod.rs new file mode 100644 index 0000000..58918c8 --- /dev/null +++ b/src/manager/mod.rs @@ -0,0 +1,9 @@ +/* + * Copyright © 2023 Collabora Ltd. + * Copyright © 2024 Valve Software + * + * SPDX-License-Identifier: MIT + */ + +pub(crate) mod root; +pub(crate) mod user; diff --git a/src/manager.rs b/src/manager/root.rs similarity index 92% rename from src/manager.rs rename to src/manager/root.rs index 992e710..6d945fe 100644 --- a/src/manager.rs +++ b/src/manager/root.rs @@ -10,8 +10,9 @@ use anyhow::Result; use tokio::fs::File; use tracing::error; use zbus::zvariant::Fd; -use zbus::{interface, Connection, SignalContext}; +use zbus::{fdo, interface, Connection, SignalContext}; +use crate::error::{to_zbus_error, to_zbus_fdo_error}; use crate::hardware::{check_support, variant, FanControl, FanControlState, HardwareVariant}; use crate::power::{ get_gpu_clocks, get_gpu_performance_level, get_tdp_limit, set_gpu_clocks, @@ -22,7 +23,7 @@ use crate::wifi::{ get_wifi_backend, get_wifi_power_management_state, set_wifi_backend, set_wifi_debug_mode, set_wifi_power_management_state, WifiBackend, WifiDebugMode, WifiPowerManagement, }; -use crate::{to_zbus_error, to_zbus_fdo_error, API_VERSION}; +use crate::API_VERSION; #[derive(PartialEq, Debug, Copy, Clone)] #[repr(u32)] @@ -67,7 +68,7 @@ impl SteamOSManager { } #[zbus(property(emits_changed_signal = "false"))] - async fn wifi_power_management_state(&self) -> zbus::fdo::Result { + async fn wifi_power_management_state(&self) -> fdo::Result { match get_wifi_power_management_state().await { Ok(state) => Ok(state as u32), Err(e) => Err(to_zbus_fdo_error(e)), @@ -78,7 +79,7 @@ impl SteamOSManager { async fn set_wifi_power_management_state(&self, state: u32) -> zbus::Result<()> { let state = match WifiPowerManagement::try_from(state) { Ok(state) => state, - Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()), + Err(err) => return Err(fdo::Error::InvalidArgs(err.to_string()).into()), }; set_wifi_power_management_state(state) .await @@ -86,7 +87,7 @@ impl SteamOSManager { } #[zbus(property(emits_changed_signal = "false"))] - async fn fan_control_state(&self) -> zbus::fdo::Result { + async fn fan_control_state(&self) -> fdo::Result { Ok(self .fan_control .get_state() @@ -98,7 +99,7 @@ impl SteamOSManager { async fn set_fan_control_state(&self, state: u32) -> zbus::Result<()> { let state = match FanControlState::try_from(state) { Ok(state) => state, - Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()), + Err(err) => return Err(fdo::Error::InvalidArgs(err.to_string()).into()), }; // Run what steamos-polkit-helpers/jupiter-fan-control does self.fan_control @@ -108,7 +109,7 @@ impl SteamOSManager { } #[zbus(property(emits_changed_signal = "const"))] - async fn hardware_currently_supported(&self) -> zbus::fdo::Result { + async fn hardware_currently_supported(&self) -> fdo::Result { match check_support().await { Ok(res) => Ok(res as u32), Err(e) => Err(to_zbus_fdo_error(e)), @@ -132,26 +133,26 @@ impl SteamOSManager { } } - async fn get_als_integration_time_file_descriptor(&self) -> zbus::fdo::Result { + async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result { // Get the file descriptor for the als integration time sysfs path let result = File::create(ALS_INTEGRATION_PATH).await; match result { Ok(f) => Ok(Fd::Owned(std::os::fd::OwnedFd::from(f.into_std().await))), Err(message) => { error!("Error opening sysfs file for giving file descriptor: {message}"); - Err(zbus::fdo::Error::IOError(message.to_string())) + Err(fdo::Error::IOError(message.to_string())) } } } - async fn update_bios(&mut self) -> zbus::fdo::Result { + async fn update_bios(&mut self) -> fdo::Result { // Update the bios as needed self.process_manager .get_command_object_path("/usr/bin/jupiter-biosupdate", &["--auto"], "updating BIOS") .await } - async fn update_dock(&mut self) -> zbus::fdo::Result { + async fn update_dock(&mut self) -> fdo::Result { // Update the dock firmware as needed self.process_manager .get_command_object_path( @@ -162,7 +163,7 @@ impl SteamOSManager { .await } - async fn trim_devices(&mut self) -> zbus::fdo::Result { + async fn trim_devices(&mut self) -> fdo::Result { // Run steamos-trim-devices script self.process_manager .get_command_object_path( @@ -178,7 +179,7 @@ impl SteamOSManager { device: &str, label: &str, validate: bool, - ) -> zbus::fdo::Result { + ) -> fdo::Result { let mut args = vec!["--label", label, "--device", device]; if !validate { args.push("--skip-validation"); @@ -193,7 +194,7 @@ impl SteamOSManager { } #[zbus(property(emits_changed_signal = "false"))] - async fn gpu_performance_level(&self) -> zbus::fdo::Result { + async fn gpu_performance_level(&self) -> fdo::Result { match get_gpu_performance_level().await { Ok(level) => Ok(level as u32), Err(e) => { @@ -216,7 +217,7 @@ impl SteamOSManager { } #[zbus(property(emits_changed_signal = "false"))] - async fn manual_gpu_clock(&self) -> zbus::fdo::Result { + async fn manual_gpu_clock(&self) -> fdo::Result { get_gpu_clocks() .await .inspect_err(|message| error!("Error getting manual GPU clock: {message}")) @@ -244,7 +245,7 @@ impl SteamOSManager { } #[zbus(property(emits_changed_signal = "false"))] - async fn tdp_limit(&self) -> zbus::fdo::Result { + async fn tdp_limit(&self) -> fdo::Result { get_tdp_limit().await.map_err(to_zbus_fdo_error) } @@ -276,12 +277,12 @@ impl SteamOSManager { mode: u32, buffer_size: u32, #[zbus(signal_context)] ctx: SignalContext<'_>, - ) -> zbus::fdo::Result<()> { + ) -> fdo::Result<()> { // Set the wifi debug mode to mode, using an int for flexibility going forward but only // doing things on 0 or 1 for now let wanted_mode = match WifiDebugMode::try_from(mode) { Ok(mode) => mode, - Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())), + Err(e) => return Err(fdo::Error::InvalidArgs(e.to_string())), }; match set_wifi_debug_mode( wanted_mode, @@ -305,7 +306,7 @@ impl SteamOSManager { /// WifiBackend property. #[zbus(property(emits_changed_signal = "false"))] - async fn wifi_backend(&self) -> zbus::fdo::Result { + async fn wifi_backend(&self) -> fdo::Result { match get_wifi_backend().await { Ok(backend) => Ok(backend as u32), Err(e) => Err(to_zbus_fdo_error(e)), @@ -313,15 +314,15 @@ impl SteamOSManager { } #[zbus(property)] - async fn set_wifi_backend(&mut self, backend: u32) -> zbus::fdo::Result<()> { + async fn set_wifi_backend(&mut self, backend: u32) -> fdo::Result<()> { if self.wifi_debug_mode == WifiDebugMode::On { - return Err(zbus::fdo::Error::Failed(String::from( + return Err(fdo::Error::Failed(String::from( "operation not supported when wifi_debug_mode=on", ))); } let backend = match WifiBackend::try_from(backend) { Ok(backend) => backend, - Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())), + Err(e) => return Err(fdo::Error::InvalidArgs(e.to_string())), }; set_wifi_backend(backend) .await diff --git a/src/user_manager.rs b/src/manager/user.rs similarity index 85% rename from src/user_manager.rs rename to src/manager/user.rs index 43220eb..2ec8061 100644 --- a/src/user_manager.rs +++ b/src/manager/user.rs @@ -10,10 +10,11 @@ use anyhow::Result; use tracing::error; use zbus::proxy::Builder; use zbus::zvariant::Fd; -use zbus::{interface, Connection, Proxy, SignalContext}; +use zbus::{fdo, interface, Connection, Proxy, SignalContext}; use crate::cec::{HdmiCecControl, HdmiCecState}; -use crate::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo, API_VERSION}; +use crate::error::{to_zbus_error, to_zbus_fdo_error, zbus_to_zbus_fdo}; +use crate::API_VERSION; macro_rules! method { ($self:expr, $method:expr, $($args:expr),+) => { @@ -50,14 +51,14 @@ macro_rules! setter { }; } -pub struct SteamOSManagerUser { +pub struct SteamOSManager { proxy: Proxy<'static>, hdmi_cec: HdmiCecControl<'static>, } -impl SteamOSManagerUser { +impl SteamOSManager { pub async fn new(connection: Connection, system_conn: &Connection) -> Result { - Ok(SteamOSManagerUser { + Ok(SteamOSManager { hdmi_cec: HdmiCecControl::new(&connection).await?, proxy: Builder::new(system_conn) .destination("com.steampowered.SteamOSManager1")? @@ -71,14 +72,14 @@ impl SteamOSManagerUser { } #[interface(name = "com.steampowered.SteamOSManager1.Manager")] -impl SteamOSManagerUser { +impl SteamOSManager { #[zbus(property(emits_changed_signal = "const"))] async fn version(&self) -> u32 { API_VERSION } #[zbus(property(emits_changed_signal = "false"))] - async fn hdmi_cec_state(&self) -> zbus::fdo::Result { + async fn hdmi_cec_state(&self) -> fdo::Result { match self.hdmi_cec.get_enabled_state().await { Ok(state) => Ok(state as u32), Err(e) => Err(to_zbus_fdo_error(e)), @@ -89,7 +90,7 @@ impl SteamOSManagerUser { async fn set_hdmi_cec_state(&self, state: u32) -> zbus::Result<()> { let state = match HdmiCecState::try_from(state) { Ok(state) => state, - Err(err) => return Err(zbus::fdo::Error::InvalidArgs(err.to_string()).into()), + Err(err) => return Err(fdo::Error::InvalidArgs(err.to_string()).into()), }; self.hdmi_cec .set_enabled_state(state) @@ -98,12 +99,12 @@ impl SteamOSManagerUser { .map_err(to_zbus_error) } - async fn prepare_factory_reset(&self) -> zbus::fdo::Result { + async fn prepare_factory_reset(&self) -> fdo::Result { method!(self, "PrepareFactoryReset") } #[zbus(property(emits_changed_signal = "false"))] - async fn wifi_power_management_state(&self) -> zbus::fdo::Result { + async fn wifi_power_management_state(&self) -> fdo::Result { getter!(self, "WifiPowerManagementState") } @@ -113,7 +114,7 @@ impl SteamOSManagerUser { } #[zbus(property(emits_changed_signal = "false"))] - async fn fan_control_state(&self) -> zbus::fdo::Result { + async fn fan_control_state(&self) -> fdo::Result { getter!(self, "FanControlState") } @@ -123,16 +124,16 @@ impl SteamOSManagerUser { } #[zbus(property(emits_changed_signal = "const"))] - async fn hardware_currently_supported(&self) -> zbus::fdo::Result { + async fn hardware_currently_supported(&self) -> fdo::Result { getter!(self, "HardwareCurrentlySupported") } #[zbus(property(emits_changed_signal = "false"))] - async fn als_calibration_gain(&self) -> zbus::fdo::Result { + async fn als_calibration_gain(&self) -> fdo::Result { getter!(self, "AlsCalibrationGain") } - async fn get_als_integration_time_file_descriptor(&self) -> zbus::fdo::Result { + async fn get_als_integration_time_file_descriptor(&self) -> fdo::Result { let m = self .proxy .call_method::<&str, ()>("GetAlsIntegrationTimeFileDescriptor", &()) @@ -144,15 +145,15 @@ impl SteamOSManagerUser { } } - async fn update_bios(&self) -> zbus::fdo::Result { + async fn update_bios(&self) -> fdo::Result { method!(self, "UpdateBios") } - async fn update_dock(&self) -> zbus::fdo::Result { + async fn update_dock(&self) -> fdo::Result { method!(self, "UpdateDock") } - async fn trim_devices(&self) -> zbus::fdo::Result { + async fn trim_devices(&self) -> fdo::Result { method!(self, "TrimDevices") } @@ -161,12 +162,12 @@ impl SteamOSManagerUser { device: &str, label: &str, validate: bool, - ) -> zbus::fdo::Result { + ) -> fdo::Result { method!(self, "FormatDevice", device, label, validate) } #[zbus(property(emits_changed_signal = "false"))] - async fn gpu_performance_level(&self) -> zbus::fdo::Result { + async fn gpu_performance_level(&self) -> fdo::Result { getter!(self, "GpuPerformanceLevel") } @@ -176,7 +177,7 @@ impl SteamOSManagerUser { } #[zbus(property(emits_changed_signal = "false"))] - async fn manual_gpu_clock(&self) -> zbus::fdo::Result { + async fn manual_gpu_clock(&self) -> fdo::Result { getter!(self, "ManualGpuClock") } @@ -186,17 +187,17 @@ impl SteamOSManagerUser { } #[zbus(property(emits_changed_signal = "const"))] - async fn manual_gpu_clock_min(&self) -> zbus::fdo::Result { + async fn manual_gpu_clock_min(&self) -> fdo::Result { getter!(self, "ManualGpuClockMin") } #[zbus(property(emits_changed_signal = "const"))] - async fn manual_gpu_clock_max(&self) -> zbus::fdo::Result { + async fn manual_gpu_clock_max(&self) -> fdo::Result { getter!(self, "ManualGpuClockMax") } #[zbus(property(emits_changed_signal = "false"))] - async fn tdp_limit(&self) -> zbus::fdo::Result { + async fn tdp_limit(&self) -> fdo::Result { getter!(self, "TdpLimit") } @@ -206,17 +207,17 @@ impl SteamOSManagerUser { } #[zbus(property(emits_changed_signal = "const"))] - async fn tdp_limit_min(&self) -> zbus::fdo::Result { + async fn tdp_limit_min(&self) -> fdo::Result { getter!(self, "TdpLimitMin") } #[zbus(property(emits_changed_signal = "const"))] - async fn tdp_limit_max(&self) -> zbus::fdo::Result { + async fn tdp_limit_max(&self) -> fdo::Result { getter!(self, "TdpLimitMax") } #[zbus(property)] - async fn wifi_debug_mode_state(&self) -> zbus::fdo::Result { + async fn wifi_debug_mode_state(&self) -> fdo::Result { getter!(self, "WifiDebugModeState") } @@ -225,7 +226,7 @@ impl SteamOSManagerUser { mode: u32, buffer_size: u32, #[zbus(signal_context)] ctx: SignalContext<'_>, - ) -> zbus::fdo::Result<()> { + ) -> fdo::Result<()> { method!(self, "SetWifiDebugMode", mode, buffer_size)?; self.wifi_debug_mode_state_changed(&ctx) .await @@ -234,7 +235,7 @@ impl SteamOSManagerUser { } #[zbus(property(emits_changed_signal = "false"))] - async fn wifi_backend(&self) -> zbus::fdo::Result { + async fn wifi_backend(&self) -> fdo::Result { getter!(self, "WifiBackend") } @@ -268,7 +269,7 @@ mod test { .build() .await .unwrap(); - let manager = SteamOSManagerUser::new(connection.clone(), &connection) + let manager = SteamOSManager::new(connection.clone(), &connection) .await .unwrap(); connection @@ -306,7 +307,7 @@ mod test { let manager_ref = test .connection .object_server() - .interface::<_, SteamOSManagerUser>("/com/steampowered/SteamOSManager1") + .interface::<_, SteamOSManager>("/com/steampowered/SteamOSManager1") .await .expect("interface"); let manager = manager_ref.get().await; diff --git a/src/process.rs b/src/process.rs index d8290d7..4aabc12 100644 --- a/src/process.rs +++ b/src/process.rs @@ -15,9 +15,9 @@ use std::os::unix::process::ExitStatusExt; use std::process::ExitStatus; use tokio::process::{Child, Command}; use tracing::error; -use zbus::interface; +use zbus::{fdo, interface}; -use crate::to_zbus_fdo_error; +use crate::error::to_zbus_fdo_error; const PROCESS_PREFIX: &str = "/com/steampowered/SteamOSManager1/Process"; @@ -48,7 +48,7 @@ impl ProcessManager { executable: &str, args: &[impl AsRef], operation_name: &str, - ) -> zbus::fdo::Result { + ) -> fdo::Result { // Run the given executable and give back an object path let path = format!("{}{}", PROCESS_PREFIX, self.next_process); self.next_process += 1; @@ -128,9 +128,9 @@ impl SubProcess { #[interface(name = "com.steampowered.SteamOSManager1.SubProcess")] impl SubProcess { - pub async fn pause(&mut self) -> zbus::fdo::Result<()> { + pub async fn pause(&mut self) -> fdo::Result<()> { if self.paused { - return Err(zbus::fdo::Error::Failed("Already paused".to_string())); + return Err(fdo::Error::Failed("Already paused".to_string())); } // Pause the given process if possible // Return true on success, false otherwise @@ -139,17 +139,17 @@ impl SubProcess { result } - pub async fn resume(&mut self) -> zbus::fdo::Result<()> { + pub async fn resume(&mut self) -> fdo::Result<()> { // Resume the given process if possible if !self.paused { - return Err(zbus::fdo::Error::Failed("Not paused".to_string())); + return Err(fdo::Error::Failed("Not paused".to_string())); } let result = self.send_signal(Signal::SIGCONT).map_err(to_zbus_fdo_error); self.paused = false; result } - pub async fn cancel(&mut self) -> zbus::fdo::Result<()> { + pub async fn cancel(&mut self) -> fdo::Result<()> { if self.try_wait().map_err(to_zbus_fdo_error)?.is_none() { self.send_signal(Signal::SIGTERM) .map_err(to_zbus_fdo_error)?; @@ -160,14 +160,14 @@ impl SubProcess { Ok(()) } - pub async fn kill(&mut self) -> zbus::fdo::Result<()> { + pub async fn kill(&mut self) -> fdo::Result<()> { match self.try_wait().map_err(to_zbus_fdo_error)? { Some(_) => Ok(()), None => self.send_signal(signal::SIGKILL).map_err(to_zbus_fdo_error), } } - pub async fn wait(&mut self) -> zbus::fdo::Result { + pub async fn wait(&mut self) -> fdo::Result { if self.paused { self.resume().await?; } @@ -175,16 +175,14 @@ impl SubProcess { let code = match self.exit_code_internal().await.map_err(to_zbus_fdo_error) { Ok(v) => v, Err(_) => { - return Err(zbus::fdo::Error::Failed( - "Unable to get exit code".to_string(), - )); + return Err(fdo::Error::Failed("Unable to get exit code".to_string())); } }; self.exit_code = Some(code); Ok(code) } - pub async fn exit_code(&mut self) -> zbus::fdo::Result { + pub async fn exit_code(&mut self) -> fdo::Result { match self.try_wait() { Ok(Some(i)) => Ok(i), _ => Err(zbus::fdo::Error::Failed( @@ -275,14 +273,14 @@ mod test { assert_eq!( pause_process.pause().await.unwrap_err(), - zbus::fdo::Error::Failed("Already paused".to_string()) + fdo::Error::Failed("Already paused".to_string()) ); pause_process.resume().await.expect("resume"); assert_eq!( pause_process.resume().await.unwrap_err(), - zbus::fdo::Error::Failed("Not paused".to_string()) + fdo::Error::Failed("Not paused".to_string()) ); // Sleep gives 0 exit code when done, -1 when we haven't waited for it yet diff --git a/src/proxy.rs b/src/proxy.rs index 02285f3..4c1bb46 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -116,6 +116,7 @@ trait Manager { } #[proxy( + default_service = "com.steampowered.SteamOSManager1", interface = "com.steampowered.SteamOSManager1.SubProcess", assume_defaults = true )] diff --git a/src/sls/ftrace.rs b/src/sls/ftrace.rs index b9d6492..629ee5f 100644 --- a/src/sls/ftrace.rs +++ b/src/sls/ftrace.rs @@ -119,6 +119,7 @@ mod test { use nix::unistd; use tokio::fs::{create_dir_all, read_to_string, write}; use tokio::sync::mpsc::{error, unbounded_channel, UnboundedSender}; + use zbus::fdo; struct MockTrace { traces: UnboundedSender<(String, HashMap)>, @@ -130,7 +131,7 @@ mod test { &mut self, trace: &str, data: HashMap<&str, zvariant::Value<'_>>, - ) -> zbus::fdo::Result<()> { + ) -> fdo::Result<()> { let _ = self.traces.send(( String::from(trace), HashMap::from_iter( diff --git a/src/wifi.rs b/src/wifi.rs index 2daf3ae..523a3a9 100644 --- a/src/wifi.rs +++ b/src/wifi.rs @@ -124,7 +124,7 @@ impl fmt::Display for WifiBackend { } } -pub async fn setup_iwd_config(want_override: bool) -> std::io::Result<()> { +pub(crate) async fn setup_iwd_config(want_override: bool) -> std::io::Result<()> { // Copy override.conf file into place or out of place depending // on install value @@ -174,7 +174,7 @@ async fn start_tracing(buffer_size: u32) -> Result<()> { .await } -pub async fn set_wifi_debug_mode( +pub(crate) async fn set_wifi_debug_mode( mode: WifiDebugMode, buffer_size: u32, should_trace: bool, @@ -225,7 +225,7 @@ pub async fn set_wifi_debug_mode( Ok(()) } -pub async fn get_wifi_backend() -> Result { +pub(crate) async fn get_wifi_backend() -> Result { let wifi_backend_contents = fs::read_to_string(path(WIFI_BACKEND_PATH)) .await? .trim() @@ -240,11 +240,11 @@ pub async fn get_wifi_backend() -> Result { bail!("WiFi backend not found in config"); } -pub async fn set_wifi_backend(backend: WifiBackend) -> Result<()> { +pub(crate) async fn set_wifi_backend(backend: WifiBackend) -> Result<()> { run_script("/usr/bin/steamos-wifi-set-backend", &[backend.to_string()]).await } -pub async fn get_wifi_power_management_state() -> Result { +pub(crate) async fn get_wifi_power_management_state() -> Result { let output = script_output("/usr/bin/iwconfig", &["wlan0"]).await?; for line in output.lines() { return Ok(match line.trim() { @@ -256,7 +256,7 @@ pub async fn get_wifi_power_management_state() -> Result { bail!("Failed to query power management state") } -pub async fn set_wifi_power_management_state(state: WifiPowerManagement) -> Result<()> { +pub(crate) async fn set_wifi_power_management_state(state: WifiPowerManagement) -> Result<()> { let state = match state { WifiPowerManagement::Disabled => "off", WifiPowerManagement::Enabled => "on",