wifi: Remove get_wifi_backend_from_script

The script does exactly the same thing as what the _from_conf function did
This commit is contained in:
Vicki Pfau 2024-04-01 19:26:37 -07:00
parent b0250bda01
commit 9431ae9474
2 changed files with 11 additions and 24 deletions

View file

@ -21,8 +21,8 @@ use crate::power::{
use crate::process::{run_script, script_output}; use crate::process::{run_script, script_output};
use crate::systemd::SystemdUnit; use crate::systemd::SystemdUnit;
use crate::wifi::{ use crate::wifi::{
get_wifi_backend_from_conf, get_wifi_backend_from_script, set_wifi_backend, get_wifi_backend, set_wifi_backend, set_wifi_debug_mode, WifiBackend, WifiDebugMode,
set_wifi_debug_mode, WifiBackend, WifiDebugMode, WifiPowerManagement, WifiPowerManagement,
}; };
use crate::{anyhow_to_zbus, anyhow_to_zbus_fdo}; use crate::{anyhow_to_zbus, anyhow_to_zbus_fdo};
@ -62,7 +62,6 @@ impl fmt::Display for FanControl {
pub struct SteamOSManager { pub struct SteamOSManager {
connection: Connection, connection: Connection,
wifi_backend: WifiBackend,
wifi_debug_mode: WifiDebugMode, wifi_debug_mode: WifiDebugMode,
// Whether we should use trace-cmd or not. // Whether we should use trace-cmd or not.
// True on galileo devices, false otherwise // True on galileo devices, false otherwise
@ -73,7 +72,6 @@ impl SteamOSManager {
pub async fn new(connection: Connection) -> Result<Self> { pub async fn new(connection: Connection) -> Result<Self> {
Ok(SteamOSManager { Ok(SteamOSManager {
connection, connection,
wifi_backend: get_wifi_backend_from_conf().await?,
wifi_debug_mode: WifiDebugMode::Off, wifi_debug_mode: WifiDebugMode::Off,
should_trace: variant().await? == HardwareVariant::Galileo, should_trace: variant().await? == HardwareVariant::Galileo,
}) })
@ -309,7 +307,7 @@ impl SteamOSManager {
// Set the wifi debug mode to mode, using an int for flexibility going forward but only // Set the wifi debug mode to mode, using an int for flexibility going forward but only
// doing things on 0 or 1 for now // doing things on 0 or 1 for now
// Return false on error // Return false on error
match get_wifi_backend_from_script().await { match get_wifi_backend().await {
Ok(WifiBackend::IWD) => (), Ok(WifiBackend::IWD) => (),
Ok(backend) => { Ok(backend) => {
return Err(zbus::fdo::Error::Failed(format!( return Err(zbus::fdo::Error::Failed(format!(
@ -344,8 +342,11 @@ impl SteamOSManager {
/// WifiBackend property. /// WifiBackend property.
#[zbus(property)] #[zbus(property)]
async fn wifi_backend(&self) -> u32 { async fn wifi_backend(&self) -> zbus::fdo::Result<u32> {
self.wifi_backend as u32 match get_wifi_backend().await {
Ok(backend) => Ok(backend as u32),
Err(e) => Err(anyhow_to_zbus_fdo(e)),
}
} }
#[zbus(property)] #[zbus(property)]
@ -359,16 +360,7 @@ impl SteamOSManager {
Ok(backend) => backend, Ok(backend) => backend,
Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())), Err(e) => return Err(zbus::fdo::Error::InvalidArgs(e.to_string())),
}; };
match set_wifi_backend(backend).await { set_wifi_backend(backend).await.map_err(anyhow_to_zbus_fdo)
Ok(()) => {
self.wifi_backend = backend;
Ok(())
}
Err(e) => {
error!("Setting wifi backend failed: {e}");
Err(anyhow_to_zbus_fdo(e))
}
}
} }
/// A version property. /// A version property.

View file

@ -13,7 +13,7 @@ use tracing::error;
use zbus::Connection; use zbus::Connection;
use crate::path; use crate::path;
use crate::process::{run_script, script_output}; use crate::process::run_script;
use crate::systemd::{daemon_reload, SystemdUnit}; use crate::systemd::{daemon_reload, SystemdUnit};
const OVERRIDE_CONTENTS: &str = "[Service] const OVERRIDE_CONTENTS: &str = "[Service]
@ -224,7 +224,7 @@ pub async fn set_wifi_debug_mode(
Ok(()) Ok(())
} }
pub async fn get_wifi_backend_from_conf() -> Result<WifiBackend> { pub 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()
@ -239,11 +239,6 @@ pub async fn get_wifi_backend_from_conf() -> Result<WifiBackend> {
bail!("WiFi backend not found in config"); bail!("WiFi backend not found in config");
} }
pub async fn get_wifi_backend_from_script() -> Result<WifiBackend> {
let result = script_output("/usr/bin/steamos-wifi-set-backend", &["--check"]).await?;
WifiBackend::from_str(result.trim())
}
pub async fn set_wifi_backend(backend: WifiBackend) -> Result<()> { pub async fn set_wifi_backend(backend: WifiBackend) -> Result<()> {
run_script( run_script(
"set wifi backend", "set wifi backend",