lib: Export some modules as pub

This commit is contained in:
Vicki Pfau 2024-05-07 17:15:28 -07:00
parent 2977731fca
commit f4247de8c1
4 changed files with 19 additions and 22 deletions

View file

@ -8,7 +8,7 @@
use anyhow::Result; use anyhow::Result;
use clap::Parser; use clap::Parser;
use steamos_manager::{RootDaemon, UserDaemon}; use steamos_manager::{root, user};
#[derive(Parser)] #[derive(Parser)]
struct Args { struct Args {
@ -21,8 +21,8 @@ struct Args {
pub async fn main() -> Result<()> { pub async fn main() -> Result<()> {
let args = Args::parse(); let args = Args::parse();
if args.root { if args.root {
RootDaemon().await root::daemon().await
} else { } else {
UserDaemon().await user::daemon().await
} }
} }

View file

@ -10,7 +10,8 @@ use clap::{Parser, Subcommand};
use itertools::Itertools; use itertools::Itertools;
use std::ops::Deref; use std::ops::Deref;
use std::str::FromStr; 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::fdo::PropertiesProxy;
use zbus::names::InterfaceName; use zbus::names::InterfaceName;
use zbus::{zvariant, Connection}; use zbus::{zvariant, Connection};

View file

@ -21,22 +21,18 @@ mod hardware;
mod manager; mod manager;
mod power; mod power;
mod process; mod process;
mod proxy;
mod root;
mod sls; mod sls;
mod systemd; mod systemd;
mod user;
mod user_manager; mod user_manager;
mod wifi;
pub mod proxy;
pub mod root;
pub mod user;
pub mod wifi;
#[cfg(test)] #[cfg(test)]
mod testing; 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; const API_VERSION: u32 = 8;
pub trait Service pub trait Service
@ -85,18 +81,18 @@ pub fn path<S: AsRef<str>>(path: S) -> PathBuf {
.join(path.as_ref().trim_start_matches('/')) .join(path.as_ref().trim_start_matches('/'))
} }
pub async fn write_synced<P: AsRef<Path>>(path: P, bytes: &[u8]) -> Result<()> { pub(crate) async fn write_synced<P: AsRef<Path>>(path: P, bytes: &[u8]) -> Result<()> {
let mut file = File::create(path.as_ref()).await?; let mut file = File::create(path.as_ref()).await?;
file.write_all(bytes).await?; file.write_all(bytes).await?;
Ok(file.sync_data().await?) Ok(file.sync_data().await?)
} }
pub fn read_comm(pid: u32) -> Result<String> { pub(crate) fn read_comm(pid: u32) -> Result<String> {
let comm = std::fs::read_to_string(path(format!("/proc/{}/comm", pid)))?; let comm = std::fs::read_to_string(path(format!("/proc/{}/comm", pid)))?;
Ok(comm.trim_end().to_string()) Ok(comm.trim_end().to_string())
} }
pub fn get_appid(pid: u32) -> Result<Option<u64>> { pub(crate) fn get_appid(pid: u32) -> Result<Option<u64>> {
let environ = std::fs::read_to_string(path(format!("/proc/{}/environ", pid)))?; let environ = std::fs::read_to_string(path(format!("/proc/{}/environ", pid)))?;
for env_var in environ.split('\0') { for env_var in environ.split('\0') {
let (key, value) = match env_var.split_once('=') { let (key, value) = match env_var.split_once('=') {

View file

@ -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 // Copy override.conf file into place or out of place depending
// on install value // on install value
@ -174,7 +174,7 @@ async fn start_tracing(buffer_size: u32) -> Result<()> {
.await .await
} }
pub async fn set_wifi_debug_mode( pub(crate) async fn set_wifi_debug_mode(
mode: WifiDebugMode, mode: WifiDebugMode,
buffer_size: u32, buffer_size: u32,
should_trace: bool, should_trace: bool,
@ -225,7 +225,7 @@ pub async fn set_wifi_debug_mode(
Ok(()) Ok(())
} }
pub async fn get_wifi_backend() -> Result<WifiBackend> { pub(crate) async fn get_wifi_backend() -> Result<WifiBackend> {
let wifi_backend_contents = fs::read_to_string(path(WIFI_BACKEND_PATH)) let wifi_backend_contents = fs::read_to_string(path(WIFI_BACKEND_PATH))
.await? .await?
.trim() .trim()
@ -240,11 +240,11 @@ pub async fn get_wifi_backend() -> Result<WifiBackend> {
bail!("WiFi backend not found in config"); 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 run_script("/usr/bin/steamos-wifi-set-backend", &[backend.to_string()]).await
} }
pub async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> { pub(crate) async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
let output = script_output("/usr/bin/iwconfig", &["wlan0"]).await?; let output = script_output("/usr/bin/iwconfig", &["wlan0"]).await?;
for line in output.lines() { for line in output.lines() {
return Ok(match line.trim() { return Ok(match line.trim() {
@ -256,7 +256,7 @@ pub async fn get_wifi_power_management_state() -> Result<WifiPowerManagement> {
bail!("Failed to query power management state") 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 { let state = match state {
WifiPowerManagement::Disabled => "off", WifiPowerManagement::Disabled => "off",
WifiPowerManagement::Enabled => "on", WifiPowerManagement::Enabled => "on",